From cb52855f866cd790be0e066ec4e983b22cdaa156 Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Tue, 5 Jun 2007 13:21:26 +0000 Subject: [PATCH] fix eol: add svn property + run fixcrlf to use native eol for all text files git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/core/trunk@544480 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1216 ++-- DISCLAIMER | 12 +- LICENSE | 404 +- MANIFEST.MF | 160 +- NOTICE | 28 +- README | 68 +- RELEASE_NOTES | 382 +- ant.patterns | 10 +- build-release.xml | 358 +- build.properties | 94 +- build.xml | 990 +-- doc/apache-proposal.txt | 242 +- doc/ideas.txt | 140 +- .../apache-con-2007/demo/1/build.xml | 106 +- .../apache-con-2007/demo/1/ivysettings.xml | 50 +- .../apache-con-2007/demo/2/build.xml | 100 +- .../apache-con-2007/demo/2/ivy.xml | 76 +- .../apache-con-2007/demo/2/ivysettings.xml | 50 +- .../demo/3/common/build.properties | 48 +- .../apache-con-2007/demo/3/common/build.xml | 168 +- .../demo/3/common/ivysettings.xml | 50 +- .../demo/3/ivy-demo-3A/build.properties | 40 +- .../demo/3/ivy-demo-3A/build.xml | 46 +- .../demo/3/ivy-demo-3A/ivy.xml | 76 +- .../demo/3/ivy-demo-3A/src/demo3A/Demo3A.java | 14 +- .../demo/3/ivy-demo-3B/build.properties | 40 +- .../demo/3/ivy-demo-3B/build.xml | 46 +- .../demo/3/ivy-demo-3B/ivy.xml | 68 +- .../demo/3/ivy-demo-3B/src/demo3B/Demo3B.java | 14 +- .../apache-con-2007/demo/README.txt | 6 +- .../apache-con-2007/samples/ivysettings-1.xml | 54 +- .../apache-con-2007/samples/ivysettings-2.xml | 80 +- doc/repository.properties | 50 +- doc/samples/build-install.xml | 144 +- doc/samples/build.xml | 288 +- doc/samples/ivy-sample-xslt.xml | 204 +- doc/samples/ivy-sample.xml | 202 +- doc/samples/ivysettings-default.xml | 48 +- .../jayasoft-ivyrep-example-default.html | 744 +- doc/samples/multi-project/build.xml | 94 +- doc/samples/multi-project/common.xml | 366 +- doc/test/ivyconf-include-http-url.xml | 42 +- doc/test/ivyconf.xml | 46 +- doc/test/ivysettings-include-http-url.xml | 42 +- doc/test/ivysettings.xml | 46 +- doc/toc.json | 2 +- ivy.xml | 98 +- ivysettings.xml | 90 +- optional.patterns | 32 +- src/etc/checkstyle/RequiredHeader.txt | 34 +- src/example/build-a-ivy-repository/build.xml | 208 +- .../config/ivy-maven1-ivysettings.xml | 248 +- .../config/ivy-maven2-ivysettings.xml | 284 +- .../config/ivysettings-advanced.xml | 78 +- .../config/ivysettings-basic.xml | 60 +- .../config/ivysettings-maven1.xml | 66 +- .../config/ivysettings-maven2.xml | 66 +- src/example/chained-resolvers/build.xml | 72 +- .../chainedresolvers-project/build.xml | 162 +- .../chainedresolvers-project/ivy.xml | 50 +- .../src/example/Hello.java | 64 +- .../chained-resolvers/config/ivysettings.xml | 58 +- .../configurations/jdbc-example/build.xml | 194 +- .../configurations/jdbc-example/ivy.xml | 88 +- .../jdbc-example/src/dev.properties | 38 +- .../src/example/ConfigurationsExample.java | 122 +- .../jdbc-example/src/prod.properties | 38 +- .../multi-projects/filter-framework/build.xml | 260 +- .../multi-projects/filter-framework/ivy.xml | 72 +- .../src/filter/FilterProvider.java | 74 +- .../filter-framework/src/filter/IFilter.java | 44 +- .../src/filter/ccimpl/CCFilter.java | 90 +- .../src/filter/hmimpl/HMFilter.java | 84 +- .../test/filter/AbstractTestFilter.java | 140 +- .../test/filter/ccimpl/CCFilterTest.java | 54 +- .../test/filter/hmimpl/HMFilterTest.java | 54 +- .../multi-projects/myapp/build.xml | 186 +- .../multi-projects/myapp/ivy.xml | 62 +- .../multi-projects/myapp/src/myapp/Main.java | 66 +- src/example/dependence/build.xml | 84 +- .../dependence/config/ivysettings.properties | 38 +- src/example/dependence/config/ivysettings.xml | 64 +- src/example/dependence/depending/build.xml | 186 +- src/example/dependence/depending/ivy.xml | 48 +- .../depending/src/depending/Main.java | 70 +- src/example/dependence/standalone/build.xml | 220 +- src/example/dependence/standalone/ivy.xml | 48 +- .../standalone/src/standalone/Main.java | 120 +- src/example/dual/build.xml | 72 +- src/example/dual/config/ivysettings.xml | 58 +- src/example/dual/project/build.xml | 162 +- src/example/dual/project/ivy.xml | 50 +- .../dual/project/src/example/Hello.java | 98 +- .../commons-httpclient-ivy-2.0.2.xml | 58 +- src/example/go-ivy/build.xml | 296 +- src/example/hello-ivy/build.xml | 152 +- src/example/hello-ivy/ivy.xml | 48 +- src/example/hello-ivy/src/example/Hello.java | 62 +- src/example/ivyrep/build.xml | 160 +- src/example/ivyrep/ivy.xml | 50 +- src/example/ivyrep/src/example/Hello.java | 94 +- src/example/multi-project/build.xml | 146 +- .../multi-project/common/build.properties | 54 +- src/example/multi-project/common/common.xml | 364 +- .../projects/console/build.properties | 42 +- .../multi-project/projects/console/build.xml | 46 +- .../multi-project/projects/console/ivy.xml | 60 +- .../projects/console/src/console/Main.java | 154 +- .../projects/find/build.properties | 42 +- .../multi-project/projects/find/build.xml | 46 +- .../multi-project/projects/find/ivy.xml | 74 +- .../projects/find/src/find/FindFile.java | 92 +- .../projects/find/src/find/Main.java | 148 +- .../projects/list/build.properties | 42 +- .../multi-project/projects/list/build.xml | 46 +- .../multi-project/projects/list/ivy.xml | 70 +- .../projects/list/src/list/ListFile.java | 94 +- .../projects/list/src/list/Main.java | 136 +- .../projects/size/build.properties | 42 +- .../multi-project/projects/size/build.xml | 46 +- .../multi-project/projects/size/ivy.xml | 56 +- .../projects/size/src/size/FileSize.java | 84 +- .../projects/sizewhere/build.properties | 42 +- .../projects/sizewhere/build.xml | 46 +- .../multi-project/projects/sizewhere/ivy.xml | 74 +- .../sizewhere/src/sizewhere/Main.java | 136 +- .../sizewhere/src/sizewhere/SizeWhere.java | 72 +- .../projects/version/build.properties | 42 +- .../multi-project/projects/version/build.xml | 46 +- .../multi-project/projects/version/ivy.xml | 48 +- .../projects/version/src/version/Version.java | 92 +- src/java/org/apache/ivy/Ivy.java | 1162 +-- src/java/org/apache/ivy/Ivy14.java | 970 +-- src/java/org/apache/ivy/Main.java | 894 +-- src/java/org/apache/ivy/ant/AddPathTask.java | 206 +- .../org/apache/ivy/ant/AntBuildTrigger.java | 322 +- .../org/apache/ivy/ant/AntCallTrigger.java | 256 +- .../org/apache/ivy/ant/AntMessageImpl.java | 212 +- .../apache/ivy/ant/IvyArtifactProperty.java | 164 +- .../org/apache/ivy/ant/IvyArtifactReport.java | 598 +- src/java/org/apache/ivy/ant/IvyBuildList.java | 868 +-- .../org/apache/ivy/ant/IvyBuildNumber.java | 512 +- .../org/apache/ivy/ant/IvyCacheFileset.java | 158 +- src/java/org/apache/ivy/ant/IvyCachePath.java | 154 +- src/java/org/apache/ivy/ant/IvyCacheTask.java | 208 +- src/java/org/apache/ivy/ant/IvyCheck.java | 196 +- src/java/org/apache/ivy/ant/IvyConfigure.java | 192 +- .../org/apache/ivy/ant/IvyConvertPom.java | 156 +- src/java/org/apache/ivy/ant/IvyDeliver.java | 844 +-- .../apache/ivy/ant/IvyExtractFromSources.java | 432 +- .../org/apache/ivy/ant/IvyFindRevision.java | 208 +- src/java/org/apache/ivy/ant/IvyInfo.java | 172 +- src/java/org/apache/ivy/ant/IvyInstall.java | 376 +- .../org/apache/ivy/ant/IvyListModules.java | 256 +- .../apache/ivy/ant/IvyPostResolveTask.java | 742 +- src/java/org/apache/ivy/ant/IvyPublish.java | 914 +-- src/java/org/apache/ivy/ant/IvyReport.java | 714 +- .../apache/ivy/ant/IvyRepositoryReport.java | 644 +- src/java/org/apache/ivy/ant/IvyResolve.java | 714 +- src/java/org/apache/ivy/ant/IvyRetrieve.java | 176 +- src/java/org/apache/ivy/ant/IvyTask.java | 584 +- src/java/org/apache/ivy/ant/IvyVar.java | 262 +- .../org/apache/ivy/ant/PackageMapping.java | 138 +- src/java/org/apache/ivy/ant/antlib.xml | 88 +- src/java/org/apache/ivy/core/IvyContext.java | 592 +- .../org/apache/ivy/core/IvyPatternHelper.java | 910 +-- src/java/org/apache/ivy/core/IvyThread.java | 140 +- .../apache/ivy/core/cache/ArtifactOrigin.java | 178 +- .../apache/ivy/core/cache/CacheManager.java | 614 +- .../apache/ivy/core/check/CheckEngine.java | 280 +- .../deliver/DefaultPublishingDRResolver.java | 56 +- .../ivy/core/deliver/DeliverEngine.java | 378 +- .../ivy/core/deliver/DeliverOptions.java | 440 +- .../PublishingDependencyRevisionResolver.java | 80 +- .../apache/ivy/core/event/EventManager.java | 190 +- .../ivy/core/event/FilteredIvyListener.java | 92 +- .../org/apache/ivy/core/event/IvyEvent.java | 246 +- .../apache/ivy/core/event/IvyEventFilter.java | 314 +- .../apache/ivy/core/event/IvyListener.java | 48 +- .../core/event/download/DownloadEvent.java | 82 +- .../download/EndArtifactDownloadEvent.java | 122 +- .../event/download/NeedArtifactEvent.java | 76 +- .../event/download/PrepareDownloadEvent.java | 72 +- .../download/StartArtifactDownloadEvent.java | 98 +- .../resolve/EndResolveDependencyEvent.java | 94 +- .../core/event/resolve/EndResolveEvent.java | 74 +- .../event/resolve/ResolveDependencyEvent.java | 94 +- .../ivy/core/event/resolve/ResolveEvent.java | 78 +- .../resolve/StartResolveDependencyEvent.java | 60 +- .../core/event/resolve/StartResolveEvent.java | 58 +- .../ivy/core/install/InstallEngine.java | 346 +- .../module/descriptor/AbstractArtifact.java | 168 +- .../AbstractIncludeExcludeRule.java | 188 +- .../ivy/core/module/descriptor/Artifact.java | 182 +- .../core/module/descriptor/Configuration.java | 390 +- .../module/descriptor/ConfigurationAware.java | 78 +- .../module/descriptor/DefaultArtifact.java | 258 +- .../DefaultDependencyArtifactDescriptor.java | 236 +- .../DefaultDependencyDescriptor.java | 1038 +-- .../module/descriptor/DefaultExcludeRule.java | 68 +- .../module/descriptor/DefaultIncludeRule.java | 68 +- .../descriptor/DefaultModuleDescriptor.java | 1188 +-- .../DependencyArtifactDescriptor.java | 126 +- .../descriptor/DependencyDescriptor.java | 202 +- .../core/module/descriptor/ExcludeRule.java | 100 +- .../core/module/descriptor/IncludeRule.java | 102 +- .../ivy/core/module/descriptor/License.java | 76 +- .../core/module/descriptor/MDArtifact.java | 240 +- .../module/descriptor/ModuleDescriptor.java | 396 +- .../apache/ivy/core/module/id/ArtifactId.java | 184 +- .../core/module/id/ArtifactRevisionId.java | 250 +- .../apache/ivy/core/module/id/ModuleId.java | 192 +- .../ivy/core/module/id/ModuleRevisionId.java | 410 +- .../apache/ivy/core/module/status/Status.java | 96 +- .../ivy/core/module/status/StatusManager.java | 302 +- .../ivy/core/publish/PublishEngine.java | 474 +- .../ivy/core/publish/PublishOptions.java | 302 +- .../core/report/ArtifactDownloadReport.java | 156 +- .../report/ConfigurationResolveReport.java | 588 +- .../ivy/core/report/DownloadReport.java | 114 +- .../ivy/core/report/DownloadStatus.java | 84 +- .../apache/ivy/core/report/ResolveReport.java | 486 +- .../core/resolve/DefaultModuleRevision.java | 200 +- .../ivy/core/resolve/DownloadOptions.java | 134 +- .../org/apache/ivy/core/resolve/IvyNode.java | 2298 +++--- .../ivy/core/resolve/IvyNodeCallers.java | 526 +- .../ivy/core/resolve/IvyNodeEviction.java | 712 +- .../apache/ivy/core/resolve/ResolveData.java | 358 +- .../ivy/core/resolve/ResolveEngine.java | 1856 ++--- .../ivy/core/resolve/ResolveOptions.java | 476 +- .../core/resolve/ResolvedModuleRevision.java | 112 +- .../apache/ivy/core/resolve/VisitData.java | 144 +- .../apache/ivy/core/resolve/VisitNode.java | 966 +-- .../ivy/core/retrieve/RetrieveEngine.java | 734 +- .../ivy/core/retrieve/RetrieveOptions.java | 296 +- .../apache/ivy/core/search/ModuleEntry.java | 96 +- .../ivy/core/search/OrganisationEntry.java | 80 +- .../apache/ivy/core/search/RevisionEntry.java | 112 +- .../apache/ivy/core/search/SearchEngine.java | 614 +- .../apache/ivy/core/settings/IvyPattern.java | 66 +- .../apache/ivy/core/settings/IvySettings.java | 2300 +++--- .../ivy/core/settings/XmlSettingsParser.java | 806 +- .../apache/ivy/core/settings/ivy.properties | 84 +- .../ivy/core/settings/ivysettings-1.4.xml | 56 +- .../settings/ivysettings-default-chain.xml | 52 +- .../ivy/core/settings/ivysettings-local.xml | 58 +- .../core/settings/ivysettings-main-chain.xml | 52 +- .../ivy/core/settings/ivysettings-public.xml | 46 +- .../ivy/core/settings/ivysettings-shared.xml | 58 +- .../apache/ivy/core/settings/ivysettings.xml | 52 +- .../ivy/core/settings/repository.properties | 50 +- .../ivy/core/settings/typedef.properties | 102 +- .../ivy/core/sort/ModuleDescriptorSorter.java | 214 +- .../org/apache/ivy/core/sort/SortEngine.java | 198 +- src/java/org/apache/ivy/plugins/IvyAware.java | 48 +- .../apache/ivy/plugins/IvySettingsAware.java | 48 +- .../AbstractCircularDependencyStrategy.java | 68 +- .../circular/CircularDependencyException.java | 86 +- .../circular/CircularDependencyHelper.java | 144 +- .../circular/CircularDependencyStrategy.java | 54 +- .../ErrorCircularDependencyStrategy.java | 74 +- .../IgnoreCircularDependencyStrategy.java | 78 +- .../WarnCircularDependencyStrategy.java | 76 +- .../conflict/AbstractConflictManager.java | 94 +- .../ivy/plugins/conflict/ConflictManager.java | 86 +- .../conflict/FixedConflictManager.java | 102 +- .../conflict/LatestConflictManager.java | 292 +- .../plugins/conflict/NoConflictManager.java | 64 +- .../conflict/RegexpConflictManager.java | 242 +- .../conflict/StrictConflictException.java | 76 +- .../conflict/StrictConflictManager.java | 104 +- .../latest/AbstractLatestStrategy.java | 130 +- .../ivy/plugins/latest/ArtifactInfo.java | 48 +- .../latest/ComparatorLatestStrategy.java | 102 +- .../latest/LatestLexicographicStrategy.java | 110 +- .../latest/LatestRevisionStrategy.java | 388 +- .../ivy/plugins/latest/LatestStrategy.java | 90 +- .../plugins/latest/LatestTimeStrategy.java | 72 +- .../matcher/AbstractPatternMatcher.java | 126 +- .../ivy/plugins/matcher/AnyMatcher.java | 80 +- .../matcher/ExactOrRegexpPatternMatcher.java | 124 +- .../plugins/matcher/ExactPatternMatcher.java | 110 +- .../plugins/matcher/GlobPatternMatcher.java | 160 +- .../apache/ivy/plugins/matcher/Matcher.java | 88 +- .../ivy/plugins/matcher/MatcherHelper.java | 130 +- .../ivy/plugins/matcher/ModuleIdMatcher.java | 94 +- .../apache/ivy/plugins/matcher/NoMatcher.java | 82 +- .../ivy/plugins/matcher/PatternMatcher.java | 142 +- .../plugins/matcher/RegexpPatternMatcher.java | 132 +- .../ivy/plugins/namespace/MRIDRule.java | 148 +- .../namespace/MRIDTransformationRule.java | 290 +- .../plugins/namespace/NameSpaceHelper.java | 186 +- .../ivy/plugins/namespace/Namespace.java | 206 +- .../ivy/plugins/namespace/NamespaceRule.java | 132 +- .../namespace/NamespaceTransformer.java | 52 +- .../AbstractModuleDescriptorParser.java | 722 +- .../parser/ModuleDescriptorParser.java | 96 +- .../ModuleDescriptorParserRegistry.java | 206 +- .../parser/m2/PomModuleDescriptorParser.java | 772 +- .../parser/xml/XmlModuleDescriptorParser.java | 1392 ++-- .../xml/XmlModuleDescriptorUpdater.java | 1396 ++-- .../parser/xml/XmlModuleDescriptorWriter.java | 534 +- .../plugins/report/LogReportOutputter.java | 378 +- .../ivy/plugins/report/ReportOutputter.java | 70 +- .../plugins/report/XmlReportOutputter.java | 544 +- .../ivy/plugins/report/XmlReportParser.java | 478 +- .../repository/AbstractRepository.java | 272 +- .../ivy/plugins/repository/BasicResource.java | 152 +- .../ivy/plugins/repository/LazyResource.java | 194 +- .../ivy/plugins/repository/Repository.java | 318 +- .../RepositoryCopyProgressListener.java | 112 +- .../ivy/plugins/repository/Resource.java | 204 +- .../plugins/repository/ResourceHelper.java | 90 +- .../ivy/plugins/repository/TransferEvent.java | 576 +- .../plugins/repository/TransferListener.java | 54 +- .../repository/file/FileRepository.java | 226 +- .../plugins/repository/file/FileResource.java | 152 +- .../repository/sftp/SFTPRepository.java | 490 +- .../plugins/repository/sftp/SFTPResource.java | 174 +- .../ssh/AbstractSshBasedRepository.java | 2 +- .../ivy/plugins/repository/ssh/Scp.java | 1328 ++-- .../plugins/repository/url/URLRepository.java | 216 +- .../plugins/repository/url/URLResource.java | 202 +- .../vfs/IvyWebdavClientFactory.java | 174 +- .../vfs/IvyWebdavConnectionManager.java | 450 +- .../repository/vfs/IvyWebdavFileProvider.java | 96 +- .../repository/vfs/IvyWebdavFileSystem.java | 68 +- .../plugins/repository/vfs/VfsRepository.java | 432 +- .../plugins/repository/vfs/VfsResource.java | 410 +- .../ivy/plugins/repository/vfs/ivy_vfs.xml | 112 +- .../repository/vsftp/VsftpRepository.java | 1396 ++-- .../repository/vsftp/VsftpResource.java | 112 +- .../plugins/resolver/AbstractResolver.java | 630 +- .../resolver/AbstractResourceResolver.java | 560 +- .../resolver/AbstractSshBasedResolver.java | 2 +- .../ivy/plugins/resolver/BasicResolver.java | 2084 +++--- .../ivy/plugins/resolver/CacheResolver.java | 352 +- .../ivy/plugins/resolver/ChainResolver.java | 594 +- .../plugins/resolver/DependencyResolver.java | 196 +- .../ivy/plugins/resolver/DualResolver.java | 282 +- .../plugins/resolver/FileSystemResolver.java | 90 +- .../ivy/plugins/resolver/IBiblioResolver.java | 486 +- .../ivy/plugins/resolver/IvyRepResolver.java | 600 +- .../plugins/resolver/RepositoryResolver.java | 494 +- .../ivy/plugins/resolver/SFTPResolver.java | 82 +- .../ivy/plugins/resolver/URLResolver.java | 68 +- .../ivy/plugins/resolver/VfsResolver.java | 122 +- .../ivy/plugins/resolver/VsftpResolver.java | 148 +- .../resolver/util/ApacheHttpURLLister.java | 80 +- .../plugins/resolver/util/FileURLLister.java | 122 +- .../resolver/util/HasLatestStrategy.java | 56 +- .../resolver/util/MDResolvedResource.java | 70 +- .../util/ResolvedModuleRevisionProxy.java | 160 +- .../resolver/util/ResolvedResource.java | 96 +- .../plugins/resolver/util/ResolverHelper.java | 654 +- .../resolver/util/ResourceMDParser.java | 48 +- .../ivy/plugins/resolver/util/URLLister.java | 70 +- .../ivy/plugins/trigger/AbstractTrigger.java | 166 +- .../apache/ivy/plugins/trigger/Trigger.java | 50 +- .../version/AbstractVersionMatcher.java | 156 +- .../plugins/version/ChainVersionMatcher.java | 310 +- .../plugins/version/ExactVersionMatcher.java | 70 +- .../plugins/version/LatestVersionMatcher.java | 114 +- .../org/apache/ivy/plugins/version/Match.java | 272 +- .../version/PatternVersionMatcher.java | 198 +- .../plugins/version/SubVersionMatcher.java | 92 +- .../ivy/plugins/version/VersionMatcher.java | 208 +- .../plugins/version/VersionRangeMatcher.java | 480 +- .../tools/analyser/DependencyAnalyser.java | 48 +- .../analyser/JarJarDependencyAnalyser.java | 192 +- .../apache/ivy/tools/analyser/JarModule.java | 92 +- .../ivy/tools/analyser/JarModuleFinder.java | 156 +- .../tools/analyser/RepositoryAnalyser.java | 118 +- .../org/apache/ivy/util/ChecksumHelper.java | 274 +- .../apache/ivy/util/ConfigurationUtils.java | 172 +- .../org/apache/ivy/util/Configurator.java | 1390 ++-- .../apache/ivy/util/CopyProgressEvent.java | 120 +- .../apache/ivy/util/CopyProgressListener.java | 58 +- src/java/org/apache/ivy/util/Credentials.java | 204 +- .../org/apache/ivy/util/CredentialsUtil.java | 322 +- .../apache/ivy/util/DefaultMessageImpl.java | 102 +- .../apache/ivy/util/EncrytedProperties.java | 130 +- src/java/org/apache/ivy/util/FileUtil.java | 518 +- src/java/org/apache/ivy/util/HostUtil.java | 62 +- src/java/org/apache/ivy/util/Message.java | 490 +- src/java/org/apache/ivy/util/MessageImpl.java | 56 +- .../org/apache/ivy/util/PropertiesFile.java | 150 +- src/java/org/apache/ivy/util/StringUtils.java | 252 +- src/java/org/apache/ivy/util/XMLHelper.java | 256 +- .../extendable/DefaultExtendableItem.java | 90 +- .../ivy/util/extendable/ExtendableItem.java | 154 +- .../util/extendable/ExtendableItemHelper.java | 122 +- .../UnmodifiableExtendableItem.java | 178 +- .../org/apache/ivy/util/filter/AndFilter.java | 82 +- .../ivy/util/filter/ArtifactTypeFilter.java | 78 +- .../org/apache/ivy/util/filter/Filter.java | 44 +- .../apache/ivy/util/filter/FilterHelper.java | 122 +- .../org/apache/ivy/util/filter/NoFilter.java | 60 +- .../org/apache/ivy/util/filter/NotFilter.java | 68 +- .../org/apache/ivy/util/filter/OrFilter.java | 82 +- .../ivy/util/url/AbstractURLHandler.java | 92 +- .../apache/ivy/util/url/ApacheURLLister.java | 312 +- .../apache/ivy/util/url/BasicURLHandler.java | 306 +- .../apache/ivy/util/url/CredentialsStore.java | 112 +- .../ivy/util/url/HttpClientHandler.java | 692 +- .../apache/ivy/util/url/IvyAuthenticator.java | 118 +- .../org/apache/ivy/util/url/URLHandler.java | 276 +- .../ivy/util/url/URLHandlerDispatcher.java | 192 +- .../ivy/util/url/URLHandlerRegistry.java | 130 +- test/buildlist/A/build.xml | 36 +- test/buildlist/A/ivy.xml | 48 +- test/buildlist/B/build.xml | 36 +- test/buildlist/B/ivy.xml | 42 +- test/buildlist/C/build.xml | 36 +- test/buildlist/C/ivy.xml | 48 +- test/buildlist/D/build.xml | 36 +- test/buildlist/D/ivy.xml | 50 +- test/buildlist/E/build.xml | 36 +- test/buildlist/E/ivy.xml | 42 +- .../ivy/plugins/resolver/CustomResolver.java | 58 +- test/java/org/apache/ivy/TestHelper.java | 82 +- .../apache/ivy/ant/AntBuildTriggerTest.java | 92 +- .../apache/ivy/ant/AntCallTriggerTest.java | 446 +- .../ivy/ant/IvyArtifactPropertyTest.java | 214 +- .../apache/ivy/ant/IvyArtifactReportTest.java | 134 +- .../org/apache/ivy/ant/IvyBuildListTest.java | 594 +- .../apache/ivy/ant/IvyBuildNumberTest.java | 328 +- .../apache/ivy/ant/IvyCacheFilesetTest.java | 304 +- .../org/apache/ivy/ant/IvyCachePathTest.java | 506 +- .../org/apache/ivy/ant/IvyConfigureTest.java | 298 +- .../org/apache/ivy/ant/IvyConvertPomTest.java | 106 +- .../org/apache/ivy/ant/IvyDeliverTest.java | 662 +- .../apache/ivy/ant/IvyFindRevisionTest.java | 164 +- .../org/apache/ivy/ant/IvyInstallTest.java | 198 +- .../apache/ivy/ant/IvyListModulesTest.java | 158 +- .../ivy/ant/IvyPostResolveTaskTest.java | 822 +-- .../org/apache/ivy/ant/IvyPublishTest.java | 836 +-- .../org/apache/ivy/ant/IvyReportTest.java | 158 +- .../ivy/ant/IvyRepositoryReportTest.java | 180 +- .../org/apache/ivy/ant/IvyResolveTest.java | 658 +- .../org/apache/ivy/ant/IvyRetrieveTest.java | 678 +- test/java/org/apache/ivy/ant/IvyVarTest.java | 142 +- .../ivy/ant/imported-configurations.xml | 44 +- test/java/org/apache/ivy/ant/ivy-108.xml | 56 +- test/java/org/apache/ivy/ant/ivy-381.xml | 58 +- test/java/org/apache/ivy/ant/ivy-custom.xml | 68 +- .../ivy/ant/ivy-different-revisions.xml | 66 +- test/java/org/apache/ivy/ant/ivy-double.xml | 56 +- .../org/apache/ivy/ant/ivy-doubleretrieve.xml | 60 +- test/java/org/apache/ivy/ant/ivy-failure.xml | 56 +- test/java/org/apache/ivy/ant/ivy-failure2.xml | 56 +- test/java/org/apache/ivy/ant/ivy-failure3.xml | 56 +- .../org/apache/ivy/ant/ivy-import-confs.xml | 62 +- .../org/apache/ivy/ant/ivy-latest-branch.xml | 56 +- .../org/apache/ivy/ant/ivy-latest-extra.xml | 56 +- test/java/org/apache/ivy/ant/ivy-latest.xml | 56 +- .../java/org/apache/ivy/ant/ivy-multiconf.xml | 66 +- .../org/apache/ivy/ant/ivy-publish-multi.xml | 58 +- test/java/org/apache/ivy/ant/ivy-publish.xml | 56 +- test/java/org/apache/ivy/ant/ivy-simple.xml | 56 +- test/java/org/apache/ivy/ant/ivy-simple2.xml | 56 +- .../org/apache/ivy/ant/ivy-with-variables.xml | 62 +- .../ivy/ant/ivysettings-props.properties | 38 +- .../org/apache/ivy/ant/ivysettings-props.xml | 42 +- .../org/apache/ivy/ant/ivysettings-test.xml | 58 +- .../apache/ivy/ant/published-ivy-custom.xml | 60 +- .../org/apache/ivy/ant/test-convertpom.xml | 92 +- test/java/org/apache/ivy/ant/test.pom | 116 +- .../org/apache/ivy/ant/vartest.properties | 40 +- .../org/apache/ivy/core/TestPerformance.java | 320 +- .../ivy/core/cache/CacheManagerTest.java | 208 +- .../ivy/core/event/IvyEventFilterTest.java | 222 +- .../apache/ivy/core/install/InstallTest.java | 280 +- .../DefaultDependencyDescriptorTest.java | 126 +- .../core/module/id/ModuleRevisionIdTest.java | 98 +- .../apache/ivy/core/resolve/ResolveTest.java | 6480 ++++++++--------- .../apache/ivy/core/resolve/badcacheconf.xml | 54 +- .../core/resolve/dualchainresolverconf.xml | 82 +- .../org/apache/ivy/core/resolve/ivy-148.xml | 62 +- .../org/apache/ivy/core/resolve/ivy-148b.xml | 62 +- .../org/apache/ivy/core/resolve/ivy-182.xml | 72 +- .../org/apache/ivy/core/resolve/ivy-198.xml | 50 +- .../org/apache/ivy/core/resolve/ivy-214.xml | 60 +- .../org/apache/ivy/core/resolve/ivy-218.xml | 60 +- .../org/apache/ivy/core/resolve/ivy-225.xml | 58 +- .../org/apache/ivy/core/resolve/ivy-56.xml | 48 +- .../core/resolve/ivy-dualchainresolver.xml | 50 +- .../apache/ivy/core/resolve/ivy-extra-att.xml | 48 +- .../ivy/core/resolve/ivy-latestreleased.xml | 52 +- .../apache/ivy/core/resolve/ivy-mod1.2.xml | 52 +- .../apache/ivy/core/resolve/ivy-namespace.xml | 50 +- .../ivy/core/resolve/ivy-namespace2.xml | 50 +- .../ivy/core/resolve/ivy-namespace3.xml | 50 +- .../ivy/core/resolve/ivy-namespace4.xml | 50 +- .../org/apache/ivy/core/resolve/ivy-other.xml | 66 +- .../ivy/core/retrieve/RetrieveTest.java | 370 +- .../ivy/core/settings/ConfigureTest.java | 158 +- .../settings/OnlineXmlSettingsParserTest.java | 112 +- .../core/settings/XmlSettingsParserTest.java | 780 +- .../settings/ivysettings-conflict-manager.xml | 48 +- .../settings/ivysettings-custom-typedef.xml | 50 +- .../settings/ivysettings-custom-typedef2.xml | 50 +- .../ivy/core/settings/ivysettings-include.xml | 48 +- .../core/settings/ivysettings-macro+ref.xml | 68 +- .../ivy/core/settings/ivysettings-macro.xml | 86 +- .../ivysettings-no-name-in-module.xml | 46 +- .../settings/ivysettings-no-org-in-module.xml | 46 +- .../core/settings/ivysettings-outputter.xml | 48 +- .../ivy/core/settings/ivysettings-parser.xml | 48 +- .../ivy/core/settings/ivysettings-ref.xml | 70 +- .../ivy/core/settings/ivysettings-status.xml | 50 +- .../ivy/core/settings/ivysettings-test.xml | 102 +- .../ivy/core/settings/ivysettings-typedef.xml | 56 +- .../core/settings/ivysettings-vmatcher1.xml | 50 +- .../core/settings/ivysettings-vmatcher2.xml | 48 +- .../ivy/core/settings/ivysettings.properties | 38 +- .../org/apache/ivy/core/sort/SortTest.java | 672 +- .../conflict/LatestConflictManagerTest.java | 384 +- .../conflict/RegexpConflictManagerTest.java | 166 +- .../conflict/StrictConflictManagerTest.java | 140 +- .../apache/ivy/plugins/conflict/ivy-383.xml | 62 +- .../apache/ivy/plugins/conflict/ivy-388.xml | 62 +- .../ivy/plugins/conflict/ivy-conflict.xml | 52 +- .../plugins/conflict/ivy-latest-time-1.xml | 56 +- .../plugins/conflict/ivy-latest-time-2.xml | 56 +- .../conflict/ivy-latest-time-transitivity.xml | 52 +- .../conflict/ivy-no-regexp-conflict.xml | 60 +- .../ivy/plugins/conflict/ivy-noconflict.xml | 58 +- .../ivysettings-latest-time-transitivity.xml | 60 +- .../conflict/ivysettings-latest-time.xml | 60 +- .../plugins/conflict/ivysettings-latest.xml | 60 +- .../conflict/ivysettings-regexp-test.xml | 74 +- .../conflict/ivysettings-strict-test.xml | 66 +- .../latest/LatestRevisionStrategyTest.java | 240 +- .../matcher/AbstractPatternMatcherTest.java | 192 +- .../ExactOrRegexpPatternMatcherTest.java | 102 +- .../matcher/ExactPatternMatcherTest.java | 72 +- .../matcher/GlobPatternMatcherTest.java | 160 +- .../matcher/RegexpPatternMatcherTest.java | 90 +- .../namespace/MRIDTransformationRuleTest.java | 108 +- .../AbstractModuleDescriptorParserTester.java | 286 +- .../ModuleDescriptorParserRegistryTest.java | 122 +- .../m2/PomModuleDescriptorParserTest.java | 800 +- .../plugins/parser/m2/commons-lang-1.0.pom | 216 +- .../ivy/plugins/parser/m2/mule-1.3.3.pom | 1122 +-- .../parser/m2/mule-module-builders-1.3.3.pom | 186 +- .../parser/m2/shale-tiger-1.1.0-SNAPSHOT.pom | 450 +- .../parser/m2/spring-hibernate3-2.0.2.pom | 240 +- .../m2/test-dependencies-with-classifier.pom | 78 +- .../m2/test-dependencies-with-profile.pom | 176 +- .../m2/test-dependencies-with-scope.pom | 100 +- .../plugins/parser/m2/test-dependencies.pom | 76 +- .../ivy/plugins/parser/m2/test-exclusion.pom | 116 +- .../ivy/plugins/parser/m2/test-optional.pom | 88 +- .../ivy/plugins/parser/m2/test-parent.pom | 72 +- .../ivy/plugins/parser/m2/test-parent2.pom | 70 +- .../ivy/plugins/parser/m2/test-properties.pom | 64 +- .../ivy/plugins/parser/m2/test-simple.pom | 62 +- .../ivy/plugins/parser/m2/test-version.pom | 76 +- .../parser/m2/test-without-version.pom | 74 +- .../m2/wicket-1.3-incubating-SNAPSHOT.pom | 230 +- .../xml/XmlModuleDescriptorParserTest.java | 1722 ++--- .../xml/XmlModuleDescriptorWriterTest.java | 222 +- .../parser/xml/XmlModuleUpdaterTest.java | 414 +- .../imported-configurations-with-mapping.xml | 44 +- ...ed-configurations-with-mappingoverride.xml | 44 +- .../imported-configurations-with-wildcard.xml | 46 +- .../parser/xml/imported-configurations.xml | 44 +- .../apache/ivy/plugins/parser/xml/license.xml | 36 +- .../parser/xml/test-artifacts-defaults.xml | 56 +- .../ivy/plugins/parser/xml/test-bad-confs.xml | 54 +- .../ivy/plugins/parser/xml/test-bad-org.xml | 48 +- .../plugins/parser/xml/test-bad-version.xml | 48 +- .../ivy/plugins/parser/xml/test-bad.xml | 48 +- .../ivy/plugins/parser/xml/test-bug60.xml | 60 +- .../parser/xml/test-configextendsothers1.xml | 66 +- .../parser/xml/test-configextendsothers2.xml | 64 +- .../parser/xml/test-configextendsothers3.xml | 72 +- .../xml/test-configurations-import1.xml | 66 +- .../xml/test-configurations-import2.xml | 68 +- .../xml/test-configurations-import3.xml | 66 +- .../xml/test-configurations-import4.xml | 66 +- .../plugins/parser/xml/test-defaultconf.xml | 62 +- .../plugins/parser/xml/test-defaultconf2.xml | 70 +- .../test-defaultconfmapping-withselectors.xml | 72 +- .../parser/xml/test-defaultconfmapping.xml | 70 +- .../plugins/parser/xml/test-dependencies.xml | 62 +- .../parser/xml/test-empty-dependencies.xml | 56 +- .../parser/xml/test-extra-attributes.xml | 74 +- .../parser/xml/test-incorrectconf1.xml | 66 +- .../parser/xml/test-incorrectconf2.xml | 74 +- .../parser/xml/test-incorrectconf3.xml | 58 +- .../plugins/parser/xml/test-noartifact.xml | 48 +- .../plugins/parser/xml/test-nopublication.xml | 64 +- .../plugins/parser/xml/test-novalidate.xml | 54 +- .../ivy/plugins/parser/xml/test-simple.xml | 46 +- .../parser/xml/test-update-excludedconfs1.xml | 70 +- .../parser/xml/test-update-excludedconfs2.xml | 70 +- .../parser/xml/test-update-excludedconfs3.xml | 72 +- .../parser/xml/test-update-excludedconfs4.xml | 96 +- .../parser/xml/test-update-excludedconfs5.xml | 166 +- .../ivy/plugins/parser/xml/test-update.xml | 222 +- .../parser/xml/test-write-dependencies.xml | 76 +- .../plugins/parser/xml/test-write-full.xml | 130 +- .../plugins/parser/xml/test-write-simple.xml | 66 +- .../apache/ivy/plugins/parser/xml/test.xml | 214 +- .../apache/ivy/plugins/parser/xml/updated.xml | 216 +- .../report/XmlReportOutputterTest.java | 228 +- .../plugins/report/XmlReportParserTest.java | 166 +- .../ivy/plugins/report/ivy-with-info.xml | 56 +- .../plugins/resolver/ChainResolverTest.java | 898 +-- .../plugins/resolver/DualResolverTest.java | 314 +- .../resolver/FileSystemResolverTest.java | 1262 ++-- .../ivy/plugins/resolver/IBiblioHelper.java | 148 +- .../plugins/resolver/IBiblioResolverTest.java | 610 +- .../plugins/resolver/IvyRepResolverTest.java | 358 +- .../ivy/plugins/resolver/MockResolver.java | 218 +- .../plugins/resolver/ResolverTestHelper.java | 236 +- .../ivy/plugins/resolver/URLResolverTest.java | 724 +- .../plugins/resolver/chainresolverconf.xml | 56 +- .../plugins/resolver/dualresolverconf-bad.xml | 54 +- .../ivy/plugins/resolver/dualresolverconf.xml | 58 +- .../plugins/resolver/ibiblioresolverconf.xml | 56 +- .../plugins/version/MockVersionMatcher.java | 70 +- .../version/VersionRangeMatcherTest.java | 220 +- .../org/apache/ivy/util/ConfiguratorTest.java | 674 +- .../apache/ivy/util/IvyPatternHelperTest.java | 132 +- .../org/apache/ivy/util/MockMessageImpl.java | 220 +- .../org/apache/ivy/util/StringUtilsTest.java | 62 +- .../ivy/util/url/ApacheURLListerTest.java | 146 +- .../ivy/util/url/BasicURLHandlerTest.java | 84 +- .../util/url/HttpclientURLHandlerTest.java | 68 +- .../ivy/util/url/apache-dir-listing.html | 74 +- .../ivy/util/url/apache-file-listing.html | 1140 +-- .../ivy/util/url/listing-with-spaces.html | 96 +- .../1/org1/mod1.1/ivys/ivy-1.0.1.xml | 58 +- .../1/org1/mod1.1/ivys/ivy-1.0.xml | 58 +- .../1/org1/mod1.1/ivys/ivy-1.1.xml | 58 +- .../1/org1/mod1.1/ivys/ivy-2.0.xml | 58 +- .../1/org1/mod1.4/ivys/ivy-1.0.1.xml | 70 +- .../1/org1/mod1.4/ivys/ivy-1.0.2.xml | 68 +- .../1/org1/mod1.4/ivys/ivy-1.0.3.xml | 68 +- .../1/org1/mod1.4/ivys/ivy-1.1.xml | 56 +- .../1/org1/mod1.4/ivys/ivy-1.2.xml | 56 +- .../1/org1/mod1.4/ivys/ivy-1.3.xml | 62 +- .../1/org1/mod1.4/ivys/ivy-2.0.xml | 60 +- .../1/org1/mod1.5/ivys/ivy-1.0.1.xml | 68 +- .../1/org1/mod1.5/ivys/ivy-1.0.2.xml | 62 +- .../1/org1/mod1.6/ivys/ivy-1.0.2.xml | 52 +- .../1/org1/mod1.6/ivys/ivy-1.0.3.xml | 62 +- .../1/org2/mod2.1/ivys/ivy-0.3.1.xml | 68 +- .../1/org2/mod2.1/ivys/ivy-0.3.2.xml | 68 +- .../1/org2/mod2.1/ivys/ivy-0.3.3.xml | 68 +- .../1/org2/mod2.1/ivys/ivy-0.3.xml | 66 +- .../1/org2/mod2.1/ivys/ivy-0.4.xml | 76 +- .../1/org2/mod2.2/ivys/ivy-0.5.xml | 72 +- .../1/org2/mod2.2/ivys/ivy-0.6.xml | 68 +- .../1/org2/mod2.2/ivys/ivy-0.7.xml | 70 +- .../1/org2/mod2.3/ivys/ivy-0.4.1.xml | 84 +- .../1/org2/mod2.3/ivys/ivy-0.4.xml | 82 +- .../1/org2/mod2.3/ivys/ivy-0.5.xml | 60 +- .../1/org2/mod2.3/ivys/ivy-0.6.2.xml | 60 +- .../1/org2/mod2.3/ivys/ivy-0.6.3.xml | 60 +- .../1/org2/mod2.3/ivys/ivy-0.6.4.xml | 60 +- .../1/org2/mod2.3/ivys/ivy-0.6.5.xml | 60 +- .../1/org2/mod2.3/ivys/ivy-0.6.xml | 60 +- .../1/org2/mod2.3/ivys/ivy-0.7.xml | 56 +- .../1/org2/mod2.4/ivys/ivy-0.3.xml | 66 +- .../1/org2/mod2.5/ivys/ivy-0.6.1.xml | 56 +- .../1/org2/mod2.5/ivys/ivy-0.6.xml | 60 +- .../1/org2/mod2.5/ivys/ivy-0.7.xml | 60 +- .../1/org2/mod2.5/ivys/ivy-0.8.xml | 60 +- .../1/org2/mod2.6/ivys/ivy-0.10.xml | 60 +- .../1/org2/mod2.6/ivys/ivy-0.11.xml | 62 +- .../1/org2/mod2.6/ivys/ivy-0.6.xml | 58 +- .../1/org2/mod2.6/ivys/ivy-0.7.xml | 58 +- .../1/org2/mod2.6/ivys/ivy-0.8.xml | 64 +- .../1/org2/mod2.6/ivys/ivy-0.9.xml | 60 +- .../1/org6/mod6.1/ivys/ivy-0.3.xml | 70 +- .../1/org6/mod6.1/ivys/ivy-0.4.xml | 66 +- .../1/org6/mod6.1/ivys/ivy-0.5.xml | 58 +- .../1/org6/mod6.1/ivys/ivy-0.6.xml | 58 +- .../1/org6/mod6.1/ivys/ivy-2.0.xml | 66 +- .../1/org6/mod6.2/ivys/ivy-0.3.xml | 70 +- .../1/org6/mod6.2/ivys/ivy-0.4.xml | 72 +- .../1/org6/mod6.2/ivys/ivy-0.5.xml | 72 +- .../1/org6/mod6.2/ivys/ivy-0.6.xml | 70 +- .../1/org6/mod6.2/ivys/ivy-2.0.xml | 58 +- .../repositories/1/org6/mod6.4/ivys/ivy-1.xml | 56 +- .../repositories/1/org6/mod6.4/ivys/ivy-2.xml | 56 +- .../repositories/1/org6/mod6.4/ivys/ivy-3.xml | 56 +- .../repositories/1/org6/mod6.4/ivys/ivy-4.xml | 56 +- .../repositories/1/org6/mod6.4/ivys/ivy-5.xml | 56 +- .../1/org9/mod9.1/ivys/ivy-1.0.xml | 58 +- .../1/org9/mod9.2/ivys/ivy-1.0.xml | 60 +- .../1/org9/mod9.2/ivys/ivy-1.1.xml | 58 +- .../1/org9/mod9.2/ivys/ivy-1.2.xml | 58 +- .../1/orgfailure/modfailure/ivys/ivy-1.0.xml | 52 +- .../1/orgfailure/modfailure/ivys/ivy-1.1.xml | 50 +- .../yourdep/yoursys/yourmod/ivys/ivy-1.0.xml | 56 +- test/repositories/2/buildnumber/ivy-test.xml | 52 +- test/repositories/2/mod10.1/ivy-1.0.xml | 60 +- test/repositories/2/mod10.1/ivy-1.1.xml | 60 +- test/repositories/2/mod10.1/ivy-1.2.xml | 66 +- test/repositories/2/mod10.1/ivy-1.3.xml | 60 +- test/repositories/2/mod10.2/ivy-1.0.xml | 58 +- test/repositories/2/mod10.2/ivy-1.1.xml | 58 +- test/repositories/2/mod10.2/ivy-1.2.xml | 58 +- test/repositories/2/mod10.2/ivy-1.3.xml | 58 +- test/repositories/2/mod10.2/ivy-2.0.xml | 58 +- test/repositories/2/mod11.1/ivy-1.0.xml | 78 +- test/repositories/2/mod11.2/ivy-1.0.xml | 72 +- test/repositories/2/mod12.1/ivy-1.0.xml | 54 +- test/repositories/2/mod12.2/ivy-1.0.xml | 56 +- test/repositories/2/mod13.1/ivy-1.0.xml | 82 +- test/repositories/2/mod13.2/ivy-1.0.xml | 82 +- test/repositories/2/mod13.3/ivy-1.0.xml | 82 +- test/repositories/2/mod14.1/ivy-1.1.xml | 76 +- test/repositories/2/mod14.2/ivy-1.1.xml | 76 +- test/repositories/2/mod14.3/ivy-1.1.xml | 76 +- test/repositories/2/mod14.4/ivy-1.1.xml | 74 +- test/repositories/2/mod15.1/ivy-1.1.xml | 58 +- test/repositories/2/mod15.2/ivy-1.1.xml | 60 +- test/repositories/2/mod3.1/ivy-1.0.1.xml | 58 +- test/repositories/2/mod3.1/ivy-1.0.xml | 58 +- test/repositories/2/mod3.1/ivy-1.1.xml | 56 +- test/repositories/2/mod3.1/ivy-1.2.xml | 56 +- test/repositories/2/mod3.1/ivy-1.3.xml | 64 +- test/repositories/2/mod3.1/ivy-1.4.xml | 66 +- test/repositories/2/mod3.2/ivy-1.1.xml | 56 +- test/repositories/2/mod3.2/ivy-1.2.1.xml | 58 +- test/repositories/2/mod3.2/ivy-1.2.xml | 58 +- test/repositories/2/mod3.2/ivy-1.3.xml | 58 +- test/repositories/2/mod3.2/ivy-1.4.xml | 58 +- test/repositories/2/mod4.1/ivy-4.0.xml | 60 +- test/repositories/2/mod4.1/ivy-4.1.xml | 60 +- test/repositories/2/mod4.1/ivy-4.10.xml | 60 +- test/repositories/2/mod4.1/ivy-4.11.xml | 60 +- test/repositories/2/mod4.1/ivy-4.12.xml | 60 +- test/repositories/2/mod4.1/ivy-4.13.xml | 58 +- test/repositories/2/mod4.1/ivy-4.14.xml | 62 +- test/repositories/2/mod4.1/ivy-4.2.xml | 60 +- test/repositories/2/mod4.1/ivy-4.3.xml | 60 +- test/repositories/2/mod4.1/ivy-4.4.xml | 66 +- test/repositories/2/mod4.1/ivy-4.5.xml | 60 +- test/repositories/2/mod4.1/ivy-4.6.xml | 70 +- test/repositories/2/mod4.1/ivy-4.7.xml | 70 +- test/repositories/2/mod4.1/ivy-4.8.xml | 74 +- test/repositories/2/mod4.1/ivy-4.9.xml | 62 +- test/repositories/2/mod5.1/ivy-4.0.xml | 68 +- test/repositories/2/mod5.1/ivy-4.1.xml | 68 +- test/repositories/2/mod5.1/ivy-4.2.xml | 74 +- test/repositories/2/mod5.2/ivy-1.0.xml | 58 +- test/repositories/2/mod5.2/ivy-2.0.xml | 66 +- test/repositories/2/mod6.1/ivy-1.0.xml | 60 +- test/repositories/2/mod6.1/ivy-1.1.xml | 60 +- test/repositories/2/mod6.1/ivy-1.2.xml | 68 +- test/repositories/2/mod6.1/ivy-1.3.xml | 68 +- test/repositories/2/mod6.2/ivy-1.0.xml | 58 +- test/repositories/2/mod6.3/ivy-1.0.xml | 58 +- test/repositories/2/mod6.3/ivy-1.1.xml | 72 +- test/repositories/2/mod7.1/ivy-1.0.xml | 58 +- test/repositories/2/mod7.1/ivy-2.0.xml | 52 +- test/repositories/2/mod7.2/ivy-1.0.xml | 58 +- test/repositories/2/mod7.3/ivy-1.0.xml | 60 +- test/repositories/2/mod8.1/a-1.0.txt | 2 +- test/repositories/2/mod8.1/a-1.1.txt | 2 +- test/repositories/2/mod8.1/a-private-1.0.txt | 2 +- test/repositories/2/mod8.1/a-private-1.1.txt | 2 +- test/repositories/2/mod8.1/ivy-1.0.xml | 68 +- test/repositories/2/mod8.1/ivy-1.1.xml | 70 +- test/repositories/2/mod8.2/ivy-1.0.xml | 66 +- test/repositories/2/mod8.3/ivy-1.0.xml | 66 +- test/repositories/2/mod8.4/ivy-1.0.xml | 64 +- test/repositories/2/mod8.4/ivy-1.1.xml | 64 +- test/repositories/2/mod8.5/ivy-2.0.xml | 66 +- test/repositories/2/mod8.6/ivy-2.0.xml | 68 +- test/repositories/2/mod_released/ivy-1.0.xml | 62 +- test/repositories/2/mod_released/ivy-1.1.xml | 62 +- test/repositories/IVY-258/ivy.xml | 54 +- test/repositories/IVY-258/ivysettings.xml | 60 +- test/repositories/IVY-258/module2/ivy.xml | 48 +- test/repositories/IVY-264/ivy.xml | 52 +- test/repositories/IVY-264/ivysettings.xml | 54 +- test/repositories/IVY-264/x/ivy-1.0.xml | 48 +- test/repositories/IVY-264/y/ivy-1.0.xml | 48 +- test/repositories/IVY-264/z/ivy-1.0.xml | 48 +- test/repositories/IVY-283/B/ivy-1.0.xml | 70 +- test/repositories/IVY-283/C/ivy-1.0.xml | 66 +- test/repositories/IVY-283/ivy-d.xml | 86 +- test/repositories/IVY-283/ivy.xml | 78 +- test/repositories/IVY-283/ivysettings.xml | 54 +- .../IVY-283/module_a/ivy-local.xml | 76 +- .../IVY-283/module_b/ivy-local.xml | 80 +- .../IVY-283/module_c/ivy-local.xml | 84 +- .../IVY-283/module_e/ivy-local.xml | 72 +- .../IVY-407/MyCompany/A/ivy-1.0.0.xml | 66 +- .../IVY-407/MyCompany/B/ivy-1.0.0.xml | 64 +- .../IVY-407/MyCompany/C/ivy-1.0.0.xml | 62 +- .../IVY-407/MyCompany/C/ivy-1.0.1.xml | 62 +- .../IVY-407/MyCompany/C/ivy-1.0.2.xml | 62 +- .../IVY-407/MyCompany/D/ivy-1.0.0.xml | 64 +- test/repositories/IVY-448/ivy.xml | 50 +- test/repositories/IVY-448/ivysettings.xml | 60 +- test/repositories/IVY-448/module2/ivy-1.0.xml | 48 +- test/repositories/IVY-448/module3/ivy-1.0.xml | 42 +- test/repositories/IVY-448/module3/ivy-2.0.xml | 42 +- test/repositories/IVY-84/ivysettings.xml | 60 +- .../IVY-84/repo/test/a/ivy-1.0.1.xml | 66 +- .../IVY-84/repo/test/a/ivy-1.0.2.xml | 66 +- .../IVY-84/repo/test/b/ivy-1.0.1.xml | 72 +- .../IVY-84/repo/test/b/ivy-1.0.2.xml | 72 +- .../IVY-84/repo/test/c/ivy-1.0.1.xml | 72 +- .../IVY-84/repo/test/c/ivy-1.0.2.xml | 72 +- test/repositories/IVY-84/tests/1/ivy.xml | 72 +- test/repositories/IVY-84/tests/2/ivy.xml | 72 +- test/repositories/IVY-84/tests/3/ivy.xml | 72 +- test/repositories/IVY-84/tests/4/ivy.xml | 72 +- test/repositories/IVY-84/tests/5/ivy.xml | 72 +- test/repositories/IVY-84/tests/6/ivy.xml | 72 +- test/repositories/IVY-84/tests/7/ivy.xml | 72 +- .../badfile/ivys/ ivy-badmodule.xml | 48 +- test/repositories/badfile/ivys/ivy-badorg.xml | 48 +- .../badfile/ivys/ivy-badrevision.xml | 48 +- test/repositories/badfile/ivysettings.xml | 52 +- .../badfile/myorg/mymodule/ivy-badmodule.xml | 42 +- .../badfile/myorg/mymodule/ivy-badorg.xml | 42 +- .../myorg/mymodule/ivy-badrevision.xml | 42 +- .../branches/bar/bar1/trunk/1/ivy.xml | 48 +- .../branches/bar/bar1/trunk/2/ivy.xml | 48 +- .../branches/bar/bar1/trunk/3/ivy.xml | 50 +- .../branches/bar/bar2/trunk/1/ivy.xml | 42 +- .../branches/bar/bar2/trunk/2/ivy.xml | 42 +- .../branches/foo/foo1/branch1/2/ivy.xml | 42 +- .../branches/foo/foo1/branch1/4/ivy.xml | 42 +- .../branches/foo/foo1/trunk/1/ivy.xml | 42 +- .../branches/foo/foo1/trunk/3/ivy.xml | 42 +- .../branches/ivysettings-defaultbranch1.xml | 54 +- .../branches/ivysettings-fooonbranch1.xml | 60 +- test/repositories/branches/ivysettings.xml | 54 +- .../idautomation/barcode/ivy-barcode-4.10.xml | 50 +- .../bug148/ivysettings.properties | 40 +- test/repositories/bug148/ivysettings.xml | 70 +- .../jtv/jtv-foo/bar/ivy-bar-1.1.0.0.xml | 64 +- test/repositories/bugIVY-56/ivysettings.xml | 56 +- .../checkmodified/ivy-1.0-after.xml | 58 +- .../checkmodified/ivy-1.0-before.xml | 58 +- .../checksums/allright/ivy-1.0.xml | 58 +- .../checksums/badartcs/ivy-1.0.xml | 50 +- .../checksums/badivycs/ivy-1.0.xml | 50 +- test/repositories/circular/ivy.xml | 64 +- .../dual-local/xerces/xerces/ivy-2.6.2.xml | 56 +- .../external-artifacts/A/ivy-1.0.xml | 48 +- test/repositories/external-artifacts/ivy.xml | 60 +- .../external-artifacts/ivysettings.xml | 52 +- .../extra-attributes/ivysettings.xml | 64 +- .../mymodule/task1/1854/ivy.xml | 64 +- test/repositories/ivysettings-1.xml | 56 +- .../ivysettings-nodefaultresolver.xml | 86 +- test/repositories/ivysettings.properties | 48 +- test/repositories/ivysettings.xml | 86 +- test/repositories/m2/ivysettings.xml | 54 +- .../1.0/test-classified-1.0.pom | 62 +- .../1.0/test-classifier-1.0.pom | 78 +- .../test-version/1.0/test-version-1.0.pom | 76 +- .../m2/org/apache/test/1.0/test-1.0.pom | 62 +- .../m2/org/apache/test2/1.0/test2-1.0.pom | 76 +- .../m2/org/apache/test3/1.0/test3-1.0.pom | 76 +- .../multi-ivypattern/ivy1/ivy-1.0.xml | 54 +- .../multi-ivypattern/ivy2/ivy-1.1.xml | 58 +- .../multi-ivypattern/ivysettings.xml | 56 +- test/repositories/multirevisions/ivy.xml | 68 +- .../multirevisions/ivy/moduleX-1.0.xml | 52 +- .../multirevisions/ivy/moduleX-2.0.xml | 58 +- .../multirevisions/ivy/moduleZ-1.0.xml | 64 +- .../multirevisions/ivysettings.xml | 54 +- test/repositories/namespace/A/A/1.0/ivy.xml | 52 +- test/repositories/namespace/A/B/1.0/ivy.xml | 58 +- test/repositories/namespace/B/1/1.0/1-1.0.pom | 50 +- test/repositories/namespace/B/2/1.0/2-1.0.pom | 214 +- test/repositories/namespace/ivysettings.xml | 144 +- test/repositories/norev/ivy.xml | 54 +- test/repositories/norev/ivysettings.xml | 60 +- test/repositories/norev/module2/ivy.xml | 48 +- .../norevision/ivy-mod1.1-after.xml | 58 +- .../norevision/ivy-mod1.1-before.xml | 58 +- test/triggers/ant-build/A/build.xml | 66 +- test/triggers/ant-build/A/ivy.xml | 42 +- test/triggers/ant-build/B/ivy.xml | 50 +- test/triggers/ant-build/ivysettings.xml | 66 +- test/triggers/ant-call/A/build.xml | 90 +- test/triggers/ant-call/A/ivy.xml | 50 +- test/triggers/ant-call/ivysettings.xml | 66 +- test/triggers/ant-call/local/foo/ivy.xml | 52 +- test/xsl/test.xml | 176 +- version.properties | 40 +- 896 files changed, 77910 insertions(+), 77900 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 30394021..cac24502 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,608 +1,608 @@ - Ivy - - The agile open source dependency manager - - http://incubator.apache.org/ivy - ============================================ - -for detailed view of each issue, please consult http://issues.apache.org/jira/browse/IVY - - Committers - Maarteen Coene - Xavier Hanin - Gilles Scokart - - Contributors - Ingo Adler - Stephane Bailliez - Karl Baum - Jeffrey Blattman - Matthieu Brouillard - Kristian Cibulskis - Pierre Hägnestrand - Peter Hayes - Matt Inger - Anders Janmyr - Christer Jonsson - Matthias Kilian - Gregory Kisling - Tat Leung - Costin Leau - Antoine Levy-Lambert - William Lyvers - Jan Materne - Stephen Nesbitt - Joshua Nichols - Bernard Niset - Glen Marchesani - Mathias Muller - Peter Oxenham - Emmanuel Pellereau - Roshan Punnoose - Damon Rand - Christian Riege - Jean-Baptiste Quenot - Andreas Sahlbach - John Shields - Johan Stuyts - John Williams - Jaroslaw Wypychowski - - version in SVN -===================================== -- NEW: A checkstyle report is generated (IVY-483) (thanks to Jan Materne) -- NEW: Hide private or specific conf when publishing (IVY-77) - -- IMPROVEMENT: Use maven2 repository to download dependencies -- IMPROVEMENT: Allow "main" parameters to be passed directly (instead of using -args flag) (IVY-480) (thanks to Archie Cobbs) -- IMPROVEMENT: Remove @author tags (thanks to Stephane Bailliez) -- IMPROVEMENT: Remove use of deprecated elements in ivysettings.xml (IVY-505) (with contribution from Jan Materne) - -- FIX: The deprecated "keep" attribute on post resolve tasks causes an error (IVY-517) -- FIX: Some circular dependencies not retrieved (IVY-400) -- FIX: ${version} property not recognized in poms (IVY-512) -- FIX: Bug on handling dependency artifacts when a module configuration is specified (IVY-507) -- FIX: Configure fails when having httpclient in classpath without commons-logging (IVY-502) -- FIX: packaging data not parsed in maven 2 pom (IVY-500) (thanks to Jeffrey Blattman) -- FIX: install ant task: requires default resolver in ivy settings (IVY-477) -- FIX: Ant project reference lost from context on multiple ant calls in single thread (IVY-497) (thanks to Jaroslaw Wypychowski) -- FIX: EOL in the doc pages (IVY-470) -- FIX: Cache is storing ArtifactOrigin properties with no guarantee of unicity and types telescope during resolve. (IVY-430) (thanks to Stephane Bailliez) -- FIX: ivy:install ant task does not fail on error (IVY-475) (thanks to Jeffrey Blattman) -- FIX: Credentials are shown in build log even if debug is not enabled (IVY-486) (thanks to Gilles Scokart) -- FIX: Post-Resolve task shouldn't set the 'resolveid' (IVY-489) -- FIX: build fails without emma code coverage JARs present (IVY-478) -- FIX: buildlist broken - regression in 2.0.0-alpha1-incubating (IVY-493) -- FIX: Circular dependency startegy in buildlist (IVY-509) -- FIX: ivy should stop telling me off twice for ivyconf.xml files (IVY-513) - - 2.0.0-alpha1-incubating -===================================== -- NEW: define artifacts not declared by the dependency module descriptor (IVY-419) -- NEW: Module wide exclude (IVY-431) -- NEW: The default public resolver used is now ibiblio with m2 compatible mode (IVY-463) - -- IMPROVE: OSGIfy ivy artifacts (IVY-464) (thanks to Costin Leau) -- IMPROVE: Let user specify Ivy file when using a post-resolve task (IVY-455) -- IMPROVE: IvyArtifactProperty and IvyArtifactReport tasks should be a post resolve task (IVY-452) -- IMPROVE: Rename ivy configuration in settings to remove ambiguity on configuration meaning (IVY-438) -- IMPROVE: Please typedef CacheResolver as "cache" for us (IVY-359) -- IMPROVE: ivy:retrieve should be able to create symlinks (IVY-353) (thanks to John Williams) -- IMPROVE: Ability to have multiple roots in the task (IVY-340) (thanks to Matt Inger) -- IMPROVE: Refactoring / documentation / test of matcher package (IVY-375) (thanks to Stephane Bailliez) -- IMPROVE: Add a unit test to verify that latest.integration accepts released modules (IVY-394) (thanks to Gilles Scokart) -- IMPROVE: New "modules in use" section in console report at the end of resolve (IVY-373) (thanks to John Wiliams) -- IMPROVE: Generated XML reports now contains more information about the resolved module (IVY-446) - -- FIX: ivy-retrieve failure when explicit absolute 'ivy.dep.file' path specified (IVY-396) -- FIX: IvyPostResolve Task doesn't reuse Ivy file of previous resolve (IVY-458) -- FIX: Ivy standalone is passing null args to main method when invoking with no args (IVY-457) -- FIX: Invalid error report with m2compatible resolver (IVY-456) -- FIX: IvyPostResolve Task doesn't use specified cache for the resolve (IVY-453) -- FIX: XmlModuleDescriptorWriterTest not working with Java 6 (IVY-374) -- FIX: Conflict managers ignored, when assigned to modules in Ivy configuration (setting, ivyconf.xml) (IVY-448) -- FIX: Ivy should fail if ';' has been used in publications/artifact/@conf of ivy.xml (IVY-441) -- FIX: Ivy should fail where dependency uses undefined configuration (IVY-442) -- FIX: Dynamic revision not calculated properly when using multiple directories (IVY-427) -- FIX: LatestRevisionStrategy.sort() doesn't sort as specified (IVY-435) -- FIX: setting m2compatible on ibiblio resolver overwrite root and pattern settings (IVY-437) -- FIX: ivy.revision property not set correctly for second resolve (IVY-429) -- FIX: NPE when no organisation or no name is provided in module element of ivyconf (IVY-422) -- FIX: FileUtil#copy(File src, File dest, CopyProgressListener l, boolean overwrite) (IVY-420) -- FIX: Invalid pom parsing when version is only declared in parent (IVY-436) -- FIX: ${project.groupId} and ${project.version} not processed correctly in poms (IVY-425) -- FIX: Incorrect pom parsing with profile (IVY-423) -- FIX: Ivy doesn't recognize maven2 classifiers (IVY-418) -- FIX: PomModuleDescriptorParser fails with nested profile dependency (IVY-392) (thanks to William Lyvers) -- FIX: Static revision replacement is not working when delivering an artifact with a dependency having extra attributes (IVY-415) -- FIX: Static revision replacement is not working when delivering an artifact with a dependency on a branch (IVY-404) -- FIX: latest-time conflict manager not working properly (IVY-407) -- FIX: LatestRevisionStrategy do not consider all dynamic revisions properly (IVY-383) (thanks to John Williams for the unit test) -- FIX: IOException during publish causes NullPointerException (IVY-371) -- FIX: Comments in ivy.xml duplicated (IVY-336) (thanks to Gilles Scokart) -- FIX: Ivy failure when the ivy.xml file contains non US-ASCII characters (IVY-346) (thanks to Gilles Scokart) -- FIX: Urlresolver is not possible to use dynamic revisions on nonstandard repository structure (IVY-350) (thanks to Pierre Hägnestrand) - - - version 1.4.1 - 2006-11-09 -===================================== -- IMPROVE: ability to rebuild all dependent projects from a leaf (IVY-101) -- IMPROVE: Artifact pattern list attribute for the ivy:publish (IVY-113) -- IMPROVE: Measure code coverage (IVY-323) -- IMPROVE: add release target to build file (IVY-339) -- IMPROVE: Add a 'conf' parameter to the ivy 'publish' ant task (IVY-322) (thanks to Emmanuel Pellereau) - -- FIX: retrieve fails when resolve is done with useOrigin set to true (IVY-304) -- FIX: IVY complains about non-existent reports in the cache directory (IVY-315) -- FIX: Typo in failureproperty attribute of Ant resolve task (IVY-327) (thanks to Jean-Baptiste Quenot) -- FIX: ivy:resolve useOrigin fails to behave correctly (IVY-332) -- FIX: ChainVersionMatcher doesn't handle IvyAware children version matchers (IVY-331) -- FIX: latest. does not work properly when no matching revision exist (IVY-318) -- FIX: attribute name in macrodef is not handled as expected (IVY-319) -- FIX: confmappingoverride doesn't work for configurations extending from "*(public)" (IVY-326) - - - version 1.4 - 2006-10-09 -===================================== -Version 1.4-RC2 has been promoted to 1.4 on 2006-10-09, with documentation update. - -Known bugs and limitations: -- references in resolvers are not resolved 'in-time' with macrodef (IVY-319) -- latest. does not work properly when no matching revision exist (IVY-318) -- IVY complains about non-existent reports in the cache directory (IVY-315) -- retrieve fails when resolve is done with useOrigin set to true (IVY-304) - - - version 1.4-RC2 - 2006-09-27 -===================================== -- FIX: m2compatible flag is ignored for display of failed artifact searches (IVY-303) -- FIX: AntCallTriggerTest and AntBuildTriggerTest fail when run from ivy build.xml (IVY-310) -- FIX: Classloader problem with ant (IVY-311) -- FIX: Make resolve overview more compact (IVY-299) -- FIX: Could not write to "tmp:///webdav_tmp.c1" because it is read-only (IVY-312) - - version 1.4-RC1 - 2006-09-17 -================================= -Incompatibility with previous versions: ---------------------------------------- -* usage: - - no known major incompatiblity - - build list task now requires a configured ivy instance (configure will automatically be called if you don't call it explicitly) - - publish now requires the published ivy file to have the published revision (automatic if you use deliver) - -* API: - - Numerous API changes especially in the BasicResolver class and subclasses due to the introduction of VersionMatcher, - this may break some custom dependency resolvers or other tools or plugins depending directly on Ivy API - -Changes: --------- -* thanks to Jayasoft: - - NEW: ivy report generate full graph from automated build (IVY-155) - - NEW: support for build number calculation (IVY-276) - - NEW: find modules in repository (IVY-275) - - NEW: explicitly specify artifact download URL (IVY-271) - - NEW: introduce branch management (IVY-269) - - NEW: resolve dependencies directly without using an ivy file (IVY-268) - - NEW: ability to invoke any build scripts for dependencies (IVY-68) - - NEW: support sftp repository (IVY-267) - - NEW: pluggable version matcher (IVY-219) - - NEW: support for version ranges (IVY-295) - - NEW: dependency based on dependency status (IVY-47) - - NEW: add possibility to define extra attributes in ivy files (IVY-217) - - NEW: option to omit specific confs and allow the rest (IVY-66) - - NEW: use custom classloader for plugins (IVY-220) - - NEW: adding to SPECIAL_MEANINGS in LatestRevisionStrategy (IVY-121) - - NEW: Allow use of system properties in ivyconf.xml (IVY-228) - - - IMPROVE: allow to use file-system repository directly without cache (IVY-211) - - IMPROVE: deliver task use a default value for revision (IVY-252) - - IMPROVE: better documentation distribution (IVY-274) - in progress - - IMPROVE: define conflict manager per organisation/module in ivyconf (IVY-270) - - IMPROVE: transitive parameter in resolve (IVY-21) - - IMPROVE: add syncing feature in retrieve (IVY-33) - - IMPROVE: use of md5 and/or sha1 files to check downloads (IVY-27) - - IMPROVE: possible to use m2compatible without automatically using POMs as well (IVY-263) - - IMPROVE: support for circular dependencies (IVY-202) - - IMPROVE: make status list configurable (IVY-242) - - IMPROVE: use only ivy patterns for listing revisions when module desciptor is required (allownomd = false) (IVY-166) - - IMPROVE: implement strict haltonfailure if ivy.xml is not found (IVY-110) - - IMPROVE: artifact's "name" attribute could be omitted (IVY-231) - - IMPROVE: ivy standalone now return error status (IVY-152) - - IMPROVE: log messages do not display most specfic resolver name (IVY-170) - - IMPROVE: prints URL before downloading in verbose mode (IVY-257) - - IMPROVE: incorrect value in status attribute causes silent failure (IVY-259) - - IMPROVE: suport empty dependencies tag in an ivy file (IVY-281) - - IMPROVE: isolate dependency resolution from artifact downloading (IVY-254) - - IMPROVE: Pass artifact to repository when calling "put" (IVY-192) - - IMPROVE: Do not publish ivy file with bad revision, and allow to force the deliver when calling publish task (IVY-245) - - - FIX: Problem with multiple artifact includes in transitive dependencies (IVY-283) - - FIX: Endless recursion in report (IVY-284) - - FIX: http url lister doesn't work when link text has spaces (IVY-282) - - FIX: Incorrect ant log level (IVY-279) - - FIX: Wrong resolution of dependencies if artifacts specified explicitly (IVY-261) - - FIX: Multiple versions of dependencies appearing in retrieve (IVY-264) - - FIX: Too many false CircularDependencyException errors thrown (IVY-230) - - FIX: CircularDependencyException not always thrown (IVY-184) - - FIX: NullPointer in BasicResolver (IVY-258) - - FIX: Bad diagnostics message when no space left (IVY-250) - - FIX: Maven2 POM support can find groupId from "parent" element (IVY-262) - - FIX: Parent version is expected to be equal to the module version in POM (IVY-241) - - FIX: problem with cache and returnFirst (IVY-207) - - FIX: modules splitted across a chain are not handled correctly (IVY-206) - - FIX: problem with conf extension and latest revisions (IVY-240) - - FIX: The clean-cache target in /src/example/hello-ivy/build.xml file refers to ${user.home}/.ivy-cache instead of ${user.home}/.ivy/cache/ (IVY-265) - -* thanks to Ivy Community: - - NEW: SSH Resolver added and aligned with SFTP resolver (IVY-273) (thanks to Andreas Sahlbach) - - NEW: ability to turn off transitivity at configuration level (IVY-103) (thanks to Karl Baum and Maarten Coene) - - NEW: a conflict manager that is able to allow implementation changes but not api changes (1.2.x - OK), (1.x.x - Not OK) (IVY-223) (thanks to Anders Janmyr) - - NEW: enhance standalone mode to execute java program by creating classloader of dependant jars from cache (IVY-210) (thanks to Peter Hayes) - - NEW: addition of Vfs Resolver which uses Commons-Vfs to resolve files (IVY-128) (thanks to Glen Marchesani, Matt Inger and Stephen Nesbitt) - - - IMPROVE: use global properties in the recursive delivery (IVY-222) (with the contribution of Roshan Punnoose) - - IMPROVE: better handling of authentication (thanks to Christian Riege) - - - FIX: Ant log messsages not embedded in task log (IVY-280) (thanks to Gilles Scokart) - - FIX: Ivy fails when downloading from a server that supports NTLM authentication (IVY-213) (thanks to Damon Rand) - - FIX: Delivered Ivy files with incomplete last line. (IVY-125) (thanks to Matthias Kilian) - - FIX: the vfs resolver should not log passwords (IVY-292) (thanks to Antoine Levy-Lambert) - -* thanks to Maarten Coene: - - NEW: add failureproperty parameter to the resolve task (IVY-285) - - NEW: Add type filtering to retrieve task (IVY-260) - - NEW: Add selectors to the configuration mapping (IVY-253) - - NEW: Add Ant task to retrieve information from an Ivy file without doing a resolve (IVY-255) - - NEW: add option to cachepath task to create a path with local artifact paths (IVY-221) - - NEW: allow extending configurations to override the mapping of their super configurations (IVY-218) - - - IMPROVE: Retain artifact filenames along the publish/resolve/retrieve process (IVY-54) - - IMPROVE: report Ant-task doesn't process the reports in batch (IVY-247) - - IMPROVE: make ReportOutputter pluggable and customizable (IVY-205) - - IMPROVE: add wildcard support for extending configurations (IVY-235) - - IMPROVE: add support for xslt parameters in the report task (IVY-227) - - IMPROVE: comments now aren't lost when delivering ivy files (IVY-226) - - IMPROVE: add sort of 'fallback'-mapping to the defaultconfmapping attribute (IVY-215) - - IMPROVE: artifact origin is not included in the default report (IVY-251) - - - FIX: VFS Resolve fails when trying to resolve a + version (IVY-237) - - FIX: report Ant-task doesn't use outputpattern for generating graphml reports (IVY-246) - - FIX: report Ant-task doesn't call init() on the internal XSLTProcess (IVY-248) - - FIX: value of confmappingoverride from imported configurations is lost when writing Ivy file (IVY-239) - - FIX: including configurations doesn't import the confmappingoverride setting (IVY-238) - - FIX: NullPointerException when the creation of Ivy file in cache fails (IVY-234) - - FIX: Ivy file containing 2 different versions of the same module is not deliverd correctly (IVY-229) - - FIX: ModuleRevisionId encode/decode doesn't work if revision is empty (IVY-233) - - FIX: cachepath task should preserve the order of the dependencies (IVY-225) - - FIX: specifying a defaultconfmapping adds dependencies of each unlisted configuration (IVY-214) - -* thanks to Johan Stuyts: - - NEW: always update artifacts when revision matches a regex pattern (IVY-189) - - NEW: provide Ant task for generating report about artifacts depended upon (IVY-194) - - - IMPROVE: change default cache artifact pattern to handle missing extension (IVY-196) - -* thanks to Karl Baum: - - NEW: "this" symbol for configuration mappings (IVY-183) - - - IMPROVE: performances improved (IVY-187) - - version 1.3.1 - 2006-03-30 -=============================== -- FIX: retrieval of multiple artifacts in different configurations does not work as expected (IVY-188) -- FIX: configuration http url include doesn't work with commons http client (IVY-203) -- FIX: problem with conflict resolution in transitive dependencies (IVY-199) -- FIX: pb with force when it comes after a conflict which has already been solved (IVY-193) -- FIX: POM files that reference to the parent artifact download fails (IVY-195) (thanks to Tat Leung) -- FIX: M2 compatibility does not take into account the . replacement for publishing artifacts (IVY-191) (thanks to Peter Hayes) -- FIX: artifactproperty does not set the [conf] token in the pattern to the correct value. It is always set to 'default'. (IVY-123) (thanks to Peter Oxenham) - - version 1.3 - 2006-03-17 -=============================== -This version is the same as 1.3-RC3 promoted to release status. -For known bugs and limitations, please refer to http://jira.jayasoft.org/ - - version 1.3-RC3 - 2006-03-06 -=============================== -- IMPROVE: Retrieve task now also optionally do ivy file downloads (IVY-167) (with the contribution of Costin Leau) - -- FIX: ivy variable substitution in ivy files (IVY-186) -- FIX: force attribute is not treated as it should in some cases (IVY-182) -- FIX: problem reading 'invalid' POMs (IVY-153) -- FIX: cryptic NPE due to spelling error in ivy.xml (IVY-177) -- FIX: conflicts with dynamic revisions not resolved properly (IVY-181) -- FIX: incorrect configuration definition gives misleading NullPointerException (IVY-175) -- FIX: throw an error when using a non-existing conflict manager as default (IVY-179) (thanks to Maarten Coene) -- FIX: eviction problem with different conflicts in multiple confs (IVY-173) - - version 1.3-RC2 - 2006-02-15 -=============================== -- IMPROVE: ivy now supports ${pom.version} in poms (IVY-174) -- IMPROVE: adds the possibility to disable concistency check (IVY-163) -- IMPROVE: add possibility to choose matcher on include exclude and conflict manager rules in ivy files, and on resolver per module in ivyconf (IVY-161) -- IMPROVE: add regexp management in the install ant task (IVY-154) - -- FIX: httclient is not registered for https urls (IVY-171) -- FIX: post resolve tasks like retrieve or cachepath should be able to run from cache information (IVY-169) -- FIX: resolve fails without appropriate message when cache is empty and a module in the repository has no revision (IVY-165) -- FIX: resolve problem with configuration inheritance (IVY-164) -- FIX: some files in cache detected by not used by Ivy for subsequent retrieves (IVY-159) -- FIX: HTML report shouldn't display the dependencies of evicted modules (IVY-158) (thanks to Maarten Coene) -- FIX: bug when an organisation or module or revision contains a space (IVY-157) -- FIX: cos-nonambig warnings (IVY-156) - - version 1.3-RC1 - 2006-01-25 -=============================== ---> compatiblity with previous version: -- the default place for the cache has changed, it is now in {USER_HOME}/.ivy/cache, instead of {USER_HOME}/.ivy-cache - please move this directory if you want to avoid unnecessary downloads -- modules are now logged as they are found, set ivy.log.module.when.found variable to false to avoid this - -- NEW: namespace system: a resolver can be declared to belong to a namespace, which itself - specify the transformation to apply to convert it from and to system namespace (IVY-147) -- NEW: pluggable module descriptor parsers let define new kind of module descriptor (IVY-146) (thanks to Maarten Coene) -- NEW: a new install task let add modules found in a repository in another one, even transitively (IVY-141) -- NEW: maven2 pom compatibility: most resolvers are now able to handle m2 pom as project metadata - and there is a new convertpom task able to convert a pom file to an ivy file (IVY-140) -- NEW: include configurations from external file (IVY-88) -- NEW: a new default resolver which let override ivy files and artifacts found on public repository - (ivyrep / ibiblio) and let publish modules in a local repository (IVY-132) -- NEW: ivyconf file inclusion in ivyconf files (IVY-99) -- NEW: macrodef feature in ivyconf for defining macro resolvers with parameters (IVY-98) -- NEW: conf fallback mechanism (IVY-145) -- NEW: exclusion now let exclude whole modules (IVY-144) -- NEW: ability to use a dependency instead of an ivy file in standalone mode (IVY-96) -- NEW: ability to output a path of dependencies in cache from the standalone mode (IVY-92) -- NEW: it is now possible to reference existing resolver in resolver containers (IVY-35) -- NEW: overwrite attribute in the publish task now let force overwrite of read only files (IVY-83) -- NEW: add a conflict manager ("strict") making build fail when a diamond conflict is found (thanks to Christer Jonsson) (IVY-118) - -- IMPROVE: generate xml report using ivy:report task (IVY-143) -- IMPROVE: possibility to configure ivy so that special revisions are not queried as fixed one at all (IVY-139) -- IMPROVE: better url querying management (IVY-138) (thanks to Bernard Niset) -- IMPROVE: do not add resolver info in ivy files in cache so that they can be safely used as usual ivy files in a repository (IVY-137) -- IMPROVE: review default conf mapping management (IVY-134) -- IMPROVE: add possibility for a chain to behave like a dual chain (IVY-131) -- IMPROVE: add possibility to avoid overwrite of an ivy variable when setting them in ivyconf.xml (IVY-127) -- IMPROVE: ability to exclude the root project from the buildlist (thanks to Constantine Vetoshev) (IVY-124) -- IMPROVE: exclusion of artifacts now works on transitive artifacts, and exclusion can specify organisation and/or module (IVY-116) -- IMPROVE: now dynamic revisions replacement by deliver task can be turned off (IVY-120) -- IMPROVE: better performance with deep transitive dependencies -- IMPROVE: allow optional parts in the patterns (IVY-102) (thanks to Maarten Coene) -- IMPROVE: ability to define variable directly in ivyconf.xml (IVY-100) -- IMPROVE: ability to use no revision in pattern with latest.integration dependency, artifacts being updated according to revision change in ivy file (if checkmodified is set to true) (IVY-95) -- IMPROVE: ability to specify a root module in buildlist to filter out unnecessary build files (IVY-93) (thanks to Kristian Cibulskis) -- IMPROVE: import system properties as ivy variables in standalone mode -- IMPROVE: string identifying a module is now clearly different from a path -- IMPROVE: better error message when publish fails due to readonly destination (IVY-83) -- IMPROVE: some javadoc improvements (IVY-136 IVY-129) (thanks to Stephen Nesbitt) - -- FIX: problem resolving dependencies when 2 module versions have different configurations (IVY-151) -- FIX: problem with inheritance between public and private conf (IVY-149) -- FIX: no variable replacement during the deliver step (IVY-133) -- FIX: conflict badly solved in some complex cases (IVY-130) -- FIX: mapping on conf * now only takes public configurations (IVY-126) -- FIX: bad dependency ivy files now causes failure (IVY-112) -- FIX: stack overflow error in contradictory conflict cases (IVY-117) -- FIX: publish now doesn't call deliver when not necessary (IVY-119) -- FIX: cachefileset was returning all artifacts for empty configuration (IVY-108) -- FIX: transitive and changing attribute were not copied in ivy files in cache (IVY-94) -- FIX: chain resolver now support latest strategy configuration (IVY-90) -- FIX: raise a clean error when a cyclic variable definition is found (IVY-75) -- FIX: clean ant project reference at the end of the build to improve usability in ide launching multiple builds in the same vm (like netbeans) (IVY-87 - IVY-115) -- FIX: ivy is now able to use simple ivy files in cache (doesn't need resolver info, use default one if no resolver is given) (IVY-86) -- FIX: private conf not accessible from other modules (IVY-76) -- FIX: root module configurations isolation bug fixed (IVY-84) -- FIX: changed the place where ivy stores master ivy files in cache to not overlap - with dependencies one (IVY-85) -- FIX: bug in ResourceHelper didn't let override resource easily (IVY-80) -- FIX: throws a circular dependency exception when a circular dependency is found - instead of failing silently (IVY-79) - - version 1.2a - 2005-09-14 -=============================== -Note : version 1.2 previously published on ivy site was not the real 1.2 due to a bad release operation - version 1.2a should then be used instead - -- new ivy.deps.changed property set if there are changes since last resolve (IVY-71) -- new buildlist task: calculate order of dependencies of subprojects for easy multi-projects builds (IVY-69) -- accept organization as token (IVY-55) -- added type filtering mechanism on resolve task (IVY-45) -- detect and warn about resolver using ivy cache as repository (IVY-53) -- new transitive attribute on dependency, which enable to disable transitive dependency - management on a particular dependency (thanks to Ingo Adler) (IVY-20) -- new '@' in dependency configuration mapping declaration, used to indicate that a configuration maps to itself - useful with *, '*->@' meaning that all configurations of the module maps to their equivalent (same name) - in the dependency (IVY-52) -- new changing attribute on dependencies indicate that the dependency artifacts - may change even without revision change, but with only a new ivy file with new - publication date -- new useRemoteConfig on conf tag in ivyconf.xml, tells to use remote configuration file - for repository config -- new type filtering in cachepath task -- new cachefileset task: builds an ant fileset of artifacts in cache -- publish task now uses srcivypattern for ivy files finding and for delivery -- better debug and error messages (IVY-60 IVY-61) -- added a javadoc target in ant build (thanks to joshua nichols) -- FIX: module descriptors sort was failing in some case cases (fix by Karl Baum) -- FIX: Ivy complains about schema directive (IVY-64) -- FIX: 'null' status attribute in module descriptor (IVY-62) -- FIX: report header contains incorrect link after resolve for multiple, comma-separated configurations (IVY-57) -- FIX: error retrieving dependencies with a '+' in their revision if the ivy file doesn't exist - fixed by maarten coene (IVY-59) -- FIX: trying to resolve latest with no revision in pattern caused a StackOverflowError (IVY-56) -- FIX: now handle transitive eviction (IVY-51) -- FIX: resolve now store resolved file id in ivy variables, so that multiple resolve calls - can be followed by multiple retrieve, each retrieve will use the last resolve info (IVY-49) -- FIX: IllegalStateException on retrieve done from command line -- FIX: checks ivy files data consistency with asked info (org, module name and revision) -- FIX: use AUTH configuration for configuration file -- IMPROVE: added publish handling from command line (IVY-48) - - version 1.1 - 2005-06-13 -=============================== -- remote configuration (if available) of ivyrep and ibiblio patterns and roots -- new detailed messages when ivy fails to reach an url (thanks to Nicolas) -- new artifactproperty task, which enables to set a property for each dependency artifacts - resolved by ivy -- new defaultconf attribute in ivy file dependencies, to change the default conf to use in the file - when no conf is specified for a dependency -- add the ability to change the xsl file and report name pattern used by report task -- http listing now compatible with tomcat listing (tested with 5.0.28) -- pub revision in deliver task now defaults to timestamp if not provided by any other way -- debug messages improvements, with configuration dump among others -- new var task, enables to set ivy variables from ant -- now defaults for ivyrep and ibiblio resolver are configurable by variables -- refactoring: introduce the notion of BasicResolver, Repository, Resource, RepositoryResolver, - making much easier the task of writing basic resolvers -- added checkmodified attribute on all basic resolvers, which defaults to ${ivy.resolver.default.check.modified} - This makes ivy check last modified date of ivy files to see it its cache is up to date -- artifacts download are now first made to a temp file, which is renamed - only at the end of the download. This prevent interrupted downloads to be - considered as finished -- FIX: handle proxy configuration with http-client (thanks to Nicolas) -- FIX: remove dependency on ant outside of ant integration classes -- FIX: resolve problem when conflicts on latest revisions -- FIX: allow use of any kind of URL in IvyRepResolver (both ivyroot and artroot) and IBibiblioResolver -- FIX: chain resolver can now be used for artifacts part of dual resolver -- FIX: now detects and warn about circular dependencies -- FIX: cachepath task now takes pathid as parameter instead of id, to prevent - special handling from ant -- FIX: ivy.xsd: set artifact minOccurs to 0 in publications - -Thanks to John Shields from Robert Half International, Inc.: -- FIX: no more infinite loop when a conflict occurs between a latest subversion and a fully resolved revision -- FIX: BasicURLHandler now closes its connections -- FIX: ApacheURLLister now works with capital letter in revisions and truncated names -- now use of ivy variables is allowed in ivy files -- added a null check in pattern helper substitute - - version 1.0 - 2005-04-26 -=============================== -1.0-rc3 has been promoted to 1.0 on 2005-04-26 - -Known bugs and limitations: -- cyclic dependencies result in StackOverflowError -- infinite loop in rare cases when a conflict occur between a latest subversion and a fully resolved revision -- url connections not closed properly when not using commons-httpclient -- latest does not work with http urls in some cases, when the name of the link is truncated in the web page - - version 1.0-rc3 - 2005-04-21 -=============================== -- IMPROVE: added debug messages on variables setting -- FIX: ivyconf now able to load a properties file given as url -- FIX: deliver pub date now actually defaults to 'now' -- FIX: all tasks attributes now substitute ivy variables - - version 1.0-rc2 - 2005-04-18 -=============================== -- IMPROVE: improved messages: more debug, more verbose, and more details on failures -- FIX: bug with '\' in path patterns -- FIX: bug with relative paths patterns -- FIX: configure task tries ivy.conf.file as relative to base dir and to current dir -- FIX: file system resolver publishes ivy files with ivy pattern -- FIX: 0 content length considered as non existing (behaviour of jre 5.0 on linux) - => empty ressources are now considered as non existing - - version 1.0-rc1 - 2005-04-12 -=============================== -- add report task, which enables to generates reports of dependencies, including a graph - ready to be layed out by yEd -- add exclude feature in dependency -- include exclude feature now handles regexps -- new latest strategy: latest revision now uses a "php version_compare" like algorithm, whereas - lexicographic comparison is now available in latest lexicographic -- enhance xml resolve report details -- FIX: better separation between root configurations -- FIX: XmlModuleDescriptorUpdater now preserves xml header -- FIX: modules number in report (displayed at the end of resolve) - - version 0.9 - 2005-04-06 -=========================== -- clearly differenciate pattern tokens from variables, by using brackets as delimiter in pattern tokens - => WARNING: this introduce changes in all patterns syntax, and thus does not provide compatibility - with previous versions -- ChainResolver are now able to publish (delegating the call to the first resolver in the chain) -- DualResolver sub resolvers are now registered in Ivy -- more precise message on eviction -- add validate attribute on most resolvers -- ivy files validation handling review -- use ivy variables in ant tasks to get default values for attributes -- documentation update for configuring ivy -- FIX: dependencies order not taken into account during resolve -- FIX: evicting modules also evict confs -- FIX: NPE during resolve when a dependency ivy file has no publication date -- FIX: check nullity of artifact download reports - - version 0.8 - 2005-03-30 -=========================== -- added validate attribute on resolve, retrieve and publish, which allows to disable ivy file validation - against ivy.xsd (useful to parse future compatible ivy files) -- ant properties are now available in ivyconf file -- unified default properties in ivyconf, with better independance from url or file -- added ext on artifacts: this enable to distinguish artifact extension from artifact - type, util in cases where it differs (example: 'src' type with 'zip' extension, 'ivy' type with 'xml' extension, ...) -- added publish artifacts feature, which enable to publish declared artifacts of a module to a repository - described by a dependency resolver. It currently works only with filesystem resolver. -- url resolver now handles latest with file urls and http ones (tested only with apache server) -- added latest strategy concept: the way to determine which artifact is the latest - is now configurable on resolvers handling latest. -- added parameter on chain resolver to say if it should return first found or - try to find the latest among all if asked -- a module can now publish no artifact, useful for virtual modules consisting only - of integration of other modules -- added conflict management at resolve time: during resolve, modules in conflict can be evicted - and thus not downloaded -- added ivyrep resolver, using ivyrep to find ivy files, and ibiblio for artifacts -- use ivyrep instead of ibiblio as default resolver -- added more info in ivy files (description, homepage, ivy authors, license, public repository, ...) -- now cache layout is configurable, using cacheIvyPattern and cacheArtifactPattern - attributes on conf element in ivyconf.xml -- changed default cache layout: artifacts are separated by type -- added cachepath task, which enables to build an ant path of artifacts in cache required for a conf - - version 0.7 - 2005-03-11 -=========================== -- added latest sub revision feature: you can now select the latest sub revision of a module - using a +. For instance, "1.0+" selects the latest revision starting with 1.0. (thanks to jonas for the idea) -- haltonfailure now defaults to true (as suggested by Jeroen) -- shorter info lines to better view important info (as suggested by Jeroen) -- retrieve now checks if files are up to date before copying them from cache. This feature - can be disabled using the checkUpToDate attribute in ivy configuration file. -- do not download dependencies when not necessary during publication (as suggested by Daniele) -- bug fix: better handling of publish without recursive delivery - - version 0.6.1 - 2005-02-11 -============================= -- bug fix: conf extends problem with publications -- bug fix: typedef badly handled in ivyconf.xml -- bug fix: default properties loading in ivy configure loaded using task classloader - - version 0.6 - 2005-02-03 -=========================== -+ functional -- added haltonfailure attribute on resolve and retrieve task, so that build can be halt when - resolve or retrieve fails -- added dependency artifacts filtering feature, enabling to work better with ibiblio -- ibiblio resolver can now be configured to use any maven like repository, with root and pattern attributes -- added download progression info on resolve -- default cache is now in user home (.ivy-cache in user home), so that cache is shared - by default for all projects of the same user -- added public access to method getDependencies(...) in Ivy, which resolve dependencies without - downloading artifacts -- added DualResolver, which allows to have ivy files in one place and artifacts in another one - -+ non functional -- added some unit tests -- deep review of ivy file reference documentation - -+ bugs and refactoring -- bug fix: SimpleURLResolver not handling the case when there is no ivy file -- refactoring: URLResolver renamed to AbstractURLResolver -- refactoring: SimpleURLResolver renamed to URLResolver - - version 0.5.1 - 2005-01-16 -============================= -- Bug Fix: NPE in publish task when no delivery.list.file is provided -- documentation update - - version 0.5 - 2005-01-12 -=========================== -initial public version + Ivy + - The agile open source dependency manager + - http://incubator.apache.org/ivy + ============================================ + +for detailed view of each issue, please consult http://issues.apache.org/jira/browse/IVY + + Committers + Maarteen Coene + Xavier Hanin + Gilles Scokart + + Contributors + Ingo Adler + Stephane Bailliez + Karl Baum + Jeffrey Blattman + Matthieu Brouillard + Kristian Cibulskis + Pierre Hägnestrand + Peter Hayes + Matt Inger + Anders Janmyr + Christer Jonsson + Matthias Kilian + Gregory Kisling + Tat Leung + Costin Leau + Antoine Levy-Lambert + William Lyvers + Jan Materne + Stephen Nesbitt + Joshua Nichols + Bernard Niset + Glen Marchesani + Mathias Muller + Peter Oxenham + Emmanuel Pellereau + Roshan Punnoose + Damon Rand + Christian Riege + Jean-Baptiste Quenot + Andreas Sahlbach + John Shields + Johan Stuyts + John Williams + Jaroslaw Wypychowski + + version in SVN +===================================== +- NEW: A checkstyle report is generated (IVY-483) (thanks to Jan Materne) +- NEW: Hide private or specific conf when publishing (IVY-77) + +- IMPROVEMENT: Use maven2 repository to download dependencies +- IMPROVEMENT: Allow "main" parameters to be passed directly (instead of using -args flag) (IVY-480) (thanks to Archie Cobbs) +- IMPROVEMENT: Remove @author tags (thanks to Stephane Bailliez) +- IMPROVEMENT: Remove use of deprecated elements in ivysettings.xml (IVY-505) (with contribution from Jan Materne) + +- FIX: The deprecated "keep" attribute on post resolve tasks causes an error (IVY-517) +- FIX: Some circular dependencies not retrieved (IVY-400) +- FIX: ${version} property not recognized in poms (IVY-512) +- FIX: Bug on handling dependency artifacts when a module configuration is specified (IVY-507) +- FIX: Configure fails when having httpclient in classpath without commons-logging (IVY-502) +- FIX: packaging data not parsed in maven 2 pom (IVY-500) (thanks to Jeffrey Blattman) +- FIX: install ant task: requires default resolver in ivy settings (IVY-477) +- FIX: Ant project reference lost from context on multiple ant calls in single thread (IVY-497) (thanks to Jaroslaw Wypychowski) +- FIX: EOL in the doc pages (IVY-470) +- FIX: Cache is storing ArtifactOrigin properties with no guarantee of unicity and types telescope during resolve. (IVY-430) (thanks to Stephane Bailliez) +- FIX: ivy:install ant task does not fail on error (IVY-475) (thanks to Jeffrey Blattman) +- FIX: Credentials are shown in build log even if debug is not enabled (IVY-486) (thanks to Gilles Scokart) +- FIX: Post-Resolve task shouldn't set the 'resolveid' (IVY-489) +- FIX: build fails without emma code coverage JARs present (IVY-478) +- FIX: buildlist broken - regression in 2.0.0-alpha1-incubating (IVY-493) +- FIX: Circular dependency startegy in buildlist (IVY-509) +- FIX: ivy should stop telling me off twice for ivyconf.xml files (IVY-513) + + 2.0.0-alpha1-incubating +===================================== +- NEW: define artifacts not declared by the dependency module descriptor (IVY-419) +- NEW: Module wide exclude (IVY-431) +- NEW: The default public resolver used is now ibiblio with m2 compatible mode (IVY-463) + +- IMPROVE: OSGIfy ivy artifacts (IVY-464) (thanks to Costin Leau) +- IMPROVE: Let user specify Ivy file when using a post-resolve task (IVY-455) +- IMPROVE: IvyArtifactProperty and IvyArtifactReport tasks should be a post resolve task (IVY-452) +- IMPROVE: Rename ivy configuration in settings to remove ambiguity on configuration meaning (IVY-438) +- IMPROVE: Please typedef CacheResolver as "cache" for us (IVY-359) +- IMPROVE: ivy:retrieve should be able to create symlinks (IVY-353) (thanks to John Williams) +- IMPROVE: Ability to have multiple roots in the task (IVY-340) (thanks to Matt Inger) +- IMPROVE: Refactoring / documentation / test of matcher package (IVY-375) (thanks to Stephane Bailliez) +- IMPROVE: Add a unit test to verify that latest.integration accepts released modules (IVY-394) (thanks to Gilles Scokart) +- IMPROVE: New "modules in use" section in console report at the end of resolve (IVY-373) (thanks to John Wiliams) +- IMPROVE: Generated XML reports now contains more information about the resolved module (IVY-446) + +- FIX: ivy-retrieve failure when explicit absolute 'ivy.dep.file' path specified (IVY-396) +- FIX: IvyPostResolve Task doesn't reuse Ivy file of previous resolve (IVY-458) +- FIX: Ivy standalone is passing null args to main method when invoking with no args (IVY-457) +- FIX: Invalid error report with m2compatible resolver (IVY-456) +- FIX: IvyPostResolve Task doesn't use specified cache for the resolve (IVY-453) +- FIX: XmlModuleDescriptorWriterTest not working with Java 6 (IVY-374) +- FIX: Conflict managers ignored, when assigned to modules in Ivy configuration (setting, ivyconf.xml) (IVY-448) +- FIX: Ivy should fail if ';' has been used in publications/artifact/@conf of ivy.xml (IVY-441) +- FIX: Ivy should fail where dependency uses undefined configuration (IVY-442) +- FIX: Dynamic revision not calculated properly when using multiple directories (IVY-427) +- FIX: LatestRevisionStrategy.sort() doesn't sort as specified (IVY-435) +- FIX: setting m2compatible on ibiblio resolver overwrite root and pattern settings (IVY-437) +- FIX: ivy.revision property not set correctly for second resolve (IVY-429) +- FIX: NPE when no organisation or no name is provided in module element of ivyconf (IVY-422) +- FIX: FileUtil#copy(File src, File dest, CopyProgressListener l, boolean overwrite) (IVY-420) +- FIX: Invalid pom parsing when version is only declared in parent (IVY-436) +- FIX: ${project.groupId} and ${project.version} not processed correctly in poms (IVY-425) +- FIX: Incorrect pom parsing with profile (IVY-423) +- FIX: Ivy doesn't recognize maven2 classifiers (IVY-418) +- FIX: PomModuleDescriptorParser fails with nested profile dependency (IVY-392) (thanks to William Lyvers) +- FIX: Static revision replacement is not working when delivering an artifact with a dependency having extra attributes (IVY-415) +- FIX: Static revision replacement is not working when delivering an artifact with a dependency on a branch (IVY-404) +- FIX: latest-time conflict manager not working properly (IVY-407) +- FIX: LatestRevisionStrategy do not consider all dynamic revisions properly (IVY-383) (thanks to John Williams for the unit test) +- FIX: IOException during publish causes NullPointerException (IVY-371) +- FIX: Comments in ivy.xml duplicated (IVY-336) (thanks to Gilles Scokart) +- FIX: Ivy failure when the ivy.xml file contains non US-ASCII characters (IVY-346) (thanks to Gilles Scokart) +- FIX: Urlresolver is not possible to use dynamic revisions on nonstandard repository structure (IVY-350) (thanks to Pierre Hägnestrand) + + + version 1.4.1 - 2006-11-09 +===================================== +- IMPROVE: ability to rebuild all dependent projects from a leaf (IVY-101) +- IMPROVE: Artifact pattern list attribute for the ivy:publish (IVY-113) +- IMPROVE: Measure code coverage (IVY-323) +- IMPROVE: add release target to build file (IVY-339) +- IMPROVE: Add a 'conf' parameter to the ivy 'publish' ant task (IVY-322) (thanks to Emmanuel Pellereau) + +- FIX: retrieve fails when resolve is done with useOrigin set to true (IVY-304) +- FIX: IVY complains about non-existent reports in the cache directory (IVY-315) +- FIX: Typo in failureproperty attribute of Ant resolve task (IVY-327) (thanks to Jean-Baptiste Quenot) +- FIX: ivy:resolve useOrigin fails to behave correctly (IVY-332) +- FIX: ChainVersionMatcher doesn't handle IvyAware children version matchers (IVY-331) +- FIX: latest. does not work properly when no matching revision exist (IVY-318) +- FIX: attribute name in macrodef is not handled as expected (IVY-319) +- FIX: confmappingoverride doesn't work for configurations extending from "*(public)" (IVY-326) + + + version 1.4 - 2006-10-09 +===================================== +Version 1.4-RC2 has been promoted to 1.4 on 2006-10-09, with documentation update. + +Known bugs and limitations: +- references in resolvers are not resolved 'in-time' with macrodef (IVY-319) +- latest. does not work properly when no matching revision exist (IVY-318) +- IVY complains about non-existent reports in the cache directory (IVY-315) +- retrieve fails when resolve is done with useOrigin set to true (IVY-304) + + + version 1.4-RC2 - 2006-09-27 +===================================== +- FIX: m2compatible flag is ignored for display of failed artifact searches (IVY-303) +- FIX: AntCallTriggerTest and AntBuildTriggerTest fail when run from ivy build.xml (IVY-310) +- FIX: Classloader problem with ant (IVY-311) +- FIX: Make resolve overview more compact (IVY-299) +- FIX: Could not write to "tmp:///webdav_tmp.c1" because it is read-only (IVY-312) + + version 1.4-RC1 - 2006-09-17 +================================= +Incompatibility with previous versions: +--------------------------------------- +* usage: + - no known major incompatiblity + - build list task now requires a configured ivy instance (configure will automatically be called if you don't call it explicitly) + - publish now requires the published ivy file to have the published revision (automatic if you use deliver) + +* API: + - Numerous API changes especially in the BasicResolver class and subclasses due to the introduction of VersionMatcher, + this may break some custom dependency resolvers or other tools or plugins depending directly on Ivy API + +Changes: +-------- +* thanks to Jayasoft: + - NEW: ivy report generate full graph from automated build (IVY-155) + - NEW: support for build number calculation (IVY-276) + - NEW: find modules in repository (IVY-275) + - NEW: explicitly specify artifact download URL (IVY-271) + - NEW: introduce branch management (IVY-269) + - NEW: resolve dependencies directly without using an ivy file (IVY-268) + - NEW: ability to invoke any build scripts for dependencies (IVY-68) + - NEW: support sftp repository (IVY-267) + - NEW: pluggable version matcher (IVY-219) + - NEW: support for version ranges (IVY-295) + - NEW: dependency based on dependency status (IVY-47) + - NEW: add possibility to define extra attributes in ivy files (IVY-217) + - NEW: option to omit specific confs and allow the rest (IVY-66) + - NEW: use custom classloader for plugins (IVY-220) + - NEW: adding to SPECIAL_MEANINGS in LatestRevisionStrategy (IVY-121) + - NEW: Allow use of system properties in ivyconf.xml (IVY-228) + + - IMPROVE: allow to use file-system repository directly without cache (IVY-211) + - IMPROVE: deliver task use a default value for revision (IVY-252) + - IMPROVE: better documentation distribution (IVY-274) - in progress + - IMPROVE: define conflict manager per organisation/module in ivyconf (IVY-270) + - IMPROVE: transitive parameter in resolve (IVY-21) + - IMPROVE: add syncing feature in retrieve (IVY-33) + - IMPROVE: use of md5 and/or sha1 files to check downloads (IVY-27) + - IMPROVE: possible to use m2compatible without automatically using POMs as well (IVY-263) + - IMPROVE: support for circular dependencies (IVY-202) + - IMPROVE: make status list configurable (IVY-242) + - IMPROVE: use only ivy patterns for listing revisions when module desciptor is required (allownomd = false) (IVY-166) + - IMPROVE: implement strict haltonfailure if ivy.xml is not found (IVY-110) + - IMPROVE: artifact's "name" attribute could be omitted (IVY-231) + - IMPROVE: ivy standalone now return error status (IVY-152) + - IMPROVE: log messages do not display most specfic resolver name (IVY-170) + - IMPROVE: prints URL before downloading in verbose mode (IVY-257) + - IMPROVE: incorrect value in status attribute causes silent failure (IVY-259) + - IMPROVE: suport empty dependencies tag in an ivy file (IVY-281) + - IMPROVE: isolate dependency resolution from artifact downloading (IVY-254) + - IMPROVE: Pass artifact to repository when calling "put" (IVY-192) + - IMPROVE: Do not publish ivy file with bad revision, and allow to force the deliver when calling publish task (IVY-245) + + - FIX: Problem with multiple artifact includes in transitive dependencies (IVY-283) + - FIX: Endless recursion in report (IVY-284) + - FIX: http url lister doesn't work when link text has spaces (IVY-282) + - FIX: Incorrect ant log level (IVY-279) + - FIX: Wrong resolution of dependencies if artifacts specified explicitly (IVY-261) + - FIX: Multiple versions of dependencies appearing in retrieve (IVY-264) + - FIX: Too many false CircularDependencyException errors thrown (IVY-230) + - FIX: CircularDependencyException not always thrown (IVY-184) + - FIX: NullPointer in BasicResolver (IVY-258) + - FIX: Bad diagnostics message when no space left (IVY-250) + - FIX: Maven2 POM support can find groupId from "parent" element (IVY-262) + - FIX: Parent version is expected to be equal to the module version in POM (IVY-241) + - FIX: problem with cache and returnFirst (IVY-207) + - FIX: modules splitted across a chain are not handled correctly (IVY-206) + - FIX: problem with conf extension and latest revisions (IVY-240) + - FIX: The clean-cache target in /src/example/hello-ivy/build.xml file refers to ${user.home}/.ivy-cache instead of ${user.home}/.ivy/cache/ (IVY-265) + +* thanks to Ivy Community: + - NEW: SSH Resolver added and aligned with SFTP resolver (IVY-273) (thanks to Andreas Sahlbach) + - NEW: ability to turn off transitivity at configuration level (IVY-103) (thanks to Karl Baum and Maarten Coene) + - NEW: a conflict manager that is able to allow implementation changes but not api changes (1.2.x - OK), (1.x.x - Not OK) (IVY-223) (thanks to Anders Janmyr) + - NEW: enhance standalone mode to execute java program by creating classloader of dependant jars from cache (IVY-210) (thanks to Peter Hayes) + - NEW: addition of Vfs Resolver which uses Commons-Vfs to resolve files (IVY-128) (thanks to Glen Marchesani, Matt Inger and Stephen Nesbitt) + + - IMPROVE: use global properties in the recursive delivery (IVY-222) (with the contribution of Roshan Punnoose) + - IMPROVE: better handling of authentication (thanks to Christian Riege) + + - FIX: Ant log messsages not embedded in task log (IVY-280) (thanks to Gilles Scokart) + - FIX: Ivy fails when downloading from a server that supports NTLM authentication (IVY-213) (thanks to Damon Rand) + - FIX: Delivered Ivy files with incomplete last line. (IVY-125) (thanks to Matthias Kilian) + - FIX: the vfs resolver should not log passwords (IVY-292) (thanks to Antoine Levy-Lambert) + +* thanks to Maarten Coene: + - NEW: add failureproperty parameter to the resolve task (IVY-285) + - NEW: Add type filtering to retrieve task (IVY-260) + - NEW: Add selectors to the configuration mapping (IVY-253) + - NEW: Add Ant task to retrieve information from an Ivy file without doing a resolve (IVY-255) + - NEW: add option to cachepath task to create a path with local artifact paths (IVY-221) + - NEW: allow extending configurations to override the mapping of their super configurations (IVY-218) + + - IMPROVE: Retain artifact filenames along the publish/resolve/retrieve process (IVY-54) + - IMPROVE: report Ant-task doesn't process the reports in batch (IVY-247) + - IMPROVE: make ReportOutputter pluggable and customizable (IVY-205) + - IMPROVE: add wildcard support for extending configurations (IVY-235) + - IMPROVE: add support for xslt parameters in the report task (IVY-227) + - IMPROVE: comments now aren't lost when delivering ivy files (IVY-226) + - IMPROVE: add sort of 'fallback'-mapping to the defaultconfmapping attribute (IVY-215) + - IMPROVE: artifact origin is not included in the default report (IVY-251) + + - FIX: VFS Resolve fails when trying to resolve a + version (IVY-237) + - FIX: report Ant-task doesn't use outputpattern for generating graphml reports (IVY-246) + - FIX: report Ant-task doesn't call init() on the internal XSLTProcess (IVY-248) + - FIX: value of confmappingoverride from imported configurations is lost when writing Ivy file (IVY-239) + - FIX: including configurations doesn't import the confmappingoverride setting (IVY-238) + - FIX: NullPointerException when the creation of Ivy file in cache fails (IVY-234) + - FIX: Ivy file containing 2 different versions of the same module is not deliverd correctly (IVY-229) + - FIX: ModuleRevisionId encode/decode doesn't work if revision is empty (IVY-233) + - FIX: cachepath task should preserve the order of the dependencies (IVY-225) + - FIX: specifying a defaultconfmapping adds dependencies of each unlisted configuration (IVY-214) + +* thanks to Johan Stuyts: + - NEW: always update artifacts when revision matches a regex pattern (IVY-189) + - NEW: provide Ant task for generating report about artifacts depended upon (IVY-194) + + - IMPROVE: change default cache artifact pattern to handle missing extension (IVY-196) + +* thanks to Karl Baum: + - NEW: "this" symbol for configuration mappings (IVY-183) + + - IMPROVE: performances improved (IVY-187) + + version 1.3.1 - 2006-03-30 +=============================== +- FIX: retrieval of multiple artifacts in different configurations does not work as expected (IVY-188) +- FIX: configuration http url include doesn't work with commons http client (IVY-203) +- FIX: problem with conflict resolution in transitive dependencies (IVY-199) +- FIX: pb with force when it comes after a conflict which has already been solved (IVY-193) +- FIX: POM files that reference to the parent artifact download fails (IVY-195) (thanks to Tat Leung) +- FIX: M2 compatibility does not take into account the . replacement for publishing artifacts (IVY-191) (thanks to Peter Hayes) +- FIX: artifactproperty does not set the [conf] token in the pattern to the correct value. It is always set to 'default'. (IVY-123) (thanks to Peter Oxenham) + + version 1.3 - 2006-03-17 +=============================== +This version is the same as 1.3-RC3 promoted to release status. +For known bugs and limitations, please refer to http://jira.jayasoft.org/ + + version 1.3-RC3 - 2006-03-06 +=============================== +- IMPROVE: Retrieve task now also optionally do ivy file downloads (IVY-167) (with the contribution of Costin Leau) + +- FIX: ivy variable substitution in ivy files (IVY-186) +- FIX: force attribute is not treated as it should in some cases (IVY-182) +- FIX: problem reading 'invalid' POMs (IVY-153) +- FIX: cryptic NPE due to spelling error in ivy.xml (IVY-177) +- FIX: conflicts with dynamic revisions not resolved properly (IVY-181) +- FIX: incorrect configuration definition gives misleading NullPointerException (IVY-175) +- FIX: throw an error when using a non-existing conflict manager as default (IVY-179) (thanks to Maarten Coene) +- FIX: eviction problem with different conflicts in multiple confs (IVY-173) + + version 1.3-RC2 - 2006-02-15 +=============================== +- IMPROVE: ivy now supports ${pom.version} in poms (IVY-174) +- IMPROVE: adds the possibility to disable concistency check (IVY-163) +- IMPROVE: add possibility to choose matcher on include exclude and conflict manager rules in ivy files, and on resolver per module in ivyconf (IVY-161) +- IMPROVE: add regexp management in the install ant task (IVY-154) + +- FIX: httclient is not registered for https urls (IVY-171) +- FIX: post resolve tasks like retrieve or cachepath should be able to run from cache information (IVY-169) +- FIX: resolve fails without appropriate message when cache is empty and a module in the repository has no revision (IVY-165) +- FIX: resolve problem with configuration inheritance (IVY-164) +- FIX: some files in cache detected by not used by Ivy for subsequent retrieves (IVY-159) +- FIX: HTML report shouldn't display the dependencies of evicted modules (IVY-158) (thanks to Maarten Coene) +- FIX: bug when an organisation or module or revision contains a space (IVY-157) +- FIX: cos-nonambig warnings (IVY-156) + + version 1.3-RC1 - 2006-01-25 +=============================== +--> compatiblity with previous version: +- the default place for the cache has changed, it is now in {USER_HOME}/.ivy/cache, instead of {USER_HOME}/.ivy-cache + please move this directory if you want to avoid unnecessary downloads +- modules are now logged as they are found, set ivy.log.module.when.found variable to false to avoid this + +- NEW: namespace system: a resolver can be declared to belong to a namespace, which itself + specify the transformation to apply to convert it from and to system namespace (IVY-147) +- NEW: pluggable module descriptor parsers let define new kind of module descriptor (IVY-146) (thanks to Maarten Coene) +- NEW: a new install task let add modules found in a repository in another one, even transitively (IVY-141) +- NEW: maven2 pom compatibility: most resolvers are now able to handle m2 pom as project metadata + and there is a new convertpom task able to convert a pom file to an ivy file (IVY-140) +- NEW: include configurations from external file (IVY-88) +- NEW: a new default resolver which let override ivy files and artifacts found on public repository + (ivyrep / ibiblio) and let publish modules in a local repository (IVY-132) +- NEW: ivyconf file inclusion in ivyconf files (IVY-99) +- NEW: macrodef feature in ivyconf for defining macro resolvers with parameters (IVY-98) +- NEW: conf fallback mechanism (IVY-145) +- NEW: exclusion now let exclude whole modules (IVY-144) +- NEW: ability to use a dependency instead of an ivy file in standalone mode (IVY-96) +- NEW: ability to output a path of dependencies in cache from the standalone mode (IVY-92) +- NEW: it is now possible to reference existing resolver in resolver containers (IVY-35) +- NEW: overwrite attribute in the publish task now let force overwrite of read only files (IVY-83) +- NEW: add a conflict manager ("strict") making build fail when a diamond conflict is found (thanks to Christer Jonsson) (IVY-118) + +- IMPROVE: generate xml report using ivy:report task (IVY-143) +- IMPROVE: possibility to configure ivy so that special revisions are not queried as fixed one at all (IVY-139) +- IMPROVE: better url querying management (IVY-138) (thanks to Bernard Niset) +- IMPROVE: do not add resolver info in ivy files in cache so that they can be safely used as usual ivy files in a repository (IVY-137) +- IMPROVE: review default conf mapping management (IVY-134) +- IMPROVE: add possibility for a chain to behave like a dual chain (IVY-131) +- IMPROVE: add possibility to avoid overwrite of an ivy variable when setting them in ivyconf.xml (IVY-127) +- IMPROVE: ability to exclude the root project from the buildlist (thanks to Constantine Vetoshev) (IVY-124) +- IMPROVE: exclusion of artifacts now works on transitive artifacts, and exclusion can specify organisation and/or module (IVY-116) +- IMPROVE: now dynamic revisions replacement by deliver task can be turned off (IVY-120) +- IMPROVE: better performance with deep transitive dependencies +- IMPROVE: allow optional parts in the patterns (IVY-102) (thanks to Maarten Coene) +- IMPROVE: ability to define variable directly in ivyconf.xml (IVY-100) +- IMPROVE: ability to use no revision in pattern with latest.integration dependency, artifacts being updated according to revision change in ivy file (if checkmodified is set to true) (IVY-95) +- IMPROVE: ability to specify a root module in buildlist to filter out unnecessary build files (IVY-93) (thanks to Kristian Cibulskis) +- IMPROVE: import system properties as ivy variables in standalone mode +- IMPROVE: string identifying a module is now clearly different from a path +- IMPROVE: better error message when publish fails due to readonly destination (IVY-83) +- IMPROVE: some javadoc improvements (IVY-136 IVY-129) (thanks to Stephen Nesbitt) + +- FIX: problem resolving dependencies when 2 module versions have different configurations (IVY-151) +- FIX: problem with inheritance between public and private conf (IVY-149) +- FIX: no variable replacement during the deliver step (IVY-133) +- FIX: conflict badly solved in some complex cases (IVY-130) +- FIX: mapping on conf * now only takes public configurations (IVY-126) +- FIX: bad dependency ivy files now causes failure (IVY-112) +- FIX: stack overflow error in contradictory conflict cases (IVY-117) +- FIX: publish now doesn't call deliver when not necessary (IVY-119) +- FIX: cachefileset was returning all artifacts for empty configuration (IVY-108) +- FIX: transitive and changing attribute were not copied in ivy files in cache (IVY-94) +- FIX: chain resolver now support latest strategy configuration (IVY-90) +- FIX: raise a clean error when a cyclic variable definition is found (IVY-75) +- FIX: clean ant project reference at the end of the build to improve usability in ide launching multiple builds in the same vm (like netbeans) (IVY-87 - IVY-115) +- FIX: ivy is now able to use simple ivy files in cache (doesn't need resolver info, use default one if no resolver is given) (IVY-86) +- FIX: private conf not accessible from other modules (IVY-76) +- FIX: root module configurations isolation bug fixed (IVY-84) +- FIX: changed the place where ivy stores master ivy files in cache to not overlap + with dependencies one (IVY-85) +- FIX: bug in ResourceHelper didn't let override resource easily (IVY-80) +- FIX: throws a circular dependency exception when a circular dependency is found + instead of failing silently (IVY-79) + + version 1.2a - 2005-09-14 +=============================== +Note : version 1.2 previously published on ivy site was not the real 1.2 due to a bad release operation + version 1.2a should then be used instead + +- new ivy.deps.changed property set if there are changes since last resolve (IVY-71) +- new buildlist task: calculate order of dependencies of subprojects for easy multi-projects builds (IVY-69) +- accept organization as token (IVY-55) +- added type filtering mechanism on resolve task (IVY-45) +- detect and warn about resolver using ivy cache as repository (IVY-53) +- new transitive attribute on dependency, which enable to disable transitive dependency + management on a particular dependency (thanks to Ingo Adler) (IVY-20) +- new '@' in dependency configuration mapping declaration, used to indicate that a configuration maps to itself + useful with *, '*->@' meaning that all configurations of the module maps to their equivalent (same name) + in the dependency (IVY-52) +- new changing attribute on dependencies indicate that the dependency artifacts + may change even without revision change, but with only a new ivy file with new + publication date +- new useRemoteConfig on conf tag in ivyconf.xml, tells to use remote configuration file + for repository config +- new type filtering in cachepath task +- new cachefileset task: builds an ant fileset of artifacts in cache +- publish task now uses srcivypattern for ivy files finding and for delivery +- better debug and error messages (IVY-60 IVY-61) +- added a javadoc target in ant build (thanks to joshua nichols) +- FIX: module descriptors sort was failing in some case cases (fix by Karl Baum) +- FIX: Ivy complains about schema directive (IVY-64) +- FIX: 'null' status attribute in module descriptor (IVY-62) +- FIX: report header contains incorrect link after resolve for multiple, comma-separated configurations (IVY-57) +- FIX: error retrieving dependencies with a '+' in their revision if the ivy file doesn't exist - fixed by maarten coene (IVY-59) +- FIX: trying to resolve latest with no revision in pattern caused a StackOverflowError (IVY-56) +- FIX: now handle transitive eviction (IVY-51) +- FIX: resolve now store resolved file id in ivy variables, so that multiple resolve calls + can be followed by multiple retrieve, each retrieve will use the last resolve info (IVY-49) +- FIX: IllegalStateException on retrieve done from command line +- FIX: checks ivy files data consistency with asked info (org, module name and revision) +- FIX: use AUTH configuration for configuration file +- IMPROVE: added publish handling from command line (IVY-48) + + version 1.1 - 2005-06-13 +=============================== +- remote configuration (if available) of ivyrep and ibiblio patterns and roots +- new detailed messages when ivy fails to reach an url (thanks to Nicolas) +- new artifactproperty task, which enables to set a property for each dependency artifacts + resolved by ivy +- new defaultconf attribute in ivy file dependencies, to change the default conf to use in the file + when no conf is specified for a dependency +- add the ability to change the xsl file and report name pattern used by report task +- http listing now compatible with tomcat listing (tested with 5.0.28) +- pub revision in deliver task now defaults to timestamp if not provided by any other way +- debug messages improvements, with configuration dump among others +- new var task, enables to set ivy variables from ant +- now defaults for ivyrep and ibiblio resolver are configurable by variables +- refactoring: introduce the notion of BasicResolver, Repository, Resource, RepositoryResolver, + making much easier the task of writing basic resolvers +- added checkmodified attribute on all basic resolvers, which defaults to ${ivy.resolver.default.check.modified} + This makes ivy check last modified date of ivy files to see it its cache is up to date +- artifacts download are now first made to a temp file, which is renamed + only at the end of the download. This prevent interrupted downloads to be + considered as finished +- FIX: handle proxy configuration with http-client (thanks to Nicolas) +- FIX: remove dependency on ant outside of ant integration classes +- FIX: resolve problem when conflicts on latest revisions +- FIX: allow use of any kind of URL in IvyRepResolver (both ivyroot and artroot) and IBibiblioResolver +- FIX: chain resolver can now be used for artifacts part of dual resolver +- FIX: now detects and warn about circular dependencies +- FIX: cachepath task now takes pathid as parameter instead of id, to prevent + special handling from ant +- FIX: ivy.xsd: set artifact minOccurs to 0 in publications + +Thanks to John Shields from Robert Half International, Inc.: +- FIX: no more infinite loop when a conflict occurs between a latest subversion and a fully resolved revision +- FIX: BasicURLHandler now closes its connections +- FIX: ApacheURLLister now works with capital letter in revisions and truncated names +- now use of ivy variables is allowed in ivy files +- added a null check in pattern helper substitute + + version 1.0 - 2005-04-26 +=============================== +1.0-rc3 has been promoted to 1.0 on 2005-04-26 + +Known bugs and limitations: +- cyclic dependencies result in StackOverflowError +- infinite loop in rare cases when a conflict occur between a latest subversion and a fully resolved revision +- url connections not closed properly when not using commons-httpclient +- latest does not work with http urls in some cases, when the name of the link is truncated in the web page + + version 1.0-rc3 - 2005-04-21 +=============================== +- IMPROVE: added debug messages on variables setting +- FIX: ivyconf now able to load a properties file given as url +- FIX: deliver pub date now actually defaults to 'now' +- FIX: all tasks attributes now substitute ivy variables + + version 1.0-rc2 - 2005-04-18 +=============================== +- IMPROVE: improved messages: more debug, more verbose, and more details on failures +- FIX: bug with '\' in path patterns +- FIX: bug with relative paths patterns +- FIX: configure task tries ivy.conf.file as relative to base dir and to current dir +- FIX: file system resolver publishes ivy files with ivy pattern +- FIX: 0 content length considered as non existing (behaviour of jre 5.0 on linux) + => empty ressources are now considered as non existing + + version 1.0-rc1 - 2005-04-12 +=============================== +- add report task, which enables to generates reports of dependencies, including a graph + ready to be layed out by yEd +- add exclude feature in dependency +- include exclude feature now handles regexps +- new latest strategy: latest revision now uses a "php version_compare" like algorithm, whereas + lexicographic comparison is now available in latest lexicographic +- enhance xml resolve report details +- FIX: better separation between root configurations +- FIX: XmlModuleDescriptorUpdater now preserves xml header +- FIX: modules number in report (displayed at the end of resolve) + + version 0.9 - 2005-04-06 +=========================== +- clearly differenciate pattern tokens from variables, by using brackets as delimiter in pattern tokens + => WARNING: this introduce changes in all patterns syntax, and thus does not provide compatibility + with previous versions +- ChainResolver are now able to publish (delegating the call to the first resolver in the chain) +- DualResolver sub resolvers are now registered in Ivy +- more precise message on eviction +- add validate attribute on most resolvers +- ivy files validation handling review +- use ivy variables in ant tasks to get default values for attributes +- documentation update for configuring ivy +- FIX: dependencies order not taken into account during resolve +- FIX: evicting modules also evict confs +- FIX: NPE during resolve when a dependency ivy file has no publication date +- FIX: check nullity of artifact download reports + + version 0.8 - 2005-03-30 +=========================== +- added validate attribute on resolve, retrieve and publish, which allows to disable ivy file validation + against ivy.xsd (useful to parse future compatible ivy files) +- ant properties are now available in ivyconf file +- unified default properties in ivyconf, with better independance from url or file +- added ext on artifacts: this enable to distinguish artifact extension from artifact + type, util in cases where it differs (example: 'src' type with 'zip' extension, 'ivy' type with 'xml' extension, ...) +- added publish artifacts feature, which enable to publish declared artifacts of a module to a repository + described by a dependency resolver. It currently works only with filesystem resolver. +- url resolver now handles latest with file urls and http ones (tested only with apache server) +- added latest strategy concept: the way to determine which artifact is the latest + is now configurable on resolvers handling latest. +- added parameter on chain resolver to say if it should return first found or + try to find the latest among all if asked +- a module can now publish no artifact, useful for virtual modules consisting only + of integration of other modules +- added conflict management at resolve time: during resolve, modules in conflict can be evicted + and thus not downloaded +- added ivyrep resolver, using ivyrep to find ivy files, and ibiblio for artifacts +- use ivyrep instead of ibiblio as default resolver +- added more info in ivy files (description, homepage, ivy authors, license, public repository, ...) +- now cache layout is configurable, using cacheIvyPattern and cacheArtifactPattern + attributes on conf element in ivyconf.xml +- changed default cache layout: artifacts are separated by type +- added cachepath task, which enables to build an ant path of artifacts in cache required for a conf + + version 0.7 - 2005-03-11 +=========================== +- added latest sub revision feature: you can now select the latest sub revision of a module + using a +. For instance, "1.0+" selects the latest revision starting with 1.0. (thanks to jonas for the idea) +- haltonfailure now defaults to true (as suggested by Jeroen) +- shorter info lines to better view important info (as suggested by Jeroen) +- retrieve now checks if files are up to date before copying them from cache. This feature + can be disabled using the checkUpToDate attribute in ivy configuration file. +- do not download dependencies when not necessary during publication (as suggested by Daniele) +- bug fix: better handling of publish without recursive delivery + + version 0.6.1 - 2005-02-11 +============================= +- bug fix: conf extends problem with publications +- bug fix: typedef badly handled in ivyconf.xml +- bug fix: default properties loading in ivy configure loaded using task classloader + + version 0.6 - 2005-02-03 +=========================== ++ functional +- added haltonfailure attribute on resolve and retrieve task, so that build can be halt when + resolve or retrieve fails +- added dependency artifacts filtering feature, enabling to work better with ibiblio +- ibiblio resolver can now be configured to use any maven like repository, with root and pattern attributes +- added download progression info on resolve +- default cache is now in user home (.ivy-cache in user home), so that cache is shared + by default for all projects of the same user +- added public access to method getDependencies(...) in Ivy, which resolve dependencies without + downloading artifacts +- added DualResolver, which allows to have ivy files in one place and artifacts in another one + ++ non functional +- added some unit tests +- deep review of ivy file reference documentation + ++ bugs and refactoring +- bug fix: SimpleURLResolver not handling the case when there is no ivy file +- refactoring: URLResolver renamed to AbstractURLResolver +- refactoring: SimpleURLResolver renamed to URLResolver + + version 0.5.1 - 2005-01-16 +============================= +- Bug Fix: NPE in publish task when no delivery.list.file is provided +- documentation update + + version 0.5 - 2005-01-12 +=========================== +initial public version diff --git a/DISCLAIMER b/DISCLAIMER index 144a16c0..046ea41e 100644 --- a/DISCLAIMER +++ b/DISCLAIMER @@ -1,7 +1,7 @@ -Apache Ivy is an effort undergoing incubation at The Apache Software -Foundation (ASF). Incubation is required of all newly accepted projects -until a further review indicates that the infrastructure, communications, -and decision making process have stabilized in a manner consistent with -other successful ASF projects. While incubation status is not necessarily -a reflection of the completeness or stability of the code, it does +Apache Ivy is an effort undergoing incubation at The Apache Software +Foundation (ASF). Incubation is required of all newly accepted projects +until a further review indicates that the infrastructure, communications, +and decision making process have stabilized in a manner consistent with +other successful ASF projects. While incubation status is not necessarily +a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 7db2fa3c..1572beba 100644 --- a/LICENSE +++ b/LICENSE @@ -1,203 +1,203 @@ -/* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/ - * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - * - * 1. Definitions. - * - * "License" shall mean the terms and conditions for use, reproduction, - * and distribution as defined by Sections 1 through 9 of this document. - * - * "Licensor" shall mean the copyright owner or entity authorized by - * the copyright owner that is granting the License. - * - * "Legal Entity" shall mean the union of the acting entity and all - * other entities that control, are controlled by, or are under common - * control with that entity. For the purposes of this definition, - * "control" means (i) the power, direct or indirect, to cause the - * direction or management of such entity, whether by contract or - * otherwise, or (ii) ownership of fifty percent (50%) or more of the - * outstanding shares, or (iii) beneficial ownership of such entity. - * - * "You" (or "Your") shall mean an individual or Legal Entity - * exercising permissions granted by this License. - * - * "Source" form shall mean the preferred form for making modifications, - * including but not limited to software source code, documentation - * source, and configuration files. - * - * "Object" form shall mean any form resulting from mechanical - * transformation or translation of a Source form, including but - * not limited to compiled object code, generated documentation, - * and conversions to other media types. - * - * "Work" shall mean the work of authorship, whether in Source or - * Object form, made available under the License, as indicated by a - * copyright notice that is included in or attached to the work - * (an example is provided in the Appendix below). - * - * "Derivative Works" shall mean any work, whether in Source or Object - * form, that is based on (or derived from) the Work and for which the - * editorial revisions, annotations, elaborations, or other modifications - * represent, as a whole, an original work of authorship. For the purposes - * of this License, Derivative Works shall not include works that remain - * separable from, or merely link (or bind by name) to the interfaces of, - * the Work and Derivative Works thereof. - * - * "Contribution" shall mean any work of authorship, including - * the original version of the Work and any modifications or additions - * to that Work or Derivative Works thereof, that is intentionally - * submitted to Licensor for inclusion in the Work by the copyright owner - * or by an individual or Legal Entity authorized to submit on behalf of - * the copyright owner. For the purposes of this definition, "submitted" - * means any form of electronic, verbal, or written communication sent - * to the Licensor or its representatives, including but not limited to - * communication on electronic mailing lists, source code control systems, - * and issue tracking systems that are managed by, or on behalf of, the - * Licensor for the purpose of discussing and improving the Work, but - * excluding communication that is conspicuously marked or otherwise - * designated in writing by the copyright owner as "Not a Contribution." - * - * "Contributor" shall mean Licensor and any individual or Legal Entity - * on behalf of whom a Contribution has been received by Licensor and - * subsequently incorporated within the Work. - * - * 2. Grant of Copyright License. Subject to the terms and conditions of - * this License, each Contributor hereby grants to You a perpetual, - * worldwide, non-exclusive, no-charge, royalty-free, irrevocable - * copyright license to reproduce, prepare Derivative Works of, - * publicly display, publicly perform, sublicense, and distribute the - * Work and such Derivative Works in Source or Object form. - * - * 3. Grant of Patent License. Subject to the terms and conditions of - * this License, each Contributor hereby grants to You a perpetual, - * worldwide, non-exclusive, no-charge, royalty-free, irrevocable - * (except as stated in this section) patent license to make, have made, - * use, offer to sell, sell, import, and otherwise transfer the Work, - * where such license applies only to those patent claims licensable - * by such Contributor that are necessarily infringed by their - * Contribution(s) alone or by combination of their Contribution(s) - * with the Work to which such Contribution(s) was submitted. If You - * institute patent litigation against any entity (including a - * cross-claim or counterclaim in a lawsuit) alleging that the Work - * or a Contribution incorporated within the Work constitutes direct - * or contributory patent infringement, then any patent licenses - * granted to You under this License for that Work shall terminate - * as of the date such litigation is filed. - * - * 4. Redistribution. You may reproduce and distribute copies of the - * Work or Derivative Works thereof in any medium, with or without - * modifications, and in Source or Object form, provided that You - * meet the following conditions: - * - * (a) You must give any other recipients of the Work or - * Derivative Works a copy of this License; and - * - * (b) You must cause any modified files to carry prominent notices - * stating that You changed the files; and - * - * (c) You must retain, in the Source form of any Derivative Works - * that You distribute, all copyright, patent, trademark, and - * attribution notices from the Source form of the Work, - * excluding those notices that do not pertain to any part of - * the Derivative Works; and - * - * (d) If the Work includes a "NOTICE" text file as part of its - * distribution, then any Derivative Works that You distribute must - * include a readable copy of the attribution notices contained - * within such NOTICE file, excluding those notices that do not - * pertain to any part of the Derivative Works, in at least one - * of the following places: within a NOTICE text file distributed - * as part of the Derivative Works; within the Source form or - * documentation, if provided along with the Derivative Works; or, - * within a display generated by the Derivative Works, if and - * wherever such third-party notices normally appear. The contents - * of the NOTICE file are for informational purposes only and - * do not modify the License. You may add Your own attribution - * notices within Derivative Works that You distribute, alongside - * or as an addendum to the NOTICE text from the Work, provided - * that such additional attribution notices cannot be construed - * as modifying the License. - * - * You may add Your own copyright statement to Your modifications and - * may provide additional or different license terms and conditions - * for use, reproduction, or distribution of Your modifications, or - * for any such Derivative Works as a whole, provided Your use, - * reproduction, and distribution of the Work otherwise complies with - * the conditions stated in this License. - * - * 5. Submission of Contributions. Unless You explicitly state otherwise, - * any Contribution intentionally submitted for inclusion in the Work - * by You to the Licensor shall be under the terms and conditions of - * this License, without any additional terms or conditions. - * Notwithstanding the above, nothing herein shall supersede or modify - * the terms of any separate license agreement you may have executed - * with Licensor regarding such Contributions. - * - * 6. Trademarks. This License does not grant permission to use the trade - * names, trademarks, service marks, or product names of the Licensor, - * except as required for reasonable and customary use in describing the - * origin of the Work and reproducing the content of the NOTICE file. - * - * 7. Disclaimer of Warranty. Unless required by applicable law or - * agreed to in writing, Licensor provides the Work (and each - * Contributor provides its Contributions) on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied, including, without limitation, any warranties or conditions - * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - * PARTICULAR PURPOSE. You are solely responsible for determining the - * appropriateness of using or redistributing the Work and assume any - * risks associated with Your exercise of permissions under this License. - * - * 8. Limitation of Liability. In no event and under no legal theory, - * whether in tort (including negligence), contract, or otherwise, - * unless required by applicable law (such as deliberate and grossly - * negligent acts) or agreed to in writing, shall any Contributor be - * liable to You for damages, including any direct, indirect, special, - * incidental, or consequential damages of any character arising as a - * result of this License or out of the use or inability to use the - * Work (including but not limited to damages for loss of goodwill, - * work stoppage, computer failure or malfunction, or any and all - * other commercial damages or losses), even if such Contributor - * has been advised of the possibility of such damages. - * - * 9. Accepting Warranty or Additional Liability. While redistributing - * the Work or Derivative Works thereof, You may choose to offer, - * and charge a fee for, acceptance of support, warranty, indemnity, - * or other liability obligations and/or rights consistent with this - * License. However, in accepting such obligations, You may act only - * on Your own behalf and on Your sole responsibility, not on behalf - * of any other Contributor, and only if You agree to indemnify, - * defend, and hold each Contributor harmless for any liability - * incurred by, or claims asserted against, such Contributor by reason - * of your accepting any such warranty or additional liability. - * - * END OF TERMS AND CONDITIONS - * - * APPENDIX: How to apply the Apache License to your work. - * - * To apply the Apache License to your work, attach the following - * boilerplate notice, with the fields enclosed by brackets "[]" - * replaced with your own identifying information. (Don't include - * the brackets!) The text should be enclosed in the appropriate - * comment syntax for the file format. We also recommend that a - * file or class name and description of purpose be included on the - * same "printed page" as the copyright notice for easier - * identification within third-party archives. - * - * Copyright [yyyy] [name of copyright owner] - * - * Licensed 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. +/* + * Apache License + * Version 2.0, January 2004 + * http://www.apache.org/licenses/ + * + * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * + * 1. Definitions. + * + * "License" shall mean the terms and conditions for use, reproduction, + * and distribution as defined by Sections 1 through 9 of this document. + * + * "Licensor" shall mean the copyright owner or entity authorized by + * the copyright owner that is granting the License. + * + * "Legal Entity" shall mean the union of the acting entity and all + * other entities that control, are controlled by, or are under common + * control with that entity. For the purposes of this definition, + * "control" means (i) the power, direct or indirect, to cause the + * direction or management of such entity, whether by contract or + * otherwise, or (ii) ownership of fifty percent (50%) or more of the + * outstanding shares, or (iii) beneficial ownership of such entity. + * + * "You" (or "Your") shall mean an individual or Legal Entity + * exercising permissions granted by this License. + * + * "Source" form shall mean the preferred form for making modifications, + * including but not limited to software source code, documentation + * source, and configuration files. + * + * "Object" form shall mean any form resulting from mechanical + * transformation or translation of a Source form, including but + * not limited to compiled object code, generated documentation, + * and conversions to other media types. + * + * "Work" shall mean the work of authorship, whether in Source or + * Object form, made available under the License, as indicated by a + * copyright notice that is included in or attached to the work + * (an example is provided in the Appendix below). + * + * "Derivative Works" shall mean any work, whether in Source or Object + * form, that is based on (or derived from) the Work and for which the + * editorial revisions, annotations, elaborations, or other modifications + * represent, as a whole, an original work of authorship. For the purposes + * of this License, Derivative Works shall not include works that remain + * separable from, or merely link (or bind by name) to the interfaces of, + * the Work and Derivative Works thereof. + * + * "Contribution" shall mean any work of authorship, including + * the original version of the Work and any modifications or additions + * to that Work or Derivative Works thereof, that is intentionally + * submitted to Licensor for inclusion in the Work by the copyright owner + * or by an individual or Legal Entity authorized to submit on behalf of + * the copyright owner. For the purposes of this definition, "submitted" + * means any form of electronic, verbal, or written communication sent + * to the Licensor or its representatives, including but not limited to + * communication on electronic mailing lists, source code control systems, + * and issue tracking systems that are managed by, or on behalf of, the + * Licensor for the purpose of discussing and improving the Work, but + * excluding communication that is conspicuously marked or otherwise + * designated in writing by the copyright owner as "Not a Contribution." + * + * "Contributor" shall mean Licensor and any individual or Legal Entity + * on behalf of whom a Contribution has been received by Licensor and + * subsequently incorporated within the Work. + * + * 2. Grant of Copyright License. Subject to the terms and conditions of + * this License, each Contributor hereby grants to You a perpetual, + * worldwide, non-exclusive, no-charge, royalty-free, irrevocable + * copyright license to reproduce, prepare Derivative Works of, + * publicly display, publicly perform, sublicense, and distribute the + * Work and such Derivative Works in Source or Object form. + * + * 3. Grant of Patent License. Subject to the terms and conditions of + * this License, each Contributor hereby grants to You a perpetual, + * worldwide, non-exclusive, no-charge, royalty-free, irrevocable + * (except as stated in this section) patent license to make, have made, + * use, offer to sell, sell, import, and otherwise transfer the Work, + * where such license applies only to those patent claims licensable + * by such Contributor that are necessarily infringed by their + * Contribution(s) alone or by combination of their Contribution(s) + * with the Work to which such Contribution(s) was submitted. If You + * institute patent litigation against any entity (including a + * cross-claim or counterclaim in a lawsuit) alleging that the Work + * or a Contribution incorporated within the Work constitutes direct + * or contributory patent infringement, then any patent licenses + * granted to You under this License for that Work shall terminate + * as of the date such litigation is filed. + * + * 4. Redistribution. You may reproduce and distribute copies of the + * Work or Derivative Works thereof in any medium, with or without + * modifications, and in Source or Object form, provided that You + * meet the following conditions: + * + * (a) You must give any other recipients of the Work or + * Derivative Works a copy of this License; and + * + * (b) You must cause any modified files to carry prominent notices + * stating that You changed the files; and + * + * (c) You must retain, in the Source form of any Derivative Works + * that You distribute, all copyright, patent, trademark, and + * attribution notices from the Source form of the Work, + * excluding those notices that do not pertain to any part of + * the Derivative Works; and + * + * (d) If the Work includes a "NOTICE" text file as part of its + * distribution, then any Derivative Works that You distribute must + * include a readable copy of the attribution notices contained + * within such NOTICE file, excluding those notices that do not + * pertain to any part of the Derivative Works, in at least one + * of the following places: within a NOTICE text file distributed + * as part of the Derivative Works; within the Source form or + * documentation, if provided along with the Derivative Works; or, + * within a display generated by the Derivative Works, if and + * wherever such third-party notices normally appear. The contents + * of the NOTICE file are for informational purposes only and + * do not modify the License. You may add Your own attribution + * notices within Derivative Works that You distribute, alongside + * or as an addendum to the NOTICE text from the Work, provided + * that such additional attribution notices cannot be construed + * as modifying the License. + * + * You may add Your own copyright statement to Your modifications and + * may provide additional or different license terms and conditions + * for use, reproduction, or distribution of Your modifications, or + * for any such Derivative Works as a whole, provided Your use, + * reproduction, and distribution of the Work otherwise complies with + * the conditions stated in this License. + * + * 5. Submission of Contributions. Unless You explicitly state otherwise, + * any Contribution intentionally submitted for inclusion in the Work + * by You to the Licensor shall be under the terms and conditions of + * this License, without any additional terms or conditions. + * Notwithstanding the above, nothing herein shall supersede or modify + * the terms of any separate license agreement you may have executed + * with Licensor regarding such Contributions. + * + * 6. Trademarks. This License does not grant permission to use the trade + * names, trademarks, service marks, or product names of the Licensor, + * except as required for reasonable and customary use in describing the + * origin of the Work and reproducing the content of the NOTICE file. + * + * 7. Disclaimer of Warranty. Unless required by applicable law or + * agreed to in writing, Licensor provides the Work (and each + * Contributor provides its Contributions) on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied, including, without limitation, any warranties or conditions + * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + * PARTICULAR PURPOSE. You are solely responsible for determining the + * appropriateness of using or redistributing the Work and assume any + * risks associated with Your exercise of permissions under this License. + * + * 8. Limitation of Liability. In no event and under no legal theory, + * whether in tort (including negligence), contract, or otherwise, + * unless required by applicable law (such as deliberate and grossly + * negligent acts) or agreed to in writing, shall any Contributor be + * liable to You for damages, including any direct, indirect, special, + * incidental, or consequential damages of any character arising as a + * result of this License or out of the use or inability to use the + * Work (including but not limited to damages for loss of goodwill, + * work stoppage, computer failure or malfunction, or any and all + * other commercial damages or losses), even if such Contributor + * has been advised of the possibility of such damages. + * + * 9. Accepting Warranty or Additional Liability. While redistributing + * the Work or Derivative Works thereof, You may choose to offer, + * and charge a fee for, acceptance of support, warranty, indemnity, + * or other liability obligations and/or rights consistent with this + * License. However, in accepting such obligations, You may act only + * on Your own behalf and on Your sole responsibility, not on behalf + * of any other Contributor, and only if You agree to indemnify, + * defend, and hold each Contributor harmless for any liability + * incurred by, or claims asserted against, such Contributor by reason + * of your accepting any such warranty or additional liability. + * + * END OF TERMS AND CONDITIONS + * + * APPENDIX: How to apply the Apache License to your work. + * + * To apply the Apache License to your work, attach the following + * boilerplate notice, with the fields enclosed by brackets "[]" + * replaced with your own identifying information. (Don't include + * the brackets!) The text should be enclosed in the appropriate + * comment syntax for the file format. We also recommend that a + * file or class name and description of purpose be included on the + * same "printed page" as the copyright notice for easier + * identification within third-party archives. + * + * Copyright [yyyy] [name of copyright owner] + * + * Licensed 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. */ \ No newline at end of file diff --git a/MANIFEST.MF b/MANIFEST.MF index 739e7c84..95013f77 100644 --- a/MANIFEST.MF +++ b/MANIFEST.MF @@ -1,80 +1,80 @@ -Manifest-Version: 1.0 -Bundle-Name: Ivy -Bundle-ManifestVersion: 2 -Bundle-SymbolicName: org.apache.ivy -Bundle-Vendor: Apache Software Foundation -Bundle-DocURL: http://incubator.apache.org/ivy -Import-Package: javax.xml.parsers, - javax.xml.transform, - javax.xml.transform.sax, - javax.xml.transform.stream, - org.xml.sax, - org.xml.sax.ext, - org.xml.sax.helpers, - com.jcraft.jsch;resolution:=optional, - javax.swing;resolution:=optional, - javax.swing.event;resolution:=optional, - org.apache.commons.cli;resolution:=optional, - org.apache.commons.httpclient;resolution:=optional, - org.apache.commons.httpclient.methods;resolution:=optional, - org.apache.commons.httpclient.params;resolution:=optional, - org.apache.commons.httpclient.protocol;resolution:=optional, - org.apache.commons.vfs;resolution:=optional, - org.apache.commons.vfs.impl;resolution:=optional, - org.apache.commons.vfs.provider;resolution:=optional, - org.apache.commons.vfs.provider.webdav;resolution:=optional, - org.apache.oro.text;resolution:=optional, - org.apache.oro.text.regex;resolution:=optional, - org.apache.webdav;resolution:=optional, - org.apache.tools.ant;resolution:=optional, - org.apache.tools.ant.filters;resolution:=optional, - org.apache.tools.ant.taskdefs;resolution:=optional, - org.apache.tools.ant.types;resolution:=optional, - org.apache.tools.ant.util;resolution:=optional -Export-Package: org.apache.ivy;version="2.0.0", - org.apache.ivy.ant;version="2.0.0", - org.apache.ivy.core;version="2.0.0", - org.apache.ivy.core.cache;version="2.0.0", - org.apache.ivy.core.check;version="2.0.0", - org.apache.ivy.core.deliver;version="2.0.0", - org.apache.ivy.core.event;version="2.0.0", - org.apache.ivy.core.event.download;version="2.0.0", - org.apache.ivy.core.event.resolve;version="2.0.0", - org.apache.ivy.core.install;version="2.0.0", - org.apache.ivy.core.module.descriptor;version="2.0.0", - org.apache.ivy.core.module.id;version="2.0.0", - org.apache.ivy.core.module.status;version="2.0.0", - org.apache.ivy.core.publish;version="2.0.0", - org.apache.ivy.core.report;version="2.0.0", - org.apache.ivy.core.resolve;version="2.0.0", - org.apache.ivy.core.retrieve;version="2.0.0", - org.apache.ivy.core.search;version="2.0.0", - org.apache.ivy.core.settings;version="2.0.0", - org.apache.ivy.core.sort;version="2.0.0", - org.apache.ivy.plugins;version="2.0.0", - org.apache.ivy.plugins.circular;version="2.0.0", - org.apache.ivy.plugins.conflict;version="2.0.0", - org.apache.ivy.plugins.latest;version="2.0.0", - org.apache.ivy.plugins.matcher;version="2.0.0", - org.apache.ivy.plugins.namespace;version="2.0.0", - org.apache.ivy.plugins.parser;version="2.0.0", - org.apache.ivy.plugins.parser.m2;version="2.0.0", - org.apache.ivy.plugins.parser.xml;version="2.0.0", - org.apache.ivy.plugins.report;version="2.0.0", - org.apache.ivy.plugins.repository;version="2.0.0", - org.apache.ivy.plugins.repository.file;version="2.0.0", - org.apache.ivy.plugins.repository.sftp;version="2.0.0", - org.apache.ivy.plugins.repository.ssh;version="2.0.0", - org.apache.ivy.plugins.repository.url;version="2.0.0", - org.apache.ivy.plugins.repository.vfs;version="2.0.0", - org.apache.ivy.plugins.repository.vsftp;version="2.0.0", - org.apache.ivy.plugins.resolver;version="2.0.0", - org.apache.ivy.plugins.resolver.util;version="2.0.0", - org.apache.ivy.plugins.util;version="2.0.0", - org.apache.ivy.plugins.trigger;version="2.0.0", - org.apache.ivy.plugins.version;version="2.0.0", - org.apache.ivy.tools.analyser;version="2.0.0", - org.apache.ivy.util;version="2.0.0", - org.apache.ivy.util.extendable;version="2.0.0", - org.apache.ivy.util.filter;version="2.0.0", - org.apache.ivy.util.url;version="2.0.0" +Manifest-Version: 1.0 +Bundle-Name: Ivy +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.apache.ivy +Bundle-Vendor: Apache Software Foundation +Bundle-DocURL: http://incubator.apache.org/ivy +Import-Package: javax.xml.parsers, + javax.xml.transform, + javax.xml.transform.sax, + javax.xml.transform.stream, + org.xml.sax, + org.xml.sax.ext, + org.xml.sax.helpers, + com.jcraft.jsch;resolution:=optional, + javax.swing;resolution:=optional, + javax.swing.event;resolution:=optional, + org.apache.commons.cli;resolution:=optional, + org.apache.commons.httpclient;resolution:=optional, + org.apache.commons.httpclient.methods;resolution:=optional, + org.apache.commons.httpclient.params;resolution:=optional, + org.apache.commons.httpclient.protocol;resolution:=optional, + org.apache.commons.vfs;resolution:=optional, + org.apache.commons.vfs.impl;resolution:=optional, + org.apache.commons.vfs.provider;resolution:=optional, + org.apache.commons.vfs.provider.webdav;resolution:=optional, + org.apache.oro.text;resolution:=optional, + org.apache.oro.text.regex;resolution:=optional, + org.apache.webdav;resolution:=optional, + org.apache.tools.ant;resolution:=optional, + org.apache.tools.ant.filters;resolution:=optional, + org.apache.tools.ant.taskdefs;resolution:=optional, + org.apache.tools.ant.types;resolution:=optional, + org.apache.tools.ant.util;resolution:=optional +Export-Package: org.apache.ivy;version="2.0.0", + org.apache.ivy.ant;version="2.0.0", + org.apache.ivy.core;version="2.0.0", + org.apache.ivy.core.cache;version="2.0.0", + org.apache.ivy.core.check;version="2.0.0", + org.apache.ivy.core.deliver;version="2.0.0", + org.apache.ivy.core.event;version="2.0.0", + org.apache.ivy.core.event.download;version="2.0.0", + org.apache.ivy.core.event.resolve;version="2.0.0", + org.apache.ivy.core.install;version="2.0.0", + org.apache.ivy.core.module.descriptor;version="2.0.0", + org.apache.ivy.core.module.id;version="2.0.0", + org.apache.ivy.core.module.status;version="2.0.0", + org.apache.ivy.core.publish;version="2.0.0", + org.apache.ivy.core.report;version="2.0.0", + org.apache.ivy.core.resolve;version="2.0.0", + org.apache.ivy.core.retrieve;version="2.0.0", + org.apache.ivy.core.search;version="2.0.0", + org.apache.ivy.core.settings;version="2.0.0", + org.apache.ivy.core.sort;version="2.0.0", + org.apache.ivy.plugins;version="2.0.0", + org.apache.ivy.plugins.circular;version="2.0.0", + org.apache.ivy.plugins.conflict;version="2.0.0", + org.apache.ivy.plugins.latest;version="2.0.0", + org.apache.ivy.plugins.matcher;version="2.0.0", + org.apache.ivy.plugins.namespace;version="2.0.0", + org.apache.ivy.plugins.parser;version="2.0.0", + org.apache.ivy.plugins.parser.m2;version="2.0.0", + org.apache.ivy.plugins.parser.xml;version="2.0.0", + org.apache.ivy.plugins.report;version="2.0.0", + org.apache.ivy.plugins.repository;version="2.0.0", + org.apache.ivy.plugins.repository.file;version="2.0.0", + org.apache.ivy.plugins.repository.sftp;version="2.0.0", + org.apache.ivy.plugins.repository.ssh;version="2.0.0", + org.apache.ivy.plugins.repository.url;version="2.0.0", + org.apache.ivy.plugins.repository.vfs;version="2.0.0", + org.apache.ivy.plugins.repository.vsftp;version="2.0.0", + org.apache.ivy.plugins.resolver;version="2.0.0", + org.apache.ivy.plugins.resolver.util;version="2.0.0", + org.apache.ivy.plugins.util;version="2.0.0", + org.apache.ivy.plugins.trigger;version="2.0.0", + org.apache.ivy.plugins.version;version="2.0.0", + org.apache.ivy.tools.analyser;version="2.0.0", + org.apache.ivy.util;version="2.0.0", + org.apache.ivy.util.extendable;version="2.0.0", + org.apache.ivy.util.filter;version="2.0.0", + org.apache.ivy.util.url;version="2.0.0" diff --git a/NOTICE b/NOTICE index 243dcd8f..ad9f700d 100644 --- a/NOTICE +++ b/NOTICE @@ -1,14 +1,14 @@ - ========================================================================= - == NOTICE file corresponding to the section 4 d of == - == the Apache License, Version 2.0, == - == in this case for the Apache Ivy distribution. == - ========================================================================= - - This product includes software developed by - The Apache Software Foundation (http://www.apache.org/). - - Portions of Ivy were originally developed by - Jayasoft SARL and are - licensed to the Apache Software Foundation under the - "Software Grant License Agreement" - + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Ivy distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Portions of Ivy were originally developed by + Jayasoft SARL and are + licensed to the Apache Software Foundation under the + "Software Grant License Agreement" + diff --git a/README b/README index 37f3e68b..22de1a1a 100644 --- a/README +++ b/README @@ -1,34 +1,34 @@ - Apache Ivy v2.0.0-alpha1-incubating - ------------------------------------ - -Supported Platforms --------------------- - -Apache Ivy requires Java level 1.4; it has been tested with Sun Java SDK v1.4.2 - -Even if not mandatory, Apache Ivy is most of the times used with Apache Ant, for which version 1.6.0 or greater is required. - -Installation ----------------------- - -Please read doc/doc/install.html for installation instructions. - - -Getting Started ----------------- - -For an introduction to Apache Ivy and how to use it, please read the documentation -located in the doc subdirectory. A good place to start is the index.html - - -Disclaimer ------------ - -Apache Ivy is an effort undergoing incubation at The Apache Software -Foundation (ASF). Incubation is required of all newly accepted projects -until a further review indicates that the infrastructure, communications, -and decision making process have stabilized in a manner consistent with -other successful ASF projects. While incubation status is not necessarily -a reflection of the completeness or stability of the code, it does -indicate that the project has yet to be fully endorsed by the ASF. - + Apache Ivy v2.0.0-alpha1-incubating + ------------------------------------ + +Supported Platforms +-------------------- + +Apache Ivy requires Java level 1.4; it has been tested with Sun Java SDK v1.4.2 + +Even if not mandatory, Apache Ivy is most of the times used with Apache Ant, for which version 1.6.0 or greater is required. + +Installation +---------------------- + +Please read doc/doc/install.html for installation instructions. + + +Getting Started +---------------- + +For an introduction to Apache Ivy and how to use it, please read the documentation +located in the doc subdirectory. A good place to start is the index.html + + +Disclaimer +----------- + +Apache Ivy is an effort undergoing incubation at The Apache Software +Foundation (ASF). Incubation is required of all newly accepted projects +until a further review indicates that the infrastructure, communications, +and decision making process have stabilized in a manner consistent with +other successful ASF projects. While incubation status is not necessarily +a reflection of the completeness or stability of the code, it does +indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 193da9ba..97e52a9d 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,191 +1,191 @@ - Apache Ivy v2.0.0-alpha1-incubating - Release Notes - ----------------------------------------------------------------------- - -CONTENTS -1. What is Apache Ivy? -2. Status of this release -3. Major Changes in this Release -4. Migrating from Jayasoft Ivy to Apache Ivy -5. How to Get Involved -6. How to Report Issues -7. Committers and Contributors for this release -8. List of Changes in this Release - - -1. What is Apache Ivy? - -Apache Ivy is a tool for managing (recording, tracking, resolving and reporting) -project dependencies. -It is characterized by the following: - - 1. flexibility and configurability - Apache Ivy is essentially process agnostic and is not tied to any - methodology or structure. - Instead it provides the necessary flexibility and configurability - to be adapted to a broad range of dependency management and build - processes. - 2. tight integration with Apache Ant - while available as a standalone tool, Apache Ivy works particularly well - with Apache Ant providing a number of powerful Ant tasks ranging - from dependency resolution to dependency reporting and publication. - -2. Status of this release - -This release of Apache Ivy is the first release within the Apache Incubator, -and is labelled and should be considered as an alpha version. - -This means that we do not guarantee any stability, that API and features are still -likely to change until final 2.0.0 version, and thus we do not encourage the use -of this version, except for very early testing. - -The current production quality version is still 1.4.1, which has not been produced -within the Apache Software Foundation. - -3. Major Changes in this Release - -This section describes what has changed between version 1.4.1 and this version of -Apache Ivy. - -This new version of Apache Ivy is fully compatible with previous versions as long as you do -not use custom plugins: Ivy API has changed, but not its behavior: - -Some tasks and configuration elements have been renamed, but the old versions -are still available, they are only deprecated (you will see deprecated warnings). - -3.1. Java Package Name Changes - -All of the Ivy Java package names have changed in Apache Ivy. They now start -with org.apache rather than fr.jayasoft. There have been other changes as well. -Important refactorings have done on the source code to ease the understanding -of Ivy internal architecture by new developers. - -A class named org.apache.ivy.Ivy14 is provided with an API compatible with the -fr.jayasoft.Ivy class of Ivy 1.4.1, to ease migration to this new version. - -3.2. Configuration replaced by Settings - -Configuration used to have two meanings in prior Ivy versions, causing some confusion -with new users. -To avoid this confusion, Apache Ivy calls settings instead of configuration the files -used to customize Ivy. Configuration is still used for module configurations. - -Besides the changes in the documentation, this renaming also imply a modification -in settings files, which now use ivysettings as root element instead of ivyconf, -and settings instead of conf element to define top level defaults (such as -defaultCache, ...). -Previous names have been deprecated, so previous settings files can still be used, but -you will see a deprecation warning. - -3.3. public resolver in default settings is now ibiblio in m2 compatible mode - -In previous versions Ivy used to use the ivyrep resolver as default public resolver, -but ivyrep is no longer maintained, while maven 2 repository on ibiblio is growing rapidly. - -Since Ivy is compatible with maven 2 repository, defaulting to the ibiblio maven 2 -repository makes more sense. - -If you have any issue of backward compatibility with these new settings, you can simply -set the following ant property before calling configure (implicitly or explicitly): -ivy.14.compatible=true - -4. Migrating from Jayasoft Ivy to Apache Ivy - -Apache Ivy is fully compatible with Jayasoft Ivy as long as you do not use -custom plugins. -This means that you can use Apache Ivy as a drop in replacement of Jayasoft Ivy. - -However due to the the renaming of configuration files to settings files, we -strongly suggest to update your configuration files: -- rename the files called ivyconf*.xml in ivysettings*.xml -- rename 'ivyconf' element in 'ivysettings' -- rename 'conf' element of those settings file in 'settings' - -Migrating custom plugins can be done by using the org.apache.ivy.Ivy14 class -instead of fr.jayasoft.ivy.Ivy, and reorganizing your imports to reflect the -changes in the package names. - -5. How to Get Involved - -The Apache Ivy project really needs and appreciates any contributions, -including documentation help, source code and feedback. If you are interested -in contributing, please visit http://incubator.apache.org/ivy/get-involved.html. - -6. How to Report Issues - -The Apache Ivy project uses JIRA for issue tracking. Please report any -issues you find at http://issues.apache.org/jira/browse/IVY - -7. Committers and Contributors for this Release - -Here is the list of people who have contributed source code and documentation -to this release. Many thanks to all of them, and also to the whole Ivy community -contributing ideas and feedback, and promoting the use of Ivy. The list would be too -long, but Ivy couldn't be what it is without you! - - Committers - Maarten Coene - Xavier Hanin - - Contributors - Stephane Baillez - Pierre Hägnestrand - Matt Inger - Costin Leau - William Lyvers - Gilles Scokart - John Williams - -8. List of Changes in this Release - -For a full release history of Ivy see the file CHANGES.txt - -For details about the following changes, check our JIRA install at -http://issues.apache.org/jira/browse/ivy - -- TASK: refactor Ivy source code to improve readibility (IVY-434) - -- NEW: define artifacts not declared by the dependency module descriptor (IVY-419) -- NEW: Module wide exclude (IVY-431) -- NEW: The default public resolver used is now ibiblio with m2 compatible mode (IVY-463) - -- IMPROVE: OSGIfy ivy artifacts (IVY-464) (thanks to Costin Leau) -- IMPROVE: Let user specify Ivy file when using a post-resolve task (IVY-455) -- IMPROVE: IvyArtifactProperty and IvyArtifactReport tasks should be a post resolve task (IVY-452) -- IMPROVE: Rename ivy configuration in settings to remove ambiguity on configuration meaning (IVY-438) -- IMPROVE: Please typedef CacheResolver as "cache" for us (IVY-359) -- IMPROVE: ivy:retrieve should be able to create symlinks (IVY-353) (thanks to John Williams) -- IMPROVE: Ability to have multiple roots in the task (IVY-340) (thanks to Matt Inger) -- IMPROVE: Refactoring / documentation / test of matcher package (IVY-375) (thanks to Stephane Baillez) -- IMPROVE: Add a unit test to verify that latest.integration accepts released modules (IVY-394) (thanks to Gilles Scokart) -- IMPROVE: New "modules in use" section in console report at the end of resolve (IVY-373) (thanks to John Wiliams) -- IMPROVE: Generated XML reports now contains more information about the resolved module (IVY-446) - -- FIX: ivy-retrieve failure when explicit absolute 'ivy.dep.file' path specified (IVY-396) -- FIX: IvyPostResolve Task doesn't reuse Ivy file of previous resolve (IVY-458) -- FIX: Ivy standalone is passing null args to main method when invoking with no args (IVY-457) -- FIX: Invalid error report with m2compatible resolver (IVY-456) -- FIX: IvyPostResolve Task doesn't use specified cache for the resolve (IVY-453) -- FIX: XmlModuleDescriptorWriterTest not working with Java 6 (IVY-374) -- FIX: Conflict managers ignored, when assigned to modules in Ivy configuration (setting, ivyconf.xml) (IVY-448) -- FIX: Ivy should fail if ';' has been used in publications/artifact/@conf of ivy.xml (IVY-441) -- FIX: Ivy should fail where dependency uses undefined configuration (IVY-442) -- FIX: Dynamic revision not calculated properly when using multiple directories (IVY-427) -- FIX: LatestRevisionStrategy.sort() doesn't sort as specified (IVY-435) -- FIX: setting m2compatible on ibiblio resolver overwrite root and pattern settings (IVY-437) -- FIX: ivy.revision property not set correctly for second resolve (IVY-429) -- FIX: NPE when no organisation or no name is provided in module element of ivyconf (IVY-422) -- FIX: FileUtil#copy(File src, File dest, CopyProgressListener l, boolean overwrite) (IVY-420) -- FIX: Invalid pom parsing when version is only declared in parent (IVY-436) -- FIX: ${project.groupId} and ${project.version} not processed correctly in poms (IVY-425) -- FIX: Incorrect pom parsing with profile (IVY-423) -- FIX: Ivy doesn't recognize maven2 classifiers (IVY-418) -- FIX: PomModuleDescriptorParser fails with nested profile dependency (IVY-392) (thanks to William Lyvers) -- FIX: Static revision replacement is not working when delivering an artifact with a dependency having extra attributes (IVY-415) -- FIX: Static revision replacement is not working when delivering an artifact with a dependency on a branch (IVY-404) -- FIX: latest-time conflict manager not working properly (IVY-407) -- FIX: LatestRevisionStrategy do not consider all dynamic revisions properly (IVY-383) (thanks to John Williams for the unit test) -- FIX: IOException during publish causes NullPointerException (IVY-371) -- FIX: Comments in ivy.xml duplicated (IVY-336) (thanks to Gilles Scokart) -- FIX: Ivy failure when the ivy.xml file contains non US-ASCII characters (IVY-346) (thanks to Gilles Scokart) -- FIX: Urlresolver is not possible to use dynamic revisions on nonstandard repository structure (IVY-350) (thanks to Pierre Hägnestrand) + Apache Ivy v2.0.0-alpha1-incubating + Release Notes + ----------------------------------------------------------------------- + +CONTENTS +1. What is Apache Ivy? +2. Status of this release +3. Major Changes in this Release +4. Migrating from Jayasoft Ivy to Apache Ivy +5. How to Get Involved +6. How to Report Issues +7. Committers and Contributors for this release +8. List of Changes in this Release + + +1. What is Apache Ivy? + +Apache Ivy is a tool for managing (recording, tracking, resolving and reporting) +project dependencies. +It is characterized by the following: + + 1. flexibility and configurability + Apache Ivy is essentially process agnostic and is not tied to any + methodology or structure. + Instead it provides the necessary flexibility and configurability + to be adapted to a broad range of dependency management and build + processes. + 2. tight integration with Apache Ant + while available as a standalone tool, Apache Ivy works particularly well + with Apache Ant providing a number of powerful Ant tasks ranging + from dependency resolution to dependency reporting and publication. + +2. Status of this release + +This release of Apache Ivy is the first release within the Apache Incubator, +and is labelled and should be considered as an alpha version. + +This means that we do not guarantee any stability, that API and features are still +likely to change until final 2.0.0 version, and thus we do not encourage the use +of this version, except for very early testing. + +The current production quality version is still 1.4.1, which has not been produced +within the Apache Software Foundation. + +3. Major Changes in this Release + +This section describes what has changed between version 1.4.1 and this version of +Apache Ivy. + +This new version of Apache Ivy is fully compatible with previous versions as long as you do +not use custom plugins: Ivy API has changed, but not its behavior: + +Some tasks and configuration elements have been renamed, but the old versions +are still available, they are only deprecated (you will see deprecated warnings). + +3.1. Java Package Name Changes + +All of the Ivy Java package names have changed in Apache Ivy. They now start +with org.apache rather than fr.jayasoft. There have been other changes as well. +Important refactorings have done on the source code to ease the understanding +of Ivy internal architecture by new developers. + +A class named org.apache.ivy.Ivy14 is provided with an API compatible with the +fr.jayasoft.Ivy class of Ivy 1.4.1, to ease migration to this new version. + +3.2. Configuration replaced by Settings + +Configuration used to have two meanings in prior Ivy versions, causing some confusion +with new users. +To avoid this confusion, Apache Ivy calls settings instead of configuration the files +used to customize Ivy. Configuration is still used for module configurations. + +Besides the changes in the documentation, this renaming also imply a modification +in settings files, which now use ivysettings as root element instead of ivyconf, +and settings instead of conf element to define top level defaults (such as +defaultCache, ...). +Previous names have been deprecated, so previous settings files can still be used, but +you will see a deprecation warning. + +3.3. public resolver in default settings is now ibiblio in m2 compatible mode + +In previous versions Ivy used to use the ivyrep resolver as default public resolver, +but ivyrep is no longer maintained, while maven 2 repository on ibiblio is growing rapidly. + +Since Ivy is compatible with maven 2 repository, defaulting to the ibiblio maven 2 +repository makes more sense. + +If you have any issue of backward compatibility with these new settings, you can simply +set the following ant property before calling configure (implicitly or explicitly): +ivy.14.compatible=true + +4. Migrating from Jayasoft Ivy to Apache Ivy + +Apache Ivy is fully compatible with Jayasoft Ivy as long as you do not use +custom plugins. +This means that you can use Apache Ivy as a drop in replacement of Jayasoft Ivy. + +However due to the the renaming of configuration files to settings files, we +strongly suggest to update your configuration files: +- rename the files called ivyconf*.xml in ivysettings*.xml +- rename 'ivyconf' element in 'ivysettings' +- rename 'conf' element of those settings file in 'settings' + +Migrating custom plugins can be done by using the org.apache.ivy.Ivy14 class +instead of fr.jayasoft.ivy.Ivy, and reorganizing your imports to reflect the +changes in the package names. + +5. How to Get Involved + +The Apache Ivy project really needs and appreciates any contributions, +including documentation help, source code and feedback. If you are interested +in contributing, please visit http://incubator.apache.org/ivy/get-involved.html. + +6. How to Report Issues + +The Apache Ivy project uses JIRA for issue tracking. Please report any +issues you find at http://issues.apache.org/jira/browse/IVY + +7. Committers and Contributors for this Release + +Here is the list of people who have contributed source code and documentation +to this release. Many thanks to all of them, and also to the whole Ivy community +contributing ideas and feedback, and promoting the use of Ivy. The list would be too +long, but Ivy couldn't be what it is without you! + + Committers + Maarten Coene + Xavier Hanin + + Contributors + Stephane Baillez + Pierre Hägnestrand + Matt Inger + Costin Leau + William Lyvers + Gilles Scokart + John Williams + +8. List of Changes in this Release + +For a full release history of Ivy see the file CHANGES.txt + +For details about the following changes, check our JIRA install at +http://issues.apache.org/jira/browse/ivy + +- TASK: refactor Ivy source code to improve readibility (IVY-434) + +- NEW: define artifacts not declared by the dependency module descriptor (IVY-419) +- NEW: Module wide exclude (IVY-431) +- NEW: The default public resolver used is now ibiblio with m2 compatible mode (IVY-463) + +- IMPROVE: OSGIfy ivy artifacts (IVY-464) (thanks to Costin Leau) +- IMPROVE: Let user specify Ivy file when using a post-resolve task (IVY-455) +- IMPROVE: IvyArtifactProperty and IvyArtifactReport tasks should be a post resolve task (IVY-452) +- IMPROVE: Rename ivy configuration in settings to remove ambiguity on configuration meaning (IVY-438) +- IMPROVE: Please typedef CacheResolver as "cache" for us (IVY-359) +- IMPROVE: ivy:retrieve should be able to create symlinks (IVY-353) (thanks to John Williams) +- IMPROVE: Ability to have multiple roots in the task (IVY-340) (thanks to Matt Inger) +- IMPROVE: Refactoring / documentation / test of matcher package (IVY-375) (thanks to Stephane Baillez) +- IMPROVE: Add a unit test to verify that latest.integration accepts released modules (IVY-394) (thanks to Gilles Scokart) +- IMPROVE: New "modules in use" section in console report at the end of resolve (IVY-373) (thanks to John Wiliams) +- IMPROVE: Generated XML reports now contains more information about the resolved module (IVY-446) + +- FIX: ivy-retrieve failure when explicit absolute 'ivy.dep.file' path specified (IVY-396) +- FIX: IvyPostResolve Task doesn't reuse Ivy file of previous resolve (IVY-458) +- FIX: Ivy standalone is passing null args to main method when invoking with no args (IVY-457) +- FIX: Invalid error report with m2compatible resolver (IVY-456) +- FIX: IvyPostResolve Task doesn't use specified cache for the resolve (IVY-453) +- FIX: XmlModuleDescriptorWriterTest not working with Java 6 (IVY-374) +- FIX: Conflict managers ignored, when assigned to modules in Ivy configuration (setting, ivyconf.xml) (IVY-448) +- FIX: Ivy should fail if ';' has been used in publications/artifact/@conf of ivy.xml (IVY-441) +- FIX: Ivy should fail where dependency uses undefined configuration (IVY-442) +- FIX: Dynamic revision not calculated properly when using multiple directories (IVY-427) +- FIX: LatestRevisionStrategy.sort() doesn't sort as specified (IVY-435) +- FIX: setting m2compatible on ibiblio resolver overwrite root and pattern settings (IVY-437) +- FIX: ivy.revision property not set correctly for second resolve (IVY-429) +- FIX: NPE when no organisation or no name is provided in module element of ivyconf (IVY-422) +- FIX: FileUtil#copy(File src, File dest, CopyProgressListener l, boolean overwrite) (IVY-420) +- FIX: Invalid pom parsing when version is only declared in parent (IVY-436) +- FIX: ${project.groupId} and ${project.version} not processed correctly in poms (IVY-425) +- FIX: Incorrect pom parsing with profile (IVY-423) +- FIX: Ivy doesn't recognize maven2 classifiers (IVY-418) +- FIX: PomModuleDescriptorParser fails with nested profile dependency (IVY-392) (thanks to William Lyvers) +- FIX: Static revision replacement is not working when delivering an artifact with a dependency having extra attributes (IVY-415) +- FIX: Static revision replacement is not working when delivering an artifact with a dependency on a branch (IVY-404) +- FIX: latest-time conflict manager not working properly (IVY-407) +- FIX: LatestRevisionStrategy do not consider all dynamic revisions properly (IVY-383) (thanks to John Williams for the unit test) +- FIX: IOException during publish causes NullPointerException (IVY-371) +- FIX: Comments in ivy.xml duplicated (IVY-336) (thanks to Gilles Scokart) +- FIX: Ivy failure when the ivy.xml file contains non US-ASCII characters (IVY-346) (thanks to Gilles Scokart) +- FIX: Urlresolver is not possible to use dynamic revisions on nonstandard repository structure (IVY-350) (thanks to Pierre Hägnestrand) diff --git a/ant.patterns b/ant.patterns index dd6f5a7a..fe928a96 100644 --- a/ant.patterns +++ b/ant.patterns @@ -1,5 +1,5 @@ -#This section defines the sources to compile for ivy-ant.jar -org/apache/ivy/ant/*.java - -#This section defines the resources to copy for ivy-ant.jar -org/apache/ivy/ant/*.xml \ No newline at end of file +#This section defines the sources to compile for ivy-ant.jar +org/apache/ivy/ant/*.java + +#This section defines the resources to copy for ivy-ant.jar +org/apache/ivy/ant/*.xml diff --git a/build-release.xml b/build-release.xml index 1bee9acd..fc71da63 100644 --- a/build-release.xml +++ b/build-release.xml @@ -1,179 +1,179 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.properties b/build.properties index fa7e49aa..f8c54092 100644 --- a/build.properties +++ b/build.properties @@ -1,47 +1,47 @@ -# *************************************************************** -# * 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 -src.dir=${basedir}/src/java -test.dir=${basedir}/test/java -build.dir=${basedir}/build -classes.build.dir=${basedir}/build/classes -core.classes.build.dir=${classes.build.dir}/core -ant.classes.build.dir=${classes.build.dir}/ant -optional.classes.build.dir=${classes.build.dir}/optional -test.build.dir=${basedir}/build/test -artifacts.build.dir=${basedir}/build/artifact -distrib.dir=${basedir}/build/distrib -doc.build.dir=${basedir}/build/doc -reports.dir=${doc.build.dir}/reports -test.xml.dir=${build.dir}/test-report -test.report.dir=${reports.dir}/test -coverage.report.dir=${reports.dir}/coverage -javadoc.build.dir=${reports.dir}/api -doc.src.dir=${basedir}/doc -checkstyle.report.dir=${reports.dir}/checkstyle -checkstyle.src.dir=${basedir}/src/etc/checkstyle - -ivy.minimum.javaversion=1.4 -debug.mode=on -ivy.install.version=1.4.1 - -status=integration - -test.class.pattern = *Test - +# *************************************************************** +# * 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 +src.dir=${basedir}/src/java +test.dir=${basedir}/test/java +build.dir=${basedir}/build +classes.build.dir=${basedir}/build/classes +core.classes.build.dir=${classes.build.dir}/core +ant.classes.build.dir=${classes.build.dir}/ant +optional.classes.build.dir=${classes.build.dir}/optional +test.build.dir=${basedir}/build/test +artifacts.build.dir=${basedir}/build/artifact +distrib.dir=${basedir}/build/distrib +doc.build.dir=${basedir}/build/doc +reports.dir=${doc.build.dir}/reports +test.xml.dir=${build.dir}/test-report +test.report.dir=${reports.dir}/test +coverage.report.dir=${reports.dir}/coverage +javadoc.build.dir=${reports.dir}/api +doc.src.dir=${basedir}/doc +checkstyle.report.dir=${reports.dir}/checkstyle +checkstyle.src.dir=${basedir}/src/etc/checkstyle + +ivy.minimum.javaversion=1.4 +debug.mode=on +ivy.install.version=1.4.1 + +status=integration + +test.class.pattern = *Test + diff --git a/build.xml b/build.xml index 4e057dac..7afdfad8 100644 --- a/build.xml +++ b/build.xml @@ -1,490 +1,500 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -
-
- - - -
- - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+
+ + + +
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/doc/apache-proposal.txt b/doc/apache-proposal.txt index 05ebdfb1..0a748a38 100644 --- a/doc/apache-proposal.txt +++ b/doc/apache-proposal.txt @@ -1,121 +1,121 @@ -= Ivy Proposal = - -The following presents the proposal for creating a new Ivy project within the Apache Software Foundation. - -== Abstract == -Ivy (http://www.jayasoft.org/ivy) is a java based tool for tracking, resolving and managing project dependencies. - -== Proposal == -Ivy is a tool for managing (recording, tracking, resolving and reporting) project dependencies. It is characterized by the following: - 1) flexibility and configurability - Ivy is essentially process agnostic and is not tied to any methodology or structure. Instead it provides the necessary flexibility and configurability to be adapted to a broad range of dependency management and build processes. - 2) tight integration with Apache Ant - while available as a standalone tool, Ivy works particularly well with Apache Ant providing a number of powerful Ant tasks ranging from dependency resolution to dependency reporting and publication. - -== Rationale == - -Software development is increasingly characterized by leveraging externally provided components/capabilities and by a rapid release cycle. As a result it is not unusual for a project to depend on numerous third-party components which themselves may be dependent on a multitude of third-party of different or identical third-party components. Managing these dependencies - determining what the dependencies are, how they are used, the impact of a change, conflicts among dependencies, etc. - is extremely difficult and absolutely necessary. Ivy is one of a handful of tools addressing this need. While often compared to Maven - which has similar Ant tasks - Ivy differs from Maven in both its focus and philosophy. Ivy is solely focused on dependency management and is designed from the ground up to adapt to a wide range of requirements and scenarios. Examples include multiple aritfacts per module, plugin resolvers, configurable repository configurations and conflict managers. - -The maintainers of Ivy are interested in joining the Apache Software Foundation for several reasons: - * Ivy has been hosted since its beginning in 2004 by a private company, which make people feel like it's a corporate product, thus slowing the contribution by the community. We strongly believe in the open source movement, and would like to make Ivy independent from Jayasoft. - * We'd like to enjoy the benefits of utilizing Apache's infrastructure and legal protection. - * It might open the door for cooperation with other projects, such as Ant or Maven. - * We strongly believe in Apache philosophy, especially Meritocracy. - -== Current status == -=== Meritocracy === - -Ivy was originally created by Xavier Hanin in September 2004. Since then more than 20 users have contributed patches, and one of them has been promoted to the status of committer based on his merit through patch contribution. - -=== Community === - -Ivy already has a growing user community, with more than 10,000 downloads since its 1.0 version and more than 500 users registered on the forum. - -=== Core Developers === - -Ivy has only two core developers for the moment, but we hope joining the ASF will help increase this number. - -Xavier Hanin is the creator of the project, is an independant consultant and co founder of Jayasoft. He has an experience of 9 years in Java software development, uses open source projects intensively, and started his real participation in open source development with Ivy. -Maarten Coene has joined the committer team in may 2006. He has an experience of 9 years in java development, is co-administrator of dom4j, ex-committer for scarab, has contributed patches to several open-source projects and is a user of a lot of open-source projects. - -=== Alignment === - -Ivy has no mandatory dependencies except java 1.4. However, it is strongly recommended to be used with Ant. Ivy uses also other Apache projects, especially from Jakarta Commons. - -== Known risks == - -=== Orphaned products === -Due to its small number of committers, there is a risk of being orphaned. The main knowledge of the codebase is still mainly owned by Xavier Hanin. Even if Xavier has no plan to leave Ivy development, this is a problem we are aware of and know that need to be worked on so that the project become less dependent on an individual. - -=== Inexperience with Open Source === -While distributed under an open source license, access to Ivy was initially limited with no public access to the issue tracking system or svn repository. While things have changed since then - the svn repository is publicly accessible, a JIRA instance has been setup since june 2005, many new features are first discussed on the forum or JIRA - experience with a true open source development model is currently limited. -However, Maarten has already a good experience with true open development process, and bring his experience to the project. - -=== Homogenous Developers === -With only two core developers, at least they are not homogenous! Xavier and Maarten knew each other only due to their common interest in Ivy. - -=== Reliance on Salaried Developers === -Maarten is not paid to work on Ivy. -Xavier's case is more complex, as a co founder of Jayasoft, part of his time in Jayasoft was dedicated to Ivy and other open source developments. He now works mainly as an independent consultant, and thus is not a salaried developer. - -=== Relationships with Other Apache Products === -Ivy has a strong relationship with Apache Ant, and is often seen as a good companion of Ant. Being part of Apache could help for a closer collaboration between the two projects. - -=== A Excessive Fascination with the Apache Brand === -Even if we recognize the strong value of the Apache Brand, the purpose of joining Apache is not focused on improving the visibility of the project. The main focus of this proposition is to make Ivy a more open project, with a closer integration with Apache Ant. Even if Ivy does not join the ASF, Ivy will move out of Jayasoft umbrella and try to attract more developers. - -== Documentation == -Further reading on Ivy can be found at: -http://www.jayasoft.org/ivy - -== Initial Source == -The initial code base can be found at: -http://svn.jayasoft.org/projects/tools/ivy - -== External Dependencies == -Ivy has no mandatory dependencies at runtime. - -For compilation, it requires: -apache ant -apache commons-httpclient -apache commons-cli -apache oro -apache commons-vfs -jcraft jsch (BSD, already used by commons-vfs and by ant) - -== Required Resources == - -=== Mailing lists === - * ivy-private (with moderated subscriptions) - * ivy-dev - * ivy-user - -=== Subversion Directory === -https://svn.apache.org/repos/asf/incubator/ivy - -=== Issue Tracking === -JIRA Ivy (IVY) -An import from existing JIRA issues at http://jira.jayasoft.org/ would also be very much appreciated - -== Initial Committers == -Xavier Hanin (xavier dot hanin at gmail dot com) -Maarten Coene (maarten_coene at yahoo dot com) - -== Affiliations == -As stated in the Reliance on salaried developers section, Xavier is a co founder of Jayasoft which used to host the project. However, Jayasoft is shifting its focus to local consulting and thus won't be involved anymore in open source development. The participation of Xavier in the project is thus made as an individual, not as a member of Jayasoft. He also strongly believe in the meritocracy principle, and he's ready to see it applied to the project whatever the consequence are for his own weight in the project. - -== Sponsors == - -=== Champion === -Antoine Levy-Lambert -Sylvain Wallez - -=== Nominated Mentors === -Antoine Levy-Lambert -Stephane Baillez -Steve Loughran - -=== Sponsoring Entity === -The Ant PMC has voted the following resolution: -The Ant PMC sponsors Ivy moving to the Apache Incubator. -If the Ivy community wishes to move Ivy to become an Ant subproject -after successful incubation, and if the ASF board agrees to it, Ant -will welcome Ivy as a subproject after the incubation period. += Ivy Proposal = + +The following presents the proposal for creating a new Ivy project within the Apache Software Foundation. + +== Abstract == +Ivy (http://www.jayasoft.org/ivy) is a java based tool for tracking, resolving and managing project dependencies. + +== Proposal == +Ivy is a tool for managing (recording, tracking, resolving and reporting) project dependencies. It is characterized by the following: + 1) flexibility and configurability - Ivy is essentially process agnostic and is not tied to any methodology or structure. Instead it provides the necessary flexibility and configurability to be adapted to a broad range of dependency management and build processes. + 2) tight integration with Apache Ant - while available as a standalone tool, Ivy works particularly well with Apache Ant providing a number of powerful Ant tasks ranging from dependency resolution to dependency reporting and publication. + +== Rationale == + +Software development is increasingly characterized by leveraging externally provided components/capabilities and by a rapid release cycle. As a result it is not unusual for a project to depend on numerous third-party components which themselves may be dependent on a multitude of third-party of different or identical third-party components. Managing these dependencies - determining what the dependencies are, how they are used, the impact of a change, conflicts among dependencies, etc. - is extremely difficult and absolutely necessary. Ivy is one of a handful of tools addressing this need. While often compared to Maven - which has similar Ant tasks - Ivy differs from Maven in both its focus and philosophy. Ivy is solely focused on dependency management and is designed from the ground up to adapt to a wide range of requirements and scenarios. Examples include multiple aritfacts per module, plugin resolvers, configurable repository configurations and conflict managers. + +The maintainers of Ivy are interested in joining the Apache Software Foundation for several reasons: + * Ivy has been hosted since its beginning in 2004 by a private company, which make people feel like it's a corporate product, thus slowing the contribution by the community. We strongly believe in the open source movement, and would like to make Ivy independent from Jayasoft. + * We'd like to enjoy the benefits of utilizing Apache's infrastructure and legal protection. + * It might open the door for cooperation with other projects, such as Ant or Maven. + * We strongly believe in Apache philosophy, especially Meritocracy. + +== Current status == +=== Meritocracy === + +Ivy was originally created by Xavier Hanin in September 2004. Since then more than 20 users have contributed patches, and one of them has been promoted to the status of committer based on his merit through patch contribution. + +=== Community === + +Ivy already has a growing user community, with more than 10,000 downloads since its 1.0 version and more than 500 users registered on the forum. + +=== Core Developers === + +Ivy has only two core developers for the moment, but we hope joining the ASF will help increase this number. + +Xavier Hanin is the creator of the project, is an independant consultant and co founder of Jayasoft. He has an experience of 9 years in Java software development, uses open source projects intensively, and started his real participation in open source development with Ivy. +Maarten Coene has joined the committer team in may 2006. He has an experience of 9 years in java development, is co-administrator of dom4j, ex-committer for scarab, has contributed patches to several open-source projects and is a user of a lot of open-source projects. + +=== Alignment === + +Ivy has no mandatory dependencies except java 1.4. However, it is strongly recommended to be used with Ant. Ivy uses also other Apache projects, especially from Jakarta Commons. + +== Known risks == + +=== Orphaned products === +Due to its small number of committers, there is a risk of being orphaned. The main knowledge of the codebase is still mainly owned by Xavier Hanin. Even if Xavier has no plan to leave Ivy development, this is a problem we are aware of and know that need to be worked on so that the project become less dependent on an individual. + +=== Inexperience with Open Source === +While distributed under an open source license, access to Ivy was initially limited with no public access to the issue tracking system or svn repository. While things have changed since then - the svn repository is publicly accessible, a JIRA instance has been setup since june 2005, many new features are first discussed on the forum or JIRA - experience with a true open source development model is currently limited. +However, Maarten has already a good experience with true open development process, and bring his experience to the project. + +=== Homogenous Developers === +With only two core developers, at least they are not homogenous! Xavier and Maarten knew each other only due to their common interest in Ivy. + +=== Reliance on Salaried Developers === +Maarten is not paid to work on Ivy. +Xavier's case is more complex, as a co founder of Jayasoft, part of his time in Jayasoft was dedicated to Ivy and other open source developments. He now works mainly as an independent consultant, and thus is not a salaried developer. + +=== Relationships with Other Apache Products === +Ivy has a strong relationship with Apache Ant, and is often seen as a good companion of Ant. Being part of Apache could help for a closer collaboration between the two projects. + +=== A Excessive Fascination with the Apache Brand === +Even if we recognize the strong value of the Apache Brand, the purpose of joining Apache is not focused on improving the visibility of the project. The main focus of this proposition is to make Ivy a more open project, with a closer integration with Apache Ant. Even if Ivy does not join the ASF, Ivy will move out of Jayasoft umbrella and try to attract more developers. + +== Documentation == +Further reading on Ivy can be found at: +http://www.jayasoft.org/ivy + +== Initial Source == +The initial code base can be found at: +http://svn.jayasoft.org/projects/tools/ivy + +== External Dependencies == +Ivy has no mandatory dependencies at runtime. + +For compilation, it requires: +apache ant +apache commons-httpclient +apache commons-cli +apache oro +apache commons-vfs +jcraft jsch (BSD, already used by commons-vfs and by ant) + +== Required Resources == + +=== Mailing lists === + * ivy-private (with moderated subscriptions) + * ivy-dev + * ivy-user + +=== Subversion Directory === +https://svn.apache.org/repos/asf/incubator/ivy + +=== Issue Tracking === +JIRA Ivy (IVY) +An import from existing JIRA issues at http://jira.jayasoft.org/ would also be very much appreciated + +== Initial Committers == +Xavier Hanin (xavier dot hanin at gmail dot com) +Maarten Coene (maarten_coene at yahoo dot com) + +== Affiliations == +As stated in the Reliance on salaried developers section, Xavier is a co founder of Jayasoft which used to host the project. However, Jayasoft is shifting its focus to local consulting and thus won't be involved anymore in open source development. The participation of Xavier in the project is thus made as an individual, not as a member of Jayasoft. He also strongly believe in the meritocracy principle, and he's ready to see it applied to the project whatever the consequence are for his own weight in the project. + +== Sponsors == + +=== Champion === +Antoine Levy-Lambert +Sylvain Wallez + +=== Nominated Mentors === +Antoine Levy-Lambert +Stephane Baillez +Steve Loughran + +=== Sponsoring Entity === +The Ant PMC has voted the following resolution: +The Ant PMC sponsors Ivy moving to the Apache Incubator. +If the Ivy community wishes to move Ivy to become an Ant subproject +after successful incubation, and if the ASF board agrees to it, Ant +will welcome Ivy as a subproject after the incubation period. diff --git a/doc/ideas.txt b/doc/ideas.txt index 1f450af6..9de6c5a7 100644 --- a/doc/ideas.txt +++ b/doc/ideas.txt @@ -1,70 +1,70 @@ -- messages - it is quite difficult to know exactly what messages should be output to the console or not, and it often - depends on the user profile: beginner, expert, build manager, simple user, ... - - Being able to define the messages output in a single and homogeneous way could be a good thing. - - To allow this, maybe a solution could be to output messages in the code only by using keys: - LOGGER.debug("unhandled.revision", mrid.getRevision()); - - The LOGGER would be a constant initialised with the class name. - - a profile wold consist in a message.properties file, associating each key (prefixed by the FQCN) to a - message for the given profile. A key with no mapping result in no message at all. - - it would be possible to disable all messages of a class or activate only a certain level per class - (as in log4j for instance) to customize a profile at runtime - - shifting is costly, about 400 calls to messages - -- promote task to update an already published module with a new status - this task would also automatically update compatiblity data (see below) -- tag task to add one or several tags to an already published module - tag could be added in a simple properties file next to the module ivy file - this properties would be updated by this task - every time ivy parses an ivy file, it would try to locate corresponding tag file, - and if any load tags in the module descriptor instance -- compatiblity data - tags could be used for to indicate that a module has some compatibility level - with another one: if module A 2.0 has been tested successfully with B 1.0 and thus obtain status milestone, - then a tag "compatible.with.A.2.0=milestone" is put on B 1.0 - then latest version matcher code could be updated to handle something like this: - latest.compatible.milestone - to be able to get the latest version of a dependency with at least a tag like - compatible.with.A.[any revision]=milestone - - since all tags should be inspected to know that, maybe using an xml file like this would be better: - - - - - - This would be cleaner, but less simple, and less flexible than using a tags system, which could be used - for other use cases. - - Another solution would be to put two tags on B 1.0: one with A revision, and one without. The tag without - the revision could be used for latest.compatible.*, meaning that the last compatiblity status only would - be used. For instance, A 2.0 is said to be release compatible with B 1.0. using latest.compatible.release - is thus resolved to B 1.0. But now A 2.1 is built, and a first test tell that it is (at least) milestone - compatible with B 1.0. The compatibility status of B is thus decreased to milestone, and - latest.compatible.release is not resolved anymore to B 1.0, but maybe B 0.9... at least until the release - compatibility tests are done on A. Then if it is release compatible, the tag is put back to the good status, - and if it isn't compatible, the compatiblity status is left to milestone, which is ok. - Consequently the main problem with this solution is the time before all the tests are run. So maybe a module - should be promoted (and thus compatiblity status updated) only when all tests are done, or when an incompatible - level is reached. Note that this solution is only acceptable in case of automatic tests. When the promotion is - done by a QA team several days or even weeks after the previous status, maybe we can't wait for these tests - to be done... - Another solution would be to promote the module at eeach step, but only update the tag if the compatibility level - is better than the previous one. Another task woudl then allow to indicate an incompatibility, if some level of - tests then fails. - - - switching between latest compatible and latest version could also be done without any modification in ivy file: - use latest.* dependency revision, and configure your resolve task to use compatible only versions. - - this way testing absolute latest version for a continuous integration server would be easy, and if the latest - version fails, latest compatible could be used easily, to test the module in a relative isolation of dependency - changes. In this case the continuous integration server should notify of the first failure before notifying of - the success of the compatible build: integration of latest modules has failed, but not the module itself. - It would thus allow to have more often a latest successful build, even in case of api breaks. +- messages + it is quite difficult to know exactly what messages should be output to the console or not, and it often + depends on the user profile: beginner, expert, build manager, simple user, ... + + Being able to define the messages output in a single and homogeneous way could be a good thing. + + To allow this, maybe a solution could be to output messages in the code only by using keys: + LOGGER.debug("unhandled.revision", mrid.getRevision()); + + The LOGGER would be a constant initialised with the class name. + + a profile wold consist in a message.properties file, associating each key (prefixed by the FQCN) to a + message for the given profile. A key with no mapping result in no message at all. + + it would be possible to disable all messages of a class or activate only a certain level per class + (as in log4j for instance) to customize a profile at runtime + + shifting is costly, about 400 calls to messages + +- promote task to update an already published module with a new status + this task would also automatically update compatiblity data (see below) +- tag task to add one or several tags to an already published module + tag could be added in a simple properties file next to the module ivy file + this properties would be updated by this task + every time ivy parses an ivy file, it would try to locate corresponding tag file, + and if any load tags in the module descriptor instance +- compatiblity data + tags could be used for to indicate that a module has some compatibility level + with another one: if module A 2.0 has been tested successfully with B 1.0 and thus obtain status milestone, + then a tag "compatible.with.A.2.0=milestone" is put on B 1.0 + then latest version matcher code could be updated to handle something like this: + latest.compatible.milestone + to be able to get the latest version of a dependency with at least a tag like + compatible.with.A.[any revision]=milestone + + since all tags should be inspected to know that, maybe using an xml file like this would be better: + + + + + + This would be cleaner, but less simple, and less flexible than using a tags system, which could be used + for other use cases. + + Another solution would be to put two tags on B 1.0: one with A revision, and one without. The tag without + the revision could be used for latest.compatible.*, meaning that the last compatiblity status only would + be used. For instance, A 2.0 is said to be release compatible with B 1.0. using latest.compatible.release + is thus resolved to B 1.0. But now A 2.1 is built, and a first test tell that it is (at least) milestone + compatible with B 1.0. The compatibility status of B is thus decreased to milestone, and + latest.compatible.release is not resolved anymore to B 1.0, but maybe B 0.9... at least until the release + compatibility tests are done on A. Then if it is release compatible, the tag is put back to the good status, + and if it isn't compatible, the compatiblity status is left to milestone, which is ok. + Consequently the main problem with this solution is the time before all the tests are run. So maybe a module + should be promoted (and thus compatiblity status updated) only when all tests are done, or when an incompatible + level is reached. Note that this solution is only acceptable in case of automatic tests. When the promotion is + done by a QA team several days or even weeks after the previous status, maybe we can't wait for these tests + to be done... + Another solution would be to promote the module at eeach step, but only update the tag if the compatibility level + is better than the previous one. Another task woudl then allow to indicate an incompatibility, if some level of + tests then fails. + + + switching between latest compatible and latest version could also be done without any modification in ivy file: + use latest.* dependency revision, and configure your resolve task to use compatible only versions. + + this way testing absolute latest version for a continuous integration server would be easy, and if the latest + version fails, latest compatible could be used easily, to test the module in a relative isolation of dependency + changes. In this case the continuous integration server should notify of the first failure before notifying of + the success of the compatible build: integration of latest modules has failed, but not the module itself. + It would thus allow to have more often a latest successful build, even in case of api breaks. diff --git a/doc/presentations/apache-con-2007/demo/1/build.xml b/doc/presentations/apache-con-2007/demo/1/build.xml index 5b87cd51..19972bbf 100644 --- a/doc/presentations/apache-con-2007/demo/1/build.xml +++ b/doc/presentations/apache-con-2007/demo/1/build.xml @@ -1,53 +1,53 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/1/ivysettings.xml b/doc/presentations/apache-con-2007/demo/1/ivysettings.xml index f6670b4d..ca913dd4 100644 --- a/doc/presentations/apache-con-2007/demo/1/ivysettings.xml +++ b/doc/presentations/apache-con-2007/demo/1/ivysettings.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/2/build.xml b/doc/presentations/apache-con-2007/demo/2/build.xml index 40690f59..eb8b16d6 100644 --- a/doc/presentations/apache-con-2007/demo/2/build.xml +++ b/doc/presentations/apache-con-2007/demo/2/build.xml @@ -1,50 +1,50 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/2/ivy.xml b/doc/presentations/apache-con-2007/demo/2/ivy.xml index ba01f9cd..316b3792 100644 --- a/doc/presentations/apache-con-2007/demo/2/ivy.xml +++ b/doc/presentations/apache-con-2007/demo/2/ivy.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/2/ivysettings.xml b/doc/presentations/apache-con-2007/demo/2/ivysettings.xml index f6670b4d..ca913dd4 100644 --- a/doc/presentations/apache-con-2007/demo/2/ivysettings.xml +++ b/doc/presentations/apache-con-2007/demo/2/ivysettings.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/3/common/build.properties b/doc/presentations/apache-con-2007/demo/3/common/build.properties index f873ca50..4fe1e7a9 100644 --- a/doc/presentations/apache-con-2007/demo/3/common/build.properties +++ b/doc/presentations/apache-con-2007/demo/3/common/build.properties @@ -1,24 +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. -# *************************************************************** -lib.dir = ${basedir}/lib -build.dir = ${basedir}/build -classes.dir = ${build.dir}/classes -src.dir = ${basedir}/src - -jar.file = ${build.dir}/${ant.project.name}.jar +# *************************************************************** +# * 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 + +jar.file = ${build.dir}/${ant.project.name}.jar diff --git a/doc/presentations/apache-con-2007/demo/3/common/build.xml b/doc/presentations/apache-con-2007/demo/3/common/build.xml index 233fc261..d5dc9065 100644 --- a/doc/presentations/apache-con-2007/demo/3/common/build.xml +++ b/doc/presentations/apache-con-2007/demo/3/common/build.xml @@ -1,84 +1,84 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/3/common/ivysettings.xml b/doc/presentations/apache-con-2007/demo/3/common/ivysettings.xml index 63a96ab2..46ac8f99 100644 --- a/doc/presentations/apache-con-2007/demo/3/common/ivysettings.xml +++ b/doc/presentations/apache-con-2007/demo/3/common/ivysettings.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.properties b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.properties index 4e3ac24a..0052a4fc 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.properties +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.properties @@ -1,20 +1,20 @@ -# *************************************************************** -# * 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. -# *************************************************************** -wkspace.dir = ${basedir}/.. -common.dir = ${wkspace.dir}/common +# *************************************************************** +# * 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. +# *************************************************************** +wkspace.dir = ${basedir}/.. +common.dir = ${wkspace.dir}/common diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.xml b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.xml index 8efc7158..7c1af71f 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.xml +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/build.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/ivy.xml b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/ivy.xml index 83570027..1214f048 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/ivy.xml +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/ivy.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/src/demo3A/Demo3A.java b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/src/demo3A/Demo3A.java index e77c647f..d02a0ea9 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/src/demo3A/Demo3A.java +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3A/src/demo3A/Demo3A.java @@ -1,7 +1,7 @@ -package demo3A; - -public class Demo3A { - public static String sayHello() { - return "Hello from Demo3A"; - } -} \ No newline at end of file +package demo3A; + +public class Demo3A { + public static String sayHello() { + return "Hello from Demo3A"; + } +} diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.properties b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.properties index 4e3ac24a..0052a4fc 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.properties +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.properties @@ -1,20 +1,20 @@ -# *************************************************************** -# * 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. -# *************************************************************** -wkspace.dir = ${basedir}/.. -common.dir = ${wkspace.dir}/common +# *************************************************************** +# * 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. +# *************************************************************** +wkspace.dir = ${basedir}/.. +common.dir = ${wkspace.dir}/common diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.xml b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.xml index 0dcd8e97..f71dffe5 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.xml +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/build.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/ivy.xml b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/ivy.xml index 0aaa96ae..8ed970c5 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/ivy.xml +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/ivy.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/src/demo3B/Demo3B.java b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/src/demo3B/Demo3B.java index cd6494b4..6f2d02d2 100644 --- a/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/src/demo3B/Demo3B.java +++ b/doc/presentations/apache-con-2007/demo/3/ivy-demo-3B/src/demo3B/Demo3B.java @@ -1,7 +1,7 @@ -package demo3B; - -public class Demo3B { - public static String sayHello() { - return demo3A.Demo3A.sayHello(); - } -} \ No newline at end of file +package demo3B; + +public class Demo3B { + public static String sayHello() { + return demo3A.Demo3A.sayHello(); + } +} diff --git a/doc/presentations/apache-con-2007/demo/README.txt b/doc/presentations/apache-con-2007/demo/README.txt index 39fd48c1..fdf9cc1e 100644 --- a/doc/presentations/apache-con-2007/demo/README.txt +++ b/doc/presentations/apache-con-2007/demo/README.txt @@ -1,3 +1,3 @@ -To run the demos you just need java 1.4+ and ant 1.6.2+ installed. - -Then go in the demo directory and type "ant" on the command line. +To run the demos you just need java 1.4+ and ant 1.6.2+ installed. + +Then go in the demo directory and type "ant" on the command line. diff --git a/doc/presentations/apache-con-2007/samples/ivysettings-1.xml b/doc/presentations/apache-con-2007/samples/ivysettings-1.xml index 7d28d4f6..89eeec8c 100644 --- a/doc/presentations/apache-con-2007/samples/ivysettings-1.xml +++ b/doc/presentations/apache-con-2007/samples/ivysettings-1.xml @@ -1,27 +1,27 @@ - - - - - - - - - + + + + + + + + + diff --git a/doc/presentations/apache-con-2007/samples/ivysettings-2.xml b/doc/presentations/apache-con-2007/samples/ivysettings-2.xml index 6bd0c114..6044bec1 100644 --- a/doc/presentations/apache-con-2007/samples/ivysettings-2.xml +++ b/doc/presentations/apache-con-2007/samples/ivysettings-2.xml @@ -1,40 +1,40 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/repository.properties b/doc/repository.properties index 2eb82d92..b28ccd39 100644 --- a/doc/repository.properties +++ b/doc/repository.properties @@ -1,25 +1,25 @@ -# *************************************************************** -# * 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.ibiblio.default.artifact.root = http://www.ibiblio.org/maven/ -ivy.ibiblio.default.artifact.pattern = [module]/[type]s/[artifact]-[revision].[ext] - -ivy.ivyrep.default.ivy.root = http://ivyrep.jayasoft.org/ -ivy.ivyrep.default.ivy.pattern = [organisation]/[module]/ivy-[revision].xml -ivy.ivyrep.default.artifact.root = ${ivy.ibiblio.default.artifact.root} -ivy.ivyrep.default.artifact.pattern = ${ivy.ibiblio.default.artifact.pattern} +# *************************************************************** +# * 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.ibiblio.default.artifact.root = http://www.ibiblio.org/maven/ +ivy.ibiblio.default.artifact.pattern = [module]/[type]s/[artifact]-[revision].[ext] + +ivy.ivyrep.default.ivy.root = http://ivyrep.jayasoft.org/ +ivy.ivyrep.default.ivy.pattern = [organisation]/[module]/ivy-[revision].xml +ivy.ivyrep.default.artifact.root = ${ivy.ibiblio.default.artifact.root} +ivy.ivyrep.default.artifact.pattern = ${ivy.ibiblio.default.artifact.pattern} diff --git a/doc/samples/build-install.xml b/doc/samples/build-install.xml index 1b89d22c..ab36c488 100644 --- a/doc/samples/build-install.xml +++ b/doc/samples/build-install.xml @@ -1,72 +1,72 @@ - - - - - - - - - - - - - - - - - - - ]]> - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + ]]> + + + + + + + + + + + + + + diff --git a/doc/samples/build.xml b/doc/samples/build.xml index aa38d594..97ab330b 100644 --- a/doc/samples/build.xml +++ b/doc/samples/build.xml @@ -1,144 +1,144 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -We are now ready to execute our simple program with its dependency on commons-lang. -Let's go! - - - - - - - - - - - - - -package example; - -import org.apache.commons.lang.WordUtils; - -public class Hello { - public static void main(String[] args) { - String message = "hello ivy !"; - System.out.println("standard message : " + message); - System.out.println("capitalized by " + WordUtils.class.getName() - + " : " + WordUtils.capitalizeFully(message)); - } -} - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +We are now ready to execute our simple program with its dependency on commons-lang. +Let's go! + + + + + + + + + + + + + +package example; + +import org.apache.commons.lang.WordUtils; + +public class Hello { + public static void main(String[] args) { + String message = "hello ivy !"; + System.out.println("standard message : " + message); + System.out.println("capitalized by " + WordUtils.class.getName() + + " : " + WordUtils.capitalizeFully(message)); + } +} + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/samples/ivy-sample-xslt.xml b/doc/samples/ivy-sample-xslt.xml index 4d426676..8d8a265e 100644 --- a/doc/samples/ivy-sample-xslt.xml +++ b/doc/samples/ivy-sample-xslt.xml @@ -1,102 +1,102 @@ - - - - - - - - - - - - - - - This module is great !
- You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + + This module is great !
+ You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/doc/samples/ivy-sample.xml b/doc/samples/ivy-sample.xml index e6d31d8c..12b35828 100644 --- a/doc/samples/ivy-sample.xml +++ b/doc/samples/ivy-sample.xml @@ -1,101 +1,101 @@ - - - - - - - - - - - - - - This module is great !
- You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + This module is great !
+ You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/doc/samples/ivysettings-default.xml b/doc/samples/ivysettings-default.xml index d5ca604b..9d985c1a 100644 --- a/doc/samples/ivysettings-default.xml +++ b/doc/samples/ivysettings-default.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/doc/samples/jayasoft-ivyrep-example-default.html b/doc/samples/jayasoft-ivyrep-example-default.html index c7591c71..7de1ac1d 100644 --- a/doc/samples/jayasoft-ivyrep-example-default.html +++ b/doc/samples/jayasoft-ivyrep-example-default.html @@ -1,372 +1,372 @@ - - - - - - -Ivy report :: ivyrep-example by jayasoft :: default - - - - - - - -

-ivyrep-example - by - jayasoft -

-
- resolved on - 2005-04-08 13:33:40
- -
-

Dependencies Stats

- - - - - - - - - - - - - -
Modules3
Revisions4 - (0 searched searched, - 0 downloaded downloaded, - 1 evicted evicted, - 0 errors error)
Artifacts3 - (0 downloaded, - 0 failed)
Artifacts size219 kB - (0 kB downloaded, - 219 kB in cache)
-

Dependencies Overview

- - - - - - - - - - - - - - - - - - - - - - - -
ModuleRevisionStatusLicensesSize
commons-cli - by - apache1.0releaseApache32 kB -
--- commons-lang - by - apache2.0release166 kB -
--- commons-lang - by - apache1.00 kB - evicted
--- commons-logging - by - apache1.0releaseApache21 kB -
commons-lang - by - apache2.0release166 kB -
-

Details

-

-commons-cli by apacheresolved by ivyrep -

-

- - Revision: 1.0 -

- - - - - - - - - - - - - - - - - - - - - - -
Home Pagehttp://jakarta.apache.org/commons/cli/
Statusrelease
Publication20021227095900
Resolverivyrep
Configurationsdefault
Artifacts size32 kB - (0 kB downloaded, - 32 kB in cache)
LicensesApache
-
Required by
- - - - - - - - - - - -
OrganisationNameIn ConfigurationsAsked Revision
jayasoftivyrep-exampledefault1.0
-
Dependencies
- - - - - - - - - - - - - - - - - -
ModuleRevisionStatusLicensesSize
commons-lang - by - apache2.0release166 kB -
commons-lang - by - apache1.00 kB - evicted
commons-logging - by - apache1.0releaseApache21 kB -
-
Artifacts
- - - - - - - - - - - -
NameTypeExtDownloadSize
commons-clijarjarno32 kB
-

-commons-lang by apacheresolved by ivyrep -

-

- - Revision: 2.0 -

- - - - - - - - - - - - - - - - -
Statusrelease
Publication20050407222759
Resolverivyrep
Configurationsdefault
Artifacts size166 kB - (0 kB downloaded, - 166 kB in cache)
-
Required by
- - - - - - - - - - - - - - -
OrganisationNameIn ConfigurationsAsked Revision
apachecommons-clidefault1.0
jayasoftivyrep-exampledefault2.0
-
Dependencies
- - - - -
- No dependency -
-
Artifacts
- - - - - - - - - - - -
NameTypeExtDownloadSize
commons-langjarjarno166 kB
-

- - Revision: 1.0evicted -

- - - - - - - - - - - - - - - - - - - -
Status
Publication
Resolver
Configurations
Artifacts size0 kB - (0 kB downloaded, - 0 kB in cache)
Evicted by2.0 - in latest-revision conflict manager -
-
Required by
- - - - - - - - - - - -
OrganisationNameIn ConfigurationsAsked Revision
apachecommons-clidefault1.0
-

-commons-logging by apacheresolved by ivyrep -

-

- - Revision: 1.0 -

- - - - - - - - - - - - - - - - - - - - - - -
Home Pagehttp://jakarta.apache.org/commons/logging/
Statusrelease
Publication20020220232200
Resolverivyrep
Configurationsdefault
Artifacts size21 kB - (0 kB downloaded, - 21 kB in cache)
LicensesApache
-
Required by
- - - - - - - - - - - -
OrganisationNameIn ConfigurationsAsked Revision
apachecommons-clidefault1.0
-
Dependencies
- - - - -
- No dependency -
-
Artifacts
- - - - - - - - - - - -
NameTypeExtDownloadSize
commons-loggingjarjarno21 kB
-
- - - - + + + + + + +Ivy report :: ivyrep-example by jayasoft :: default + + + + + + + +

+ivyrep-example + by + jayasoft +

+
+ resolved on + 2005-04-08 13:33:40
+ +
+

Dependencies Stats

+ + + + + + + + + + + + + +
Modules3
Revisions4 + (0 searched searched, + 0 downloaded downloaded, + 1 evicted evicted, + 0 errors error)
Artifacts3 + (0 downloaded, + 0 failed)
Artifacts size219 kB + (0 kB downloaded, + 219 kB in cache)
+

Dependencies Overview

+ + + + + + + + + + + + + + + + + + + + + + + +
ModuleRevisionStatusLicensesSize
commons-cli + by + apache1.0releaseApache32 kB +
--- commons-lang + by + apache2.0release166 kB +
--- commons-lang + by + apache1.00 kB + evicted
--- commons-logging + by + apache1.0releaseApache21 kB +
commons-lang + by + apache2.0release166 kB +
+

Details

+

+commons-cli by apacheresolved by ivyrep +

+

+ + Revision: 1.0 +

+ + + + + + + + + + + + + + + + + + + + + + +
Home Pagehttp://jakarta.apache.org/commons/cli/
Statusrelease
Publication20021227095900
Resolverivyrep
Configurationsdefault
Artifacts size32 kB + (0 kB downloaded, + 32 kB in cache)
LicensesApache
+
Required by
+ + + + + + + + + + + +
OrganisationNameIn ConfigurationsAsked Revision
jayasoftivyrep-exampledefault1.0
+
Dependencies
+ + + + + + + + + + + + + + + + + +
ModuleRevisionStatusLicensesSize
commons-lang + by + apache2.0release166 kB +
commons-lang + by + apache1.00 kB + evicted
commons-logging + by + apache1.0releaseApache21 kB +
+
Artifacts
+ + + + + + + + + + + +
NameTypeExtDownloadSize
commons-clijarjarno32 kB
+

+commons-lang by apacheresolved by ivyrep +

+

+ + Revision: 2.0 +

+ + + + + + + + + + + + + + + + +
Statusrelease
Publication20050407222759
Resolverivyrep
Configurationsdefault
Artifacts size166 kB + (0 kB downloaded, + 166 kB in cache)
+
Required by
+ + + + + + + + + + + + + + +
OrganisationNameIn ConfigurationsAsked Revision
apachecommons-clidefault1.0
jayasoftivyrep-exampledefault2.0
+
Dependencies
+ + + + +
+ No dependency +
+
Artifacts
+ + + + + + + + + + + +
NameTypeExtDownloadSize
commons-langjarjarno166 kB
+

+ + Revision: 1.0evicted +

+ + + + + + + + + + + + + + + + + + + +
Status
Publication
Resolver
Configurations
Artifacts size0 kB + (0 kB downloaded, + 0 kB in cache)
Evicted by2.0 + in latest-revision conflict manager +
+
Required by
+ + + + + + + + + + + +
OrganisationNameIn ConfigurationsAsked Revision
apachecommons-clidefault1.0
+

+commons-logging by apacheresolved by ivyrep +

+

+ + Revision: 1.0 +

+ + + + + + + + + + + + + + + + + + + + + + +
Home Pagehttp://jakarta.apache.org/commons/logging/
Statusrelease
Publication20020220232200
Resolverivyrep
Configurationsdefault
Artifacts size21 kB + (0 kB downloaded, + 21 kB in cache)
LicensesApache
+
Required by
+ + + + + + + + + + + +
OrganisationNameIn ConfigurationsAsked Revision
apachecommons-clidefault1.0
+
Dependencies
+ + + + +
+ No dependency +
+
Artifacts
+ + + + + + + + + + + +
NameTypeExtDownloadSize
commons-loggingjarjarno21 kB
+
+ + + + diff --git a/doc/samples/multi-project/build.xml b/doc/samples/multi-project/build.xml index e9cdf552..9d549877 100644 --- a/doc/samples/multi-project/build.xml +++ b/doc/samples/multi-project/build.xml @@ -1,47 +1,47 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/samples/multi-project/common.xml b/doc/samples/multi-project/common.xml index 2745b8d3..7ab6cfb5 100644 --- a/doc/samples/multi-project/common.xml +++ b/doc/samples/multi-project/common.xml @@ -1,183 +1,183 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/test/ivyconf-include-http-url.xml b/doc/test/ivyconf-include-http-url.xml index 35a03461..2f2e1c3e 100644 --- a/doc/test/ivyconf-include-http-url.xml +++ b/doc/test/ivyconf-include-http-url.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/doc/test/ivyconf.xml b/doc/test/ivyconf.xml index 2e11cfaf..cc280cf7 100644 --- a/doc/test/ivyconf.xml +++ b/doc/test/ivyconf.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/doc/test/ivysettings-include-http-url.xml b/doc/test/ivysettings-include-http-url.xml index f74b8d6a..0544bd7c 100644 --- a/doc/test/ivysettings-include-http-url.xml +++ b/doc/test/ivysettings-include-http-url.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/doc/test/ivysettings.xml b/doc/test/ivysettings.xml index ae8e7354..df020cfe 100644 --- a/doc/test/ivysettings.xml +++ b/doc/test/ivysettings.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/doc/toc.json b/doc/toc.json index 7a27ea06..4653d6bb 100644 --- a/doc/toc.json +++ b/doc/toc.json @@ -999,4 +999,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/ivy.xml b/ivy.xml index 41f2ae4d..bc29eea8 100644 --- a/ivy.xml +++ b/ivy.xml @@ -1,49 +1,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ivysettings.xml b/ivysettings.xml index 2c7b47bf..7ba9b828 100644 --- a/ivysettings.xml +++ b/ivysettings.xml @@ -1,45 +1,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/optional.patterns b/optional.patterns index 384dbf1d..a4007f26 100644 --- a/optional.patterns +++ b/optional.patterns @@ -1,16 +1,16 @@ -#This file defines the sources to compile for ivy-optional.jar -org/apache/ivy/Main.java -org/apache/ivy/plugins/matcher/GlobPatternMatcher.java -org/apache/ivy/plugins/repository/sftp/**/*.java -org/apache/ivy/plugins/repository/ssh/**/*.java -org/apache/ivy/plugins/repository/vfs/**/*.java -org/apache/ivy/plugins/repository/vsftp/**/*.java -org/apache/ivy/plugins/resolver/AbstractSshBasedResolver.java -org/apache/ivy/plugins/resolver/SFTPResolver.java -org/apache/ivy/plugins/resolver/SshResolver.java -org/apache/ivy/plugins/resolver/VfsResolver.java -org/apache/ivy/plugins/resolver/VsftpResolver.java -org/apache/ivy/util/url/HttpClientHandler.java - -#This section defines the resources to copy for ivy-optional.jar -org/apache/ivy/plugins/repository/vfs/*.xml \ No newline at end of file +#This file defines the sources to compile for ivy-optional.jar +org/apache/ivy/Main.java +org/apache/ivy/plugins/matcher/GlobPatternMatcher.java +org/apache/ivy/plugins/repository/sftp/**/*.java +org/apache/ivy/plugins/repository/ssh/**/*.java +org/apache/ivy/plugins/repository/vfs/**/*.java +org/apache/ivy/plugins/repository/vsftp/**/*.java +org/apache/ivy/plugins/resolver/AbstractSshBasedResolver.java +org/apache/ivy/plugins/resolver/SFTPResolver.java +org/apache/ivy/plugins/resolver/SshResolver.java +org/apache/ivy/plugins/resolver/VfsResolver.java +org/apache/ivy/plugins/resolver/VsftpResolver.java +org/apache/ivy/util/url/HttpClientHandler.java + +#This section defines the resources to copy for ivy-optional.jar +org/apache/ivy/plugins/repository/vfs/*.xml diff --git a/src/etc/checkstyle/RequiredHeader.txt b/src/etc/checkstyle/RequiredHeader.txt index 753b46f3..6a5bb9a1 100644 --- a/src/etc/checkstyle/RequiredHeader.txt +++ b/src/etc/checkstyle/RequiredHeader.txt @@ -1,17 +1,17 @@ -/* - * 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. - * - */ +/* + * 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. + * + */ diff --git a/src/example/build-a-ivy-repository/build.xml b/src/example/build-a-ivy-repository/build.xml index 3a46746c..b959a4aa 100644 --- a/src/example/build-a-ivy-repository/build.xml +++ b/src/example/build-a-ivy-repository/build.xml @@ -1,104 +1,104 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/build-a-ivy-repository/config/ivy-maven1-ivysettings.xml b/src/example/build-a-ivy-repository/config/ivy-maven1-ivysettings.xml index 01452a75..f6de7495 100644 --- a/src/example/build-a-ivy-repository/config/ivy-maven1-ivysettings.xml +++ b/src/example/build-a-ivy-repository/config/ivy-maven1-ivysettings.xml @@ -1,124 +1,124 @@ - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + +- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/build-a-ivy-repository/config/ivy-maven2-ivysettings.xml b/src/example/build-a-ivy-repository/config/ivy-maven2-ivysettings.xml index a8925675..dfcce21d 100644 --- a/src/example/build-a-ivy-repository/config/ivy-maven2-ivysettings.xml +++ b/src/example/build-a-ivy-repository/config/ivy-maven2-ivysettings.xml @@ -1,142 +1,142 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/build-a-ivy-repository/config/ivysettings-advanced.xml b/src/example/build-a-ivy-repository/config/ivysettings-advanced.xml index 77b19dbf..796f5002 100644 --- a/src/example/build-a-ivy-repository/config/ivysettings-advanced.xml +++ b/src/example/build-a-ivy-repository/config/ivysettings-advanced.xml @@ -1,39 +1,39 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/build-a-ivy-repository/config/ivysettings-basic.xml b/src/example/build-a-ivy-repository/config/ivysettings-basic.xml index bf9d0306..b4cc2895 100644 --- a/src/example/build-a-ivy-repository/config/ivysettings-basic.xml +++ b/src/example/build-a-ivy-repository/config/ivysettings-basic.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/src/example/build-a-ivy-repository/config/ivysettings-maven1.xml b/src/example/build-a-ivy-repository/config/ivysettings-maven1.xml index 43f215fa..6e907f20 100644 --- a/src/example/build-a-ivy-repository/config/ivysettings-maven1.xml +++ b/src/example/build-a-ivy-repository/config/ivysettings-maven1.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/example/build-a-ivy-repository/config/ivysettings-maven2.xml b/src/example/build-a-ivy-repository/config/ivysettings-maven2.xml index b868384f..cadb976d 100644 --- a/src/example/build-a-ivy-repository/config/ivysettings-maven2.xml +++ b/src/example/build-a-ivy-repository/config/ivysettings-maven2.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/example/chained-resolvers/build.xml b/src/example/chained-resolvers/build.xml index 7ba57b61..51203cc5 100644 --- a/src/example/chained-resolvers/build.xml +++ b/src/example/chained-resolvers/build.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/example/chained-resolvers/chainedresolvers-project/build.xml b/src/example/chained-resolvers/chainedresolvers-project/build.xml index 22072868..6f74c8c7 100644 --- a/src/example/chained-resolvers/chainedresolvers-project/build.xml +++ b/src/example/chained-resolvers/chainedresolvers-project/build.xml @@ -1,81 +1,81 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/chained-resolvers/chainedresolvers-project/ivy.xml b/src/example/chained-resolvers/chainedresolvers-project/ivy.xml index ffadb242..303ea1b1 100644 --- a/src/example/chained-resolvers/chainedresolvers-project/ivy.xml +++ b/src/example/chained-resolvers/chainedresolvers-project/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/src/example/chained-resolvers/chainedresolvers-project/src/example/Hello.java b/src/example/chained-resolvers/chainedresolvers-project/src/example/Hello.java index c61e1aeb..c0822e74 100644 --- a/src/example/chained-resolvers/chainedresolvers-project/src/example/Hello.java +++ b/src/example/chained-resolvers/chainedresolvers-project/src/example/Hello.java @@ -1,32 +1,32 @@ -/* - * 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 example; - -import org.apache.commons.lang.WordUtils; - -/** - * Simple example world to show how easy it is to retreive libs with ivy !!! - */ -public class Hello { - public static void main(String[] args) { - String message = "example world !"; - System.out.println("standard message :" + message); - System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); - System.out.println("upperCased by " + test.StringUtils.class.getName() + " : " + test.StringUtils.upperCase(message)); - } -} +/* + * 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 example; + +import org.apache.commons.lang.WordUtils; + +/** + * Simple example world to show how easy it is to retreive libs with ivy !!! + */ +public class Hello { + public static void main(String[] args) { + String message = "example world !"; + System.out.println("standard message :" + message); + System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); + System.out.println("upperCased by " + test.StringUtils.class.getName() + " : " + test.StringUtils.upperCase(message)); + } +} diff --git a/src/example/chained-resolvers/config/ivysettings.xml b/src/example/chained-resolvers/config/ivysettings.xml index 40241a4a..c1205c77 100644 --- a/src/example/chained-resolvers/config/ivysettings.xml +++ b/src/example/chained-resolvers/config/ivysettings.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/example/configurations/jdbc-example/build.xml b/src/example/configurations/jdbc-example/build.xml index 657fb9ee..1ab12aef 100644 --- a/src/example/configurations/jdbc-example/build.xml +++ b/src/example/configurations/jdbc-example/build.xml @@ -1,97 +1,97 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/configurations/jdbc-example/ivy.xml b/src/example/configurations/jdbc-example/ivy.xml index aacd9872..14f0a105 100644 --- a/src/example/configurations/jdbc-example/ivy.xml +++ b/src/example/configurations/jdbc-example/ivy.xml @@ -1,44 +1,44 @@ - - - - - - This is an example project that aims to demonstrate the usage of the configuration in ivy. - This project provide 4 configurations. Each configurations describe the requirement to build or run the project - - - - - - - - - - - - - - - - - - - - + + + + + + This is an example project that aims to demonstrate the usage of the configuration in ivy. + This project provide 4 configurations. Each configurations describe the requirement to build or run the project + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/configurations/jdbc-example/src/dev.properties b/src/example/configurations/jdbc-example/src/dev.properties index 64b1e56c..ca2146a3 100644 --- a/src/example/configurations/jdbc-example/src/dev.properties +++ b/src/example/configurations/jdbc-example/src/dev.properties @@ -1,19 +1,19 @@ -# *************************************************************** -# * 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. -# *************************************************************** -driver.class=com.mckoi.JDBCDriver \ No newline at end of file +# *************************************************************** +# * 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. +# *************************************************************** +driver.class=com.mckoi.JDBCDriver diff --git a/src/example/configurations/jdbc-example/src/example/ConfigurationsExample.java b/src/example/configurations/jdbc-example/src/example/ConfigurationsExample.java index 18f03fc9..dc2b304f 100644 --- a/src/example/configurations/jdbc-example/src/example/ConfigurationsExample.java +++ b/src/example/configurations/jdbc-example/src/example/ConfigurationsExample.java @@ -1,61 +1,61 @@ -/* - * 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 example; - -import java.io.IOException; -import java.util.Properties; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.cli.PosixParser; - -public class ConfigurationsExample { - - public static void main(String[] args) { - String jdbcPropToLoad = "prod.properties"; - CommandLineParser parser = new PosixParser(); - Options options = new Options(); - options.addOption("d", "dev", false, "Dev tag to launch app in dev mode. Means that app will launch embedded mckoi db."); - try { - CommandLine line = parser.parse( options, args ); - if(line.hasOption("d")) { - System.err.println("App is in DEV mode"); - jdbcPropToLoad = "dev.properties"; - } - } - catch( ParseException exp ) { - System.err.println( "Parsing failed. Reason: " + exp.getMessage() ); - } - Properties p = new Properties(); - try { - p.load(ConfigurationsExample.class.getResourceAsStream("/"+jdbcPropToLoad)); - } catch (IOException e) { - System.err.println( "Properties loading failed. Reason: " + e.getMessage()); - } - try { - String clazz = p.getProperty("driver.class"); - Class.forName(clazz); - System.out.println(" Jdbc driver loaded :"+clazz); - } catch (ClassNotFoundException e) { - System.err.println( "Jdbc Driver class loading failed. Reason: " + e.getMessage()); - e.printStackTrace(); - } - - } -} +/* + * 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 example; + +import java.io.IOException; +import java.util.Properties; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.cli.PosixParser; + +public class ConfigurationsExample { + + public static void main(String[] args) { + String jdbcPropToLoad = "prod.properties"; + CommandLineParser parser = new PosixParser(); + Options options = new Options(); + options.addOption("d", "dev", false, "Dev tag to launch app in dev mode. Means that app will launch embedded mckoi db."); + try { + CommandLine line = parser.parse( options, args ); + if(line.hasOption("d")) { + System.err.println("App is in DEV mode"); + jdbcPropToLoad = "dev.properties"; + } + } + catch( ParseException exp ) { + System.err.println( "Parsing failed. Reason: " + exp.getMessage() ); + } + Properties p = new Properties(); + try { + p.load(ConfigurationsExample.class.getResourceAsStream("/"+jdbcPropToLoad)); + } catch (IOException e) { + System.err.println( "Properties loading failed. Reason: " + e.getMessage()); + } + try { + String clazz = p.getProperty("driver.class"); + Class.forName(clazz); + System.out.println(" Jdbc driver loaded :"+clazz); + } catch (ClassNotFoundException e) { + System.err.println( "Jdbc Driver class loading failed. Reason: " + e.getMessage()); + e.printStackTrace(); + } + + } +} diff --git a/src/example/configurations/jdbc-example/src/prod.properties b/src/example/configurations/jdbc-example/src/prod.properties index 564c9f97..48c25ee5 100644 --- a/src/example/configurations/jdbc-example/src/prod.properties +++ b/src/example/configurations/jdbc-example/src/prod.properties @@ -1,19 +1,19 @@ -# *************************************************************** -# * 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. -# *************************************************************** -driver.class=org.gjt.mm.mysql.Driver \ No newline at end of file +# *************************************************************** +# * 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. +# *************************************************************** +driver.class=org.gjt.mm.mysql.Driver diff --git a/src/example/configurations/multi-projects/filter-framework/build.xml b/src/example/configurations/multi-projects/filter-framework/build.xml index 966a2e49..a43297e8 100644 --- a/src/example/configurations/multi-projects/filter-framework/build.xml +++ b/src/example/configurations/multi-projects/filter-framework/build.xml @@ -1,130 +1,130 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/configurations/multi-projects/filter-framework/ivy.xml b/src/example/configurations/multi-projects/filter-framework/ivy.xml index 360c9d57..99d481e4 100644 --- a/src/example/configurations/multi-projects/filter-framework/ivy.xml +++ b/src/example/configurations/multi-projects/filter-framework/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/src/example/configurations/multi-projects/filter-framework/src/filter/FilterProvider.java b/src/example/configurations/multi-projects/filter-framework/src/filter/FilterProvider.java index 6679d330..7d2f8cd2 100644 --- a/src/example/configurations/multi-projects/filter-framework/src/filter/FilterProvider.java +++ b/src/example/configurations/multi-projects/filter-framework/src/filter/FilterProvider.java @@ -1,37 +1,37 @@ -/* - * 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 filter; - - -public class FilterProvider { - - public static IFilter getFilter() { - try { - Class clazz = Class.forName("filter.ccimpl.CCFilter"); - return (IFilter) clazz.newInstance(); - } catch (Exception e) { - try { - Class clazz = Class.forName("filter.hmimpl.HMFilter"); - return (IFilter) clazz.newInstance(); - } catch (Exception e1) { - System.err.println("No filter implementation found in classpath !"); - } - return null; - } - } -} +/* + * 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 filter; + + +public class FilterProvider { + + public static IFilter getFilter() { + try { + Class clazz = Class.forName("filter.ccimpl.CCFilter"); + return (IFilter) clazz.newInstance(); + } catch (Exception e) { + try { + Class clazz = Class.forName("filter.hmimpl.HMFilter"); + return (IFilter) clazz.newInstance(); + } catch (Exception e1) { + System.err.println("No filter implementation found in classpath !"); + } + return null; + } + } +} diff --git a/src/example/configurations/multi-projects/filter-framework/src/filter/IFilter.java b/src/example/configurations/multi-projects/filter-framework/src/filter/IFilter.java index 848adb2e..7c5590ee 100644 --- a/src/example/configurations/multi-projects/filter-framework/src/filter/IFilter.java +++ b/src/example/configurations/multi-projects/filter-framework/src/filter/IFilter.java @@ -1,22 +1,22 @@ -/* - * 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 filter; - -public interface IFilter { - String[] filter(String[] values, String prefix); -} +/* + * 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 filter; + +public interface IFilter { + String[] filter(String[] values, String prefix); +} diff --git a/src/example/configurations/multi-projects/filter-framework/src/filter/ccimpl/CCFilter.java b/src/example/configurations/multi-projects/filter-framework/src/filter/ccimpl/CCFilter.java index 23a8f11b..0c890716 100644 --- a/src/example/configurations/multi-projects/filter-framework/src/filter/ccimpl/CCFilter.java +++ b/src/example/configurations/multi-projects/filter-framework/src/filter/ccimpl/CCFilter.java @@ -1,45 +1,45 @@ -/* - * 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 filter.ccimpl; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.Predicate; -import filter.IFilter; - -public class CCFilter implements IFilter { - - public String[] filter(String[] values, final String prefix) { - if(values == null) { - return null; - } - if(prefix == null) { - return values; - } - - List result = new ArrayList(Arrays.asList(values)); - CollectionUtils.filter(result, new Predicate() { - public boolean evaluate(Object o) { - return o!= null && o.toString().startsWith(prefix); - } - }); - return (String[]) result.toArray(new String[result.size()]); - } -} +/* + * 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 filter.ccimpl; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; +import filter.IFilter; + +public class CCFilter implements IFilter { + + public String[] filter(String[] values, final String prefix) { + if(values == null) { + return null; + } + if(prefix == null) { + return values; + } + + List result = new ArrayList(Arrays.asList(values)); + CollectionUtils.filter(result, new Predicate() { + public boolean evaluate(Object o) { + return o!= null && o.toString().startsWith(prefix); + } + }); + return (String[]) result.toArray(new String[result.size()]); + } +} diff --git a/src/example/configurations/multi-projects/filter-framework/src/filter/hmimpl/HMFilter.java b/src/example/configurations/multi-projects/filter-framework/src/filter/hmimpl/HMFilter.java index 94997e0d..3a5de039 100644 --- a/src/example/configurations/multi-projects/filter-framework/src/filter/hmimpl/HMFilter.java +++ b/src/example/configurations/multi-projects/filter-framework/src/filter/hmimpl/HMFilter.java @@ -1,42 +1,42 @@ -/* - * 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 filter.hmimpl; - -import java.util.ArrayList; -import java.util.List; -import filter.IFilter; - -public class HMFilter implements IFilter { - - public String[] filter(String[] values, String prefix) { - if(values == null) { - return null; - } - if(prefix == null) { - return values; - } - List result = new ArrayList(); - for (int i = 0; i < values.length; i++) { - String string = values[i]; - if(string != null && string.startsWith(prefix)) { - result.add(string); - } - } - return (String[]) result.toArray(new String[result.size()]); - } -} +/* + * 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 filter.hmimpl; + +import java.util.ArrayList; +import java.util.List; +import filter.IFilter; + +public class HMFilter implements IFilter { + + public String[] filter(String[] values, String prefix) { + if(values == null) { + return null; + } + if(prefix == null) { + return values; + } + List result = new ArrayList(); + for (int i = 0; i < values.length; i++) { + String string = values[i]; + if(string != null && string.startsWith(prefix)) { + result.add(string); + } + } + return (String[]) result.toArray(new String[result.size()]); + } +} diff --git a/src/example/configurations/multi-projects/filter-framework/test/filter/AbstractTestFilter.java b/src/example/configurations/multi-projects/filter-framework/test/filter/AbstractTestFilter.java index 1a53877b..f9fdb741 100644 --- a/src/example/configurations/multi-projects/filter-framework/test/filter/AbstractTestFilter.java +++ b/src/example/configurations/multi-projects/filter-framework/test/filter/AbstractTestFilter.java @@ -1,70 +1,70 @@ -/* - * 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 filter; - -import junit.framework.TestCase; - -public abstract class AbstractTestFilter extends TestCase { - - public void testFilterNull() { - Exception err = null; - try { - getIFilter().filter(null, null); - } catch (NullPointerException npe) { - err = npe; - } - assertNull(err); - } - - /** - * @return - */ - public abstract IFilter getIFilter() ; - - public void testFilterNullValues() { - Exception err = null; - try { - getIFilter().filter(null, "test"); - } catch (NullPointerException npe) { - err = npe; - } - assertNull(err); - } - - public void testFilterNullPrefix() { - Exception err = null; - try { - getIFilter().filter(new String[]{"test"}, null); - } catch (NullPointerException npe) { - err = npe; - } - assertNull(err); - } - - public void testFilter() { - String[] result = getIFilter().filter(new String[]{"test", "nogood", "mustbe filtered"}, "t"); - assertNotNull(result); - assertEquals(result.length, 1); - } - - public void testFilterWithNullValues() { - String[] result = getIFilter().filter(new String[]{"test", null, "mustbe filtered"}, "t"); - assertNotNull(result); - assertEquals(result.length, 1); - } -} +/* + * 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 filter; + +import junit.framework.TestCase; + +public abstract class AbstractTestFilter extends TestCase { + + public void testFilterNull() { + Exception err = null; + try { + getIFilter().filter(null, null); + } catch (NullPointerException npe) { + err = npe; + } + assertNull(err); + } + + /** + * @return + */ + public abstract IFilter getIFilter() ; + + public void testFilterNullValues() { + Exception err = null; + try { + getIFilter().filter(null, "test"); + } catch (NullPointerException npe) { + err = npe; + } + assertNull(err); + } + + public void testFilterNullPrefix() { + Exception err = null; + try { + getIFilter().filter(new String[]{"test"}, null); + } catch (NullPointerException npe) { + err = npe; + } + assertNull(err); + } + + public void testFilter() { + String[] result = getIFilter().filter(new String[]{"test", "nogood", "mustbe filtered"}, "t"); + assertNotNull(result); + assertEquals(result.length, 1); + } + + public void testFilterWithNullValues() { + String[] result = getIFilter().filter(new String[]{"test", null, "mustbe filtered"}, "t"); + assertNotNull(result); + assertEquals(result.length, 1); + } +} diff --git a/src/example/configurations/multi-projects/filter-framework/test/filter/ccimpl/CCFilterTest.java b/src/example/configurations/multi-projects/filter-framework/test/filter/ccimpl/CCFilterTest.java index 77e97140..bde00f40 100644 --- a/src/example/configurations/multi-projects/filter-framework/test/filter/ccimpl/CCFilterTest.java +++ b/src/example/configurations/multi-projects/filter-framework/test/filter/ccimpl/CCFilterTest.java @@ -1,27 +1,27 @@ -/* - * 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 filter.ccimpl; - -import filter.AbstractTestFilter; -import filter.IFilter; - -public class CCFilterTest extends AbstractTestFilter { - public IFilter getIFilter() { - return new CCFilter(); - } -} +/* + * 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 filter.ccimpl; + +import filter.AbstractTestFilter; +import filter.IFilter; + +public class CCFilterTest extends AbstractTestFilter { + public IFilter getIFilter() { + return new CCFilter(); + } +} diff --git a/src/example/configurations/multi-projects/filter-framework/test/filter/hmimpl/HMFilterTest.java b/src/example/configurations/multi-projects/filter-framework/test/filter/hmimpl/HMFilterTest.java index d55913b8..40fa914a 100644 --- a/src/example/configurations/multi-projects/filter-framework/test/filter/hmimpl/HMFilterTest.java +++ b/src/example/configurations/multi-projects/filter-framework/test/filter/hmimpl/HMFilterTest.java @@ -1,27 +1,27 @@ -/* - * 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 filter.hmimpl; - -import filter.AbstractTestFilter; -import filter.IFilter; - -public class HMFilterTest extends AbstractTestFilter { - public IFilter getIFilter() { - return new HMFilter(); - } -} +/* + * 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 filter.hmimpl; + +import filter.AbstractTestFilter; +import filter.IFilter; + +public class HMFilterTest extends AbstractTestFilter { + public IFilter getIFilter() { + return new HMFilter(); + } +} diff --git a/src/example/configurations/multi-projects/myapp/build.xml b/src/example/configurations/multi-projects/myapp/build.xml index e199e5c0..7dc8726f 100644 --- a/src/example/configurations/multi-projects/myapp/build.xml +++ b/src/example/configurations/multi-projects/myapp/build.xml @@ -1,93 +1,93 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/configurations/multi-projects/myapp/ivy.xml b/src/example/configurations/multi-projects/myapp/ivy.xml index bdcf8b5d..25a6893d 100644 --- a/src/example/configurations/multi-projects/myapp/ivy.xml +++ b/src/example/configurations/multi-projects/myapp/ivy.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/example/configurations/multi-projects/myapp/src/myapp/Main.java b/src/example/configurations/multi-projects/myapp/src/myapp/Main.java index 945ff651..2305875a 100644 --- a/src/example/configurations/multi-projects/myapp/src/myapp/Main.java +++ b/src/example/configurations/multi-projects/myapp/src/myapp/Main.java @@ -1,33 +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. - * - */ -package myapp; - -import java.util.Arrays; -import filter.FilterProvider; -import filter.IFilter; - -public class Main { - - public static void main(String[] args) { - String toFilter[] = new String[]{"one", "two", "tree", "four"}; - IFilter filter = FilterProvider.getFilter(); - System.out.println("Filtering with:"+filter.getClass()); - String filtered[] = filter.filter(toFilter, "t"); - System.out.println("Result :"+Arrays.asList(filtered)); - } -} +/* + * 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 myapp; + +import java.util.Arrays; +import filter.FilterProvider; +import filter.IFilter; + +public class Main { + + public static void main(String[] args) { + String toFilter[] = new String[]{"one", "two", "tree", "four"}; + IFilter filter = FilterProvider.getFilter(); + System.out.println("Filtering with:"+filter.getClass()); + String filtered[] = filter.filter(toFilter, "t"); + System.out.println("Result :"+Arrays.asList(filtered)); + } +} diff --git a/src/example/dependence/build.xml b/src/example/dependence/build.xml index aad97e82..4dd96279 100644 --- a/src/example/dependence/build.xml +++ b/src/example/dependence/build.xml @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/dependence/config/ivysettings.properties b/src/example/dependence/config/ivysettings.properties index b153a284..f68f4157 100644 --- a/src/example/dependence/config/ivysettings.properties +++ b/src/example/dependence/config/ivysettings.properties @@ -1,19 +1,19 @@ -# *************************************************************** -# * 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. -# *************************************************************** -repository.dir=${ivy.settings.dir}/repository +# *************************************************************** +# * 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. +# *************************************************************** +repository.dir=${ivy.settings.dir}/repository diff --git a/src/example/dependence/config/ivysettings.xml b/src/example/dependence/config/ivysettings.xml index 65f57577..527c1ce3 100644 --- a/src/example/dependence/config/ivysettings.xml +++ b/src/example/dependence/config/ivysettings.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/example/dependence/depending/build.xml b/src/example/dependence/depending/build.xml index 7d019e00..986575f3 100644 --- a/src/example/dependence/depending/build.xml +++ b/src/example/dependence/depending/build.xml @@ -1,93 +1,93 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/dependence/depending/ivy.xml b/src/example/dependence/depending/ivy.xml index 76ab8452..bde7a3b4 100644 --- a/src/example/dependence/depending/ivy.xml +++ b/src/example/dependence/depending/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/src/example/dependence/depending/src/depending/Main.java b/src/example/dependence/depending/src/depending/Main.java index 19a91e4c..5346a2f3 100644 --- a/src/example/dependence/depending/src/depending/Main.java +++ b/src/example/dependence/depending/src/depending/Main.java @@ -1,35 +1,35 @@ -/* - * 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 depending; - -/** - * TODO write javadoc - */ -public class Main { - public static void main(String[] args) { - String standaloneVersion = standalone.Main.getVersion(); - if (standaloneVersion!=null) { - System.out.println("you are using version " + standaloneVersion + " of class " + standalone.Main.class.getName()); - } else { - System.err.println("failed to get version of " + standalone.Main.class.getName()); - } - String message = "i am " + Main.class.getName() + " and " + standalone.Main.class.getName() + " will do the job for me"; - System.out.println("standard message : " + message); - System.out.println("capitalized message : " + standalone.Main.capitalizeWords(message)); - } -} +/* + * 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 depending; + +/** + * TODO write javadoc + */ +public class Main { + public static void main(String[] args) { + String standaloneVersion = standalone.Main.getVersion(); + if (standaloneVersion!=null) { + System.out.println("you are using version " + standaloneVersion + " of class " + standalone.Main.class.getName()); + } else { + System.err.println("failed to get version of " + standalone.Main.class.getName()); + } + String message = "i am " + Main.class.getName() + " and " + standalone.Main.class.getName() + " will do the job for me"; + System.out.println("standard message : " + message); + System.out.println("capitalized message : " + standalone.Main.capitalizeWords(message)); + } +} diff --git a/src/example/dependence/standalone/build.xml b/src/example/dependence/standalone/build.xml index 3819cd62..08c35dea 100644 --- a/src/example/dependence/standalone/build.xml +++ b/src/example/dependence/standalone/build.xml @@ -1,110 +1,110 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/dependence/standalone/ivy.xml b/src/example/dependence/standalone/ivy.xml index 26c2bb0e..16308046 100644 --- a/src/example/dependence/standalone/ivy.xml +++ b/src/example/dependence/standalone/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/src/example/dependence/standalone/src/standalone/Main.java b/src/example/dependence/standalone/src/standalone/Main.java index 22e3eeb5..2ce2d054 100644 --- a/src/example/dependence/standalone/src/standalone/Main.java +++ b/src/example/dependence/standalone/src/standalone/Main.java @@ -1,60 +1,60 @@ -/* - * 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 standalone; - -import java.util.Properties; - -import org.apache.commons.lang.WordUtils; - -/** - * TODO write javadoc - */ -public class Main { - /** - * Returns the version of the project - * @return a string representation of the version, null if the version could not be retreived - */ - public static String getVersion() { - Properties p = new Properties(); - try { - p.load(Main.class.getResourceAsStream("/version.properties")); - String version = p.getProperty("version"); - if (version != null) { - return String.valueOf(Integer.parseInt(version)); - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - /** - * Return the same string with all words capitalized. - * @param str the string conatining the words to capitalize - * @return null if the string was null, the string with all words capitalized otherwise - */ - public static String capitalizeWords(String str) { - System.out.println(" [" + Main.class.getName() + "] capitalizing string \"" + str + "\" using " + WordUtils.class.getName()); - return WordUtils.capitalizeFully(str); - } - public static void main(String[] args) { - String message="sentence to capitalize"; - System.out.println("standard message : " + message); - System.out.println("capitalized message : " + capitalizeWords(message)); - } -} +/* + * 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 standalone; + +import java.util.Properties; + +import org.apache.commons.lang.WordUtils; + +/** + * TODO write javadoc + */ +public class Main { + /** + * Returns the version of the project + * @return a string representation of the version, null if the version could not be retreived + */ + public static String getVersion() { + Properties p = new Properties(); + try { + p.load(Main.class.getResourceAsStream("/version.properties")); + String version = p.getProperty("version"); + if (version != null) { + return String.valueOf(Integer.parseInt(version)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * Return the same string with all words capitalized. + * @param str the string conatining the words to capitalize + * @return null if the string was null, the string with all words capitalized otherwise + */ + public static String capitalizeWords(String str) { + System.out.println(" [" + Main.class.getName() + "] capitalizing string \"" + str + "\" using " + WordUtils.class.getName()); + return WordUtils.capitalizeFully(str); + } + public static void main(String[] args) { + String message="sentence to capitalize"; + System.out.println("standard message : " + message); + System.out.println("capitalized message : " + capitalizeWords(message)); + } +} diff --git a/src/example/dual/build.xml b/src/example/dual/build.xml index b3ddd64c..5c675c24 100644 --- a/src/example/dual/build.xml +++ b/src/example/dual/build.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/example/dual/config/ivysettings.xml b/src/example/dual/config/ivysettings.xml index e9333810..00b93be2 100644 --- a/src/example/dual/config/ivysettings.xml +++ b/src/example/dual/config/ivysettings.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/example/dual/project/build.xml b/src/example/dual/project/build.xml index 0287b50d..fc146ce8 100644 --- a/src/example/dual/project/build.xml +++ b/src/example/dual/project/build.xml @@ -1,81 +1,81 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/dual/project/ivy.xml b/src/example/dual/project/ivy.xml index a9f2041f..95bc0c24 100644 --- a/src/example/dual/project/ivy.xml +++ b/src/example/dual/project/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/src/example/dual/project/src/example/Hello.java b/src/example/dual/project/src/example/Hello.java index 1c35229b..a45c0de6 100644 --- a/src/example/dual/project/src/example/Hello.java +++ b/src/example/dual/project/src/example/Hello.java @@ -1,49 +1,49 @@ -/* - * 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 example; - -import java.io.IOException; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.commons.lang.WordUtils; - -/** - * Simple hello world example to show how easy it is to retrieve libs with ivy, - * including transitive dependencies - */ -public class Hello { - public static void main(String[] args) throws Exception { - String message = "hello ivy !"; - System.out.println("standard message : " + message); - System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); - - HttpClient client = new HttpClient(); - HeadMethod head = new HeadMethod("http://www.ibiblio.org/"); - client.executeMethod(head); - - int status = head.getStatusCode(); - System.out.println("head status code with httpclient: "+status); - head.releaseConnection(); - - System.out.println("now check if httpclient dependency on commons-logging has been realized"); - Class clss = Class.forName("org.apache.commons.logging.Log"); - System.out.println("found logging class in classpath: "+clss); - } -} +/* + * 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 example; + +import java.io.IOException; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.commons.lang.WordUtils; + +/** + * Simple hello world example to show how easy it is to retrieve libs with ivy, + * including transitive dependencies + */ +public class Hello { + public static void main(String[] args) throws Exception { + String message = "hello ivy !"; + System.out.println("standard message : " + message); + System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); + + HttpClient client = new HttpClient(); + HeadMethod head = new HeadMethod("http://www.ibiblio.org/"); + client.executeMethod(head); + + int status = head.getStatusCode(); + System.out.println("head status code with httpclient: "+status); + head.releaseConnection(); + + System.out.println("now check if httpclient dependency on commons-logging has been realized"); + Class clss = Class.forName("org.apache.commons.logging.Log"); + System.out.println("found logging class in classpath: "+clss); + } +} diff --git a/src/example/dual/repository/commons-httpclient-ivy-2.0.2.xml b/src/example/dual/repository/commons-httpclient-ivy-2.0.2.xml index 17239ceb..4fcb29d4 100644 --- a/src/example/dual/repository/commons-httpclient-ivy-2.0.2.xml +++ b/src/example/dual/repository/commons-httpclient-ivy-2.0.2.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/src/example/go-ivy/build.xml b/src/example/go-ivy/build.xml index 9e5b4dda..3638218c 100644 --- a/src/example/go-ivy/build.xml +++ b/src/example/go-ivy/build.xml @@ -1,148 +1,148 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -We are now ready to execute our simple program with its dependency on commons-lang. -Let's go! - - - - - - - - - - - - - -package example; - -import org.apache.commons.lang.WordUtils; - -public class Hello { - public static void main(String[] args) { - String message = "hello ivy !"; - System.out.println("standard message : " + message); - System.out.println("capitalized by " + WordUtils.class.getName() - + " : " + WordUtils.capitalizeFully(message)); - } -} - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +We are now ready to execute our simple program with its dependency on commons-lang. +Let's go! + + + + + + + + + + + + + +package example; + +import org.apache.commons.lang.WordUtils; + +public class Hello { + public static void main(String[] args) { + String message = "hello ivy !"; + System.out.println("standard message : " + message); + System.out.println("capitalized by " + WordUtils.class.getName() + + " : " + WordUtils.capitalizeFully(message)); + } +} + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/hello-ivy/build.xml b/src/example/hello-ivy/build.xml index d392ca5b..503a2e7d 100644 --- a/src/example/hello-ivy/build.xml +++ b/src/example/hello-ivy/build.xml @@ -1,76 +1,76 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/hello-ivy/ivy.xml b/src/example/hello-ivy/ivy.xml index f5831652..9bceb7e2 100644 --- a/src/example/hello-ivy/ivy.xml +++ b/src/example/hello-ivy/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/src/example/hello-ivy/src/example/Hello.java b/src/example/hello-ivy/src/example/Hello.java index 6bfde8bf..a27aeec8 100644 --- a/src/example/hello-ivy/src/example/Hello.java +++ b/src/example/hello-ivy/src/example/Hello.java @@ -1,31 +1,31 @@ -/* - * 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 example; - -import org.apache.commons.lang.WordUtils; - -/** - * Simple example world to show how easy it is to retreive libs with ivy !!! - */ -public class Hello { - public static void main(String[] args) { - String message = "hello ivy !"; - System.out.println("standard message : " + message); - System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); - } -} +/* + * 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 example; + +import org.apache.commons.lang.WordUtils; + +/** + * Simple example world to show how easy it is to retreive libs with ivy !!! + */ +public class Hello { + public static void main(String[] args) { + String message = "hello ivy !"; + System.out.println("standard message : " + message); + System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); + } +} diff --git a/src/example/ivyrep/build.xml b/src/example/ivyrep/build.xml index 93840c43..19f1f2dc 100644 --- a/src/example/ivyrep/build.xml +++ b/src/example/ivyrep/build.xml @@ -1,80 +1,80 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/ivyrep/ivy.xml b/src/example/ivyrep/ivy.xml index c31c0722..3eb5296f 100644 --- a/src/example/ivyrep/ivy.xml +++ b/src/example/ivyrep/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/src/example/ivyrep/src/example/Hello.java b/src/example/ivyrep/src/example/Hello.java index d1809daa..d9abc9ad 100644 --- a/src/example/ivyrep/src/example/Hello.java +++ b/src/example/ivyrep/src/example/Hello.java @@ -1,47 +1,47 @@ -/* - * 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 example; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; -import org.apache.commons.lang.WordUtils; - -/** - * Simple example to show how easy it is to retrieve transitive libs with ivy !!! - */ -public class Hello { - public static void main(String[] args) throws Exception { - Option msg = OptionBuilder.withArgName( "msg" ) - .hasArg() - .withDescription( "the message to capitalize" ) - .create( "message" ); - Options options = new Options(); - options.addOption(msg); - - CommandLineParser parser = new GnuParser(); - CommandLine line = parser.parse( options, args ); - - String message = line.getOptionValue("message", "hello ivy !"); - System.out.println("standard message : " + message); - System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); - } -} +/* + * 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 example; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.lang.WordUtils; + +/** + * Simple example to show how easy it is to retrieve transitive libs with ivy !!! + */ +public class Hello { + public static void main(String[] args) throws Exception { + Option msg = OptionBuilder.withArgName( "msg" ) + .hasArg() + .withDescription( "the message to capitalize" ) + .create( "message" ); + Options options = new Options(); + options.addOption(msg); + + CommandLineParser parser = new GnuParser(); + CommandLine line = parser.parse( options, args ); + + String message = line.getOptionValue("message", "hello ivy !"); + System.out.println("standard message : " + message); + System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message)); + } +} diff --git a/src/example/multi-project/build.xml b/src/example/multi-project/build.xml index 71b8235d..85062bf7 100644 --- a/src/example/multi-project/build.xml +++ b/src/example/multi-project/build.xml @@ -1,73 +1,73 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/multi-project/common/build.properties b/src/example/multi-project/common/build.properties index fd6eacf1..d1431a24 100644 --- a/src/example/multi-project/common/build.properties +++ b/src/example/multi-project/common/build.properties @@ -1,27 +1,27 @@ -# *************************************************************** -# * 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 - - -jar.file = ${build.dir}/${ant.project.name}.jar -main.class.name = ${ant.project.name}.Main +# *************************************************************** +# * 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 + + +jar.file = ${build.dir}/${ant.project.name}.jar +main.class.name = ${ant.project.name}.Main diff --git a/src/example/multi-project/common/common.xml b/src/example/multi-project/common/common.xml index 8e8933e8..db26576c 100644 --- a/src/example/multi-project/common/common.xml +++ b/src/example/multi-project/common/common.xml @@ -1,182 +1,182 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example/multi-project/projects/console/build.properties b/src/example/multi-project/projects/console/build.properties index f8ccc6bf..1b549258 100644 --- a/src/example/multi-project/projects/console/build.properties +++ b/src/example/multi-project/projects/console/build.properties @@ -1,21 +1,21 @@ -# *************************************************************** -# * 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. -# *************************************************************** -projects.dir = ${basedir}/.. -wkspace.dir = ${projects.dir}/.. -common.dir = ${wkspace.dir}/common +# *************************************************************** +# * 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. +# *************************************************************** +projects.dir = ${basedir}/.. +wkspace.dir = ${projects.dir}/.. +common.dir = ${wkspace.dir}/common diff --git a/src/example/multi-project/projects/console/build.xml b/src/example/multi-project/projects/console/build.xml index 820476ea..fa7d93ca 100644 --- a/src/example/multi-project/projects/console/build.xml +++ b/src/example/multi-project/projects/console/build.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/src/example/multi-project/projects/console/ivy.xml b/src/example/multi-project/projects/console/ivy.xml index 7e66f8c9..088fc668 100644 --- a/src/example/multi-project/projects/console/ivy.xml +++ b/src/example/multi-project/projects/console/ivy.xml @@ -1,30 +1,30 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/src/example/multi-project/projects/console/src/console/Main.java b/src/example/multi-project/projects/console/src/console/Main.java index 1b837d0e..49988794 100644 --- a/src/example/multi-project/projects/console/src/console/Main.java +++ b/src/example/multi-project/projects/console/src/console/Main.java @@ -1,77 +1,77 @@ -/* - * 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 console; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.Collection; -import java.util.Arrays; -import java.lang.reflect.Method; - - -public class Main { - private static Collection QUIT_COMMANDS = Arrays.asList(new String[] {"quit", "q", "exit"}); - private static Collection HELP_COMMANDS = Arrays.asList(new String[] {"help", "h", "?"}); - - public static void main(String[] a) throws Exception { - BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); - while (true) { - System.out.print("> "); - String command = in.readLine().trim(); - if (QUIT_COMMANDS.contains(command)) { - return; - } - if (HELP_COMMANDS.contains(command)) { - help(); - continue; - } - String[] split = command.split(" "); - if (split.length == 0) { - error(command); - continue; - } - - try { - String[] args = new String[split.length - 1]; - System.arraycopy(split, 1, args, 0, args.length); - Class cl = Class.forName(split[0]+".Main"); - Method m = cl.getMethod("main", new Class[] {String[].class}); - m.invoke(null, new Object[] {args}); - } catch (Exception ex) { - error(command); - continue; - } - } - } - - private static void help() { - System.out.println("available commands:"); - System.out.println("\tquit: quit the console"); - System.out.println("\thelp: displays this message"); - System.out.println("\tlist -dir : list files in given directory"); - System.out.println("\tfind -dir -name : list files with given name in given dir"); - System.out.println("\tsizewhere -dir -name : compute total size of files with given name in given dir"); - System.out.println("\thelp: displays this message"); - } - - private static void error(String command) { - System.out.println("unknown command "+command); - System.out.println("type ? for help"); - } - -} +/* + * 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 console; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Collection; +import java.util.Arrays; +import java.lang.reflect.Method; + + +public class Main { + private static Collection QUIT_COMMANDS = Arrays.asList(new String[] {"quit", "q", "exit"}); + private static Collection HELP_COMMANDS = Arrays.asList(new String[] {"help", "h", "?"}); + + public static void main(String[] a) throws Exception { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + while (true) { + System.out.print("> "); + String command = in.readLine().trim(); + if (QUIT_COMMANDS.contains(command)) { + return; + } + if (HELP_COMMANDS.contains(command)) { + help(); + continue; + } + String[] split = command.split(" "); + if (split.length == 0) { + error(command); + continue; + } + + try { + String[] args = new String[split.length - 1]; + System.arraycopy(split, 1, args, 0, args.length); + Class cl = Class.forName(split[0]+".Main"); + Method m = cl.getMethod("main", new Class[] {String[].class}); + m.invoke(null, new Object[] {args}); + } catch (Exception ex) { + error(command); + continue; + } + } + } + + private static void help() { + System.out.println("available commands:"); + System.out.println("\tquit: quit the console"); + System.out.println("\thelp: displays this message"); + System.out.println("\tlist -dir : list files in given directory"); + System.out.println("\tfind -dir -name : list files with given name in given dir"); + System.out.println("\tsizewhere -dir -name : compute total size of files with given name in given dir"); + System.out.println("\thelp: displays this message"); + } + + private static void error(String command) { + System.out.println("unknown command "+command); + System.out.println("type ? for help"); + } + +} diff --git a/src/example/multi-project/projects/find/build.properties b/src/example/multi-project/projects/find/build.properties index f8ccc6bf..1b549258 100644 --- a/src/example/multi-project/projects/find/build.properties +++ b/src/example/multi-project/projects/find/build.properties @@ -1,21 +1,21 @@ -# *************************************************************** -# * 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. -# *************************************************************** -projects.dir = ${basedir}/.. -wkspace.dir = ${projects.dir}/.. -common.dir = ${wkspace.dir}/common +# *************************************************************** +# * 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. +# *************************************************************** +projects.dir = ${basedir}/.. +wkspace.dir = ${projects.dir}/.. +common.dir = ${wkspace.dir}/common diff --git a/src/example/multi-project/projects/find/build.xml b/src/example/multi-project/projects/find/build.xml index 289d0133..270e2cfe 100644 --- a/src/example/multi-project/projects/find/build.xml +++ b/src/example/multi-project/projects/find/build.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/src/example/multi-project/projects/find/ivy.xml b/src/example/multi-project/projects/find/ivy.xml index de236f95..3e4ff50e 100644 --- a/src/example/multi-project/projects/find/ivy.xml +++ b/src/example/multi-project/projects/find/ivy.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/src/example/multi-project/projects/find/src/find/FindFile.java b/src/example/multi-project/projects/find/src/find/FindFile.java index 9597586e..99930df5 100644 --- a/src/example/multi-project/projects/find/src/find/FindFile.java +++ b/src/example/multi-project/projects/find/src/find/FindFile.java @@ -1,46 +1,46 @@ -/* - * 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 find; - -import version.Version; -import list.ListFile; - -import java.util.Collection; -import java.util.ArrayList; -import java.io.File; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.Predicate; - -public class FindFile { - static { - Version.register("find"); - } - - public static Collection find(File dir, String name) { - return find(ListFile.list(dir), name); - } - - private static Collection find(Collection files, final String name) { - return CollectionUtils.select(files, new Predicate() { - public boolean evaluate(Object o) { - return ((File)o).getName().indexOf(name) != -1; - } - }); - } -} +/* + * 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 find; + +import version.Version; +import list.ListFile; + +import java.util.Collection; +import java.util.ArrayList; +import java.io.File; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; + +public class FindFile { + static { + Version.register("find"); + } + + public static Collection find(File dir, String name) { + return find(ListFile.list(dir), name); + } + + private static Collection find(Collection files, final String name) { + return CollectionUtils.select(files, new Predicate() { + public boolean evaluate(Object o) { + return ((File)o).getName().indexOf(name) != -1; + } + }); + } +} diff --git a/src/example/multi-project/projects/find/src/find/Main.java b/src/example/multi-project/projects/find/src/find/Main.java index b28e9d49..9c202de0 100644 --- a/src/example/multi-project/projects/find/src/find/Main.java +++ b/src/example/multi-project/projects/find/src/find/Main.java @@ -1,74 +1,74 @@ -/* - * 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 find; - -import java.io.File; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -public class Main { - private static Options getOptions() { - Option dir = OptionBuilder.withArgName( "dir" ) - .hasArg() - .withDescription( "list files in given dir" ) - .create( "dir" ); - Option name = OptionBuilder.withArgName( "name" ) - .hasArg() - .withDescription( "list files with given name" ) - .create( "name" ); - Options options = new Options(); - - options.addOption(dir); - options.addOption(name); - - return options; - } - - public static void main(String[] args) throws Exception { - Options options = getOptions(); - try { - - CommandLineParser parser = new GnuParser(); - - CommandLine line = parser.parse( options, args ); - File dir = new File(line.getOptionValue("dir", ".")); - String name = line.getOptionValue("name", "jar"); - Collection files = FindFile.find(dir, name); - System.out.println("listing files in "+dir+" containing "+name); - for (Iterator it = files.iterator(); it.hasNext(); ) { - System.out.println("\t"+it.next()+"\n"); - } - } catch( ParseException exp ) { - // oops, something went wrong - System.err.println( "Parsing failed. Reason: " + exp.getMessage() ); - - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp( "find", options ); - } - } - -} +/* + * 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 find; + +import java.io.File; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + +public class Main { + private static Options getOptions() { + Option dir = OptionBuilder.withArgName( "dir" ) + .hasArg() + .withDescription( "list files in given dir" ) + .create( "dir" ); + Option name = OptionBuilder.withArgName( "name" ) + .hasArg() + .withDescription( "list files with given name" ) + .create( "name" ); + Options options = new Options(); + + options.addOption(dir); + options.addOption(name); + + return options; + } + + public static void main(String[] args) throws Exception { + Options options = getOptions(); + try { + + CommandLineParser parser = new GnuParser(); + + CommandLine line = parser.parse( options, args ); + File dir = new File(line.getOptionValue("dir", ".")); + String name = line.getOptionValue("name", "jar"); + Collection files = FindFile.find(dir, name); + System.out.println("listing files in "+dir+" containing "+name); + for (Iterator it = files.iterator(); it.hasNext(); ) { + System.out.println("\t"+it.next()+"\n"); + } + } catch( ParseException exp ) { + // oops, something went wrong + System.err.println( "Parsing failed. Reason: " + exp.getMessage() ); + + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp( "find", options ); + } + } + +} diff --git a/src/example/multi-project/projects/list/build.properties b/src/example/multi-project/projects/list/build.properties index f8ccc6bf..1b549258 100644 --- a/src/example/multi-project/projects/list/build.properties +++ b/src/example/multi-project/projects/list/build.properties @@ -1,21 +1,21 @@ -# *************************************************************** -# * 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. -# *************************************************************** -projects.dir = ${basedir}/.. -wkspace.dir = ${projects.dir}/.. -common.dir = ${wkspace.dir}/common +# *************************************************************** +# * 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. +# *************************************************************** +projects.dir = ${basedir}/.. +wkspace.dir = ${projects.dir}/.. +common.dir = ${wkspace.dir}/common diff --git a/src/example/multi-project/projects/list/build.xml b/src/example/multi-project/projects/list/build.xml index 7efc8208..e86db1a7 100644 --- a/src/example/multi-project/projects/list/build.xml +++ b/src/example/multi-project/projects/list/build.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/src/example/multi-project/projects/list/ivy.xml b/src/example/multi-project/projects/list/ivy.xml index 20edbf65..908725bc 100644 --- a/src/example/multi-project/projects/list/ivy.xml +++ b/src/example/multi-project/projects/list/ivy.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/example/multi-project/projects/list/src/list/ListFile.java b/src/example/multi-project/projects/list/src/list/ListFile.java index 56c2e9c0..1951f851 100644 --- a/src/example/multi-project/projects/list/src/list/ListFile.java +++ b/src/example/multi-project/projects/list/src/list/ListFile.java @@ -1,47 +1,47 @@ -/* - * 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 list; - -import version.Version; -import java.util.Collection; -import java.util.ArrayList; -import java.io.File; - -public class ListFile { - static { - Version.register("list"); - } - - public static Collection list(File dir) { - Collection files = new ArrayList(); - - return list(dir, files); - } - - private static Collection list(File file, Collection files) { - if (file.isDirectory()) { - File[] f = file.listFiles(); - for (int i=0; i - - - - - + + + + + + diff --git a/src/example/multi-project/projects/size/ivy.xml b/src/example/multi-project/projects/size/ivy.xml index 78da8224..1fb863bf 100644 --- a/src/example/multi-project/projects/size/ivy.xml +++ b/src/example/multi-project/projects/size/ivy.xml @@ -1,28 +1,28 @@ - - - - - - - - + + + + + + + + diff --git a/src/example/multi-project/projects/size/src/size/FileSize.java b/src/example/multi-project/projects/size/src/size/FileSize.java index aa3b8186..b1ba05d9 100644 --- a/src/example/multi-project/projects/size/src/size/FileSize.java +++ b/src/example/multi-project/projects/size/src/size/FileSize.java @@ -1,42 +1,42 @@ -/* - * 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 size; - -import version.Version; -import java.util.Collection; -import java.util.Iterator; -import java.io.File; - -public class FileSize { - static { - Version.register("size"); - } - - public static long totalSize(File dir) { - return totalSize(list.ListFile.list(dir)); - } - - public static long totalSize(Collection files) { - long total = 0; - for (Iterator it = files.iterator(); it.hasNext(); ) { - File f = (File)it.next(); - total += f.length(); - } - return total; - } -} +/* + * 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 size; + +import version.Version; +import java.util.Collection; +import java.util.Iterator; +import java.io.File; + +public class FileSize { + static { + Version.register("size"); + } + + public static long totalSize(File dir) { + return totalSize(list.ListFile.list(dir)); + } + + public static long totalSize(Collection files) { + long total = 0; + for (Iterator it = files.iterator(); it.hasNext(); ) { + File f = (File)it.next(); + total += f.length(); + } + return total; + } +} diff --git a/src/example/multi-project/projects/sizewhere/build.properties b/src/example/multi-project/projects/sizewhere/build.properties index f8ccc6bf..1b549258 100644 --- a/src/example/multi-project/projects/sizewhere/build.properties +++ b/src/example/multi-project/projects/sizewhere/build.properties @@ -1,21 +1,21 @@ -# *************************************************************** -# * 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. -# *************************************************************** -projects.dir = ${basedir}/.. -wkspace.dir = ${projects.dir}/.. -common.dir = ${wkspace.dir}/common +# *************************************************************** +# * 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. +# *************************************************************** +projects.dir = ${basedir}/.. +wkspace.dir = ${projects.dir}/.. +common.dir = ${wkspace.dir}/common diff --git a/src/example/multi-project/projects/sizewhere/build.xml b/src/example/multi-project/projects/sizewhere/build.xml index 0aef064e..107d1ca0 100644 --- a/src/example/multi-project/projects/sizewhere/build.xml +++ b/src/example/multi-project/projects/sizewhere/build.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/src/example/multi-project/projects/sizewhere/ivy.xml b/src/example/multi-project/projects/sizewhere/ivy.xml index 029fb586..9a3996a5 100644 --- a/src/example/multi-project/projects/sizewhere/ivy.xml +++ b/src/example/multi-project/projects/sizewhere/ivy.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/src/example/multi-project/projects/sizewhere/src/sizewhere/Main.java b/src/example/multi-project/projects/sizewhere/src/sizewhere/Main.java index 3fbb734c..b97eb629 100644 --- a/src/example/multi-project/projects/sizewhere/src/sizewhere/Main.java +++ b/src/example/multi-project/projects/sizewhere/src/sizewhere/Main.java @@ -1,68 +1,68 @@ -/* - * 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 sizewhere; - -import java.io.File; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -public class Main { - private static Options getOptions() { - Option dir = OptionBuilder.withArgName( "dir" ) - .hasArg() - .withDescription( "give total size of files in given dir" ) - .create( "dir" ); - Option name = OptionBuilder.withArgName( "name" ) - .hasArg() - .withDescription( "give total size of files with given name" ) - .create( "name" ); - Options options = new Options(); - - options.addOption(dir); - options.addOption(name); - - return options; - } - - public static void main(String[] args) throws Exception { - Options options = getOptions(); - try { - - CommandLineParser parser = new GnuParser(); - - CommandLine line = parser.parse( options, args ); - File dir = new File(line.getOptionValue("dir", ".")); - String name = line.getOptionValue("name", "jar"); - System.out.println("total size of files in "+dir+" containing "+name+": "+SizeWhere.totalSize(dir, name)); - } catch( ParseException exp ) { - // oops, something went wrong - System.err.println( "Parsing failed. Reason: " + exp.getMessage() ); - - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp( "sizewhere", options ); - } - } - -} +/* + * 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 sizewhere; + +import java.io.File; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + +public class Main { + private static Options getOptions() { + Option dir = OptionBuilder.withArgName( "dir" ) + .hasArg() + .withDescription( "give total size of files in given dir" ) + .create( "dir" ); + Option name = OptionBuilder.withArgName( "name" ) + .hasArg() + .withDescription( "give total size of files with given name" ) + .create( "name" ); + Options options = new Options(); + + options.addOption(dir); + options.addOption(name); + + return options; + } + + public static void main(String[] args) throws Exception { + Options options = getOptions(); + try { + + CommandLineParser parser = new GnuParser(); + + CommandLine line = parser.parse( options, args ); + File dir = new File(line.getOptionValue("dir", ".")); + String name = line.getOptionValue("name", "jar"); + System.out.println("total size of files in "+dir+" containing "+name+": "+SizeWhere.totalSize(dir, name)); + } catch( ParseException exp ) { + // oops, something went wrong + System.err.println( "Parsing failed. Reason: " + exp.getMessage() ); + + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp( "sizewhere", options ); + } + } + +} diff --git a/src/example/multi-project/projects/sizewhere/src/sizewhere/SizeWhere.java b/src/example/multi-project/projects/sizewhere/src/sizewhere/SizeWhere.java index c53c389a..428d7fe3 100644 --- a/src/example/multi-project/projects/sizewhere/src/sizewhere/SizeWhere.java +++ b/src/example/multi-project/projects/sizewhere/src/sizewhere/SizeWhere.java @@ -1,36 +1,36 @@ -/* - * 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 sizewhere; - -import version.Version; -import size.FileSize; -import find.FindFile; - -import java.util.Collection; -import java.util.ArrayList; -import java.io.File; - -public class SizeWhere { - static { - Version.register("sizewhere"); - } - - public static long totalSize(File dir, String name) { - return FileSize.totalSize(FindFile.find(dir, name)); - } -} +/* + * 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 sizewhere; + +import version.Version; +import size.FileSize; +import find.FindFile; + +import java.util.Collection; +import java.util.ArrayList; +import java.io.File; + +public class SizeWhere { + static { + Version.register("sizewhere"); + } + + public static long totalSize(File dir, String name) { + return FileSize.totalSize(FindFile.find(dir, name)); + } +} diff --git a/src/example/multi-project/projects/version/build.properties b/src/example/multi-project/projects/version/build.properties index f8ccc6bf..1b549258 100644 --- a/src/example/multi-project/projects/version/build.properties +++ b/src/example/multi-project/projects/version/build.properties @@ -1,21 +1,21 @@ -# *************************************************************** -# * 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. -# *************************************************************** -projects.dir = ${basedir}/.. -wkspace.dir = ${projects.dir}/.. -common.dir = ${wkspace.dir}/common +# *************************************************************** +# * 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. +# *************************************************************** +projects.dir = ${basedir}/.. +wkspace.dir = ${projects.dir}/.. +common.dir = ${wkspace.dir}/common diff --git a/src/example/multi-project/projects/version/build.xml b/src/example/multi-project/projects/version/build.xml index 41850af2..5200004b 100644 --- a/src/example/multi-project/projects/version/build.xml +++ b/src/example/multi-project/projects/version/build.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/src/example/multi-project/projects/version/ivy.xml b/src/example/multi-project/projects/version/ivy.xml index dd082d36..e65a75d5 100644 --- a/src/example/multi-project/projects/version/ivy.xml +++ b/src/example/multi-project/projects/version/ivy.xml @@ -1,24 +1,24 @@ - - - - + + + + diff --git a/src/example/multi-project/projects/version/src/version/Version.java b/src/example/multi-project/projects/version/src/version/Version.java index 196bc45a..c561146b 100644 --- a/src/example/multi-project/projects/version/src/version/Version.java +++ b/src/example/multi-project/projects/version/src/version/Version.java @@ -1,46 +1,46 @@ -/* - * 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 version; - -import java.io.InputStream; -import java.util.Properties; -import java.util.Map; -import java.util.HashMap; - -public class Version { - static { - versions = new HashMap(); - register("version"); - } - - private static Map versions; - - public static void register(String module) { - try { - InputStream moduleVersion = Version.class.getResourceAsStream("/"+module+".properties"); - Properties props = new Properties(); - props.load(moduleVersion); - String version = (String)props.get("version"); - versions.put(module, version); - System.out.println("--- using "+module+" v"+version); - } catch (Exception ex) { - System.err.println("an error occured while registering "+module+": "+ex.getMessage()); - ex.printStackTrace(); - } - } -} +/* + * 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 version; + +import java.io.InputStream; +import java.util.Properties; +import java.util.Map; +import java.util.HashMap; + +public class Version { + static { + versions = new HashMap(); + register("version"); + } + + private static Map versions; + + public static void register(String module) { + try { + InputStream moduleVersion = Version.class.getResourceAsStream("/"+module+".properties"); + Properties props = new Properties(); + props.load(moduleVersion); + String version = (String)props.get("version"); + versions.put(module, version); + System.out.println("--- using "+module+" v"+version); + } catch (Exception ex) { + System.err.println("an error occured while registering "+module+": "+ex.getMessage()); + ex.printStackTrace(); + } + } +} diff --git a/src/java/org/apache/ivy/Ivy.java b/src/java/org/apache/ivy/Ivy.java index 0129593e..50456fed 100644 --- a/src/java/org/apache/ivy/Ivy.java +++ b/src/java/org/apache/ivy/Ivy.java @@ -1,581 +1,581 @@ -/* - * 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; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.check.CheckEngine; -import org.apache.ivy.core.deliver.DeliverEngine; -import org.apache.ivy.core.deliver.DeliverOptions; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.install.InstallEngine; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.publish.PublishEngine; -import org.apache.ivy.core.publish.PublishOptions; -import org.apache.ivy.core.report.ResolveReport; -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.retrieve.RetrieveEngine; -import org.apache.ivy.core.retrieve.RetrieveOptions; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.core.search.SearchEngine; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.core.sort.NonMatchingVersionReporter; -import org.apache.ivy.core.sort.SortEngine; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.repository.TransferEvent; -import org.apache.ivy.plugins.repository.TransferListener; -import org.apache.ivy.plugins.trigger.Trigger; -import org.apache.ivy.util.HostUtil; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.filter.Filter; - -/** - * Ivy is a free java based dependency manager. - *

- * This class is the main class of Ivy, which acts as a Facade to all services offered by Ivy: - *

    - *
  • resolve dependencies
  • - *
  • retrieve artifacts to a local location
  • - *
  • deliver and publish modules
  • - *
  • repository search and listing
  • - * - * Here is one typical usage: - * - *
    - * Ivy ivy = Ivy.newInstance();
    - * ivy.configure(new URL("ivysettings.xml"));
    - * ivy.resolve(new URL("ivy.xml"));
    - * 
    - */ -public class Ivy { - private static final int KILO = 1024; - - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); - - public static Ivy newInstance() { - Ivy ivy = new Ivy(); - ivy.bind(); - return ivy; - } - - public static Ivy newInstance(IvySettings settings) { - Ivy ivy = new Ivy(); - ivy.setSettings(settings); - ivy.bind(); - return ivy; - } - - /** - * True if the current processing has been requested to be interrupted, false otherwise - */ - private boolean interrupted; - - /** - * True if this instance of Ivy hass already been bound to its dependencies, false otherwise. - * - * @see bind() - */ - private boolean bound; - - /* - * Following are dependencies of the Ivy instance on instances of engines and manager which - * actually do the work The attributes can be set either manually using the corresponding - * setters, or all at once with the default implementations using the bind method - */ - private IvySettings settings; - - private EventManager eventManager; - - private SortEngine sortEngine; - - private SearchEngine searchEngine; - - private CheckEngine checkEngine; - - private ResolveEngine resolveEngine; - - private RetrieveEngine retrieveEngine; - - private DeliverEngine deliverEngine; - - private PublishEngine publishEngine; - - private InstallEngine installEngine; - - /** - * The default constructor of Ivy allows to create an instance of Ivy with none of its - * dependencies (engines, settings, ...) created. If you use this constructor, it's your - * responsibility to set the dependencies of Ivy using the appropriate setters - * (setResolveEngine, ...). You can also call the bind method to set all the dependencies except - * those that you have provided using the setters. If you want to get an instance ready to use, - * prefer the use of Ivy.newInstance(). - */ - public Ivy() { - } - - /** - * This method is used to bind this Ivy instance to required dependencies, i.e. instance of - * settings, engines, and so on. After thes call Ivy is still not configured, which means that - * the settings object is still empty. - */ - public void bind() { - IvyContext.getContext().setIvy(this); - if (settings == null) { - settings = new IvySettings(); - } - if (eventManager == null) { - eventManager = new EventManager(); - } - if (sortEngine == null) { - sortEngine = new SortEngine(settings); - } - if (searchEngine == null) { - searchEngine = new SearchEngine(settings); - } - if (resolveEngine == null) { - resolveEngine = new ResolveEngine(settings, eventManager, sortEngine); - } - if (retrieveEngine == null) { - retrieveEngine = new RetrieveEngine(settings); - } - if (deliverEngine == null) { - deliverEngine = new DeliverEngine(settings); - } - if (publishEngine == null) { - publishEngine = new PublishEngine(settings); - } - if (installEngine == null) { - installEngine = new InstallEngine(settings, searchEngine, resolveEngine, publishEngine); - } - - eventManager.addTransferListener(new TransferListener() { - public void transferProgress(TransferEvent evt) { - switch (evt.getEventType()) { - case TransferEvent.TRANSFER_PROGRESS: - Message.progress(); - break; - case TransferEvent.TRANSFER_COMPLETED: - Message.endProgress(" (" + (evt.getTotalLength() / KILO) + "kB)"); - break; - default: - break; - } - } - }); - - bound = true; - } - - // /////////////////////////////////////////////////////////////////////// - // LOAD SETTINGS - // /////////////////////////////////////////////////////////////////////// - public void configure(File settingsFile) throws ParseException, IOException { - assertBound(); - settings.load(settingsFile); - postConfigure(); - } - - public void configure(URL settingsURL) throws ParseException, IOException { - assertBound(); - settings.load(settingsURL); - postConfigure(); - } - - public void configureDefault() throws ParseException, IOException { - assertBound(); - settings.loadDefault(); - postConfigure(); - } - - /** - * Configures Ivy with 1.4 compatible default settings - */ - public void configureDefault14() throws ParseException, IOException { - assertBound(); - settings.loadDefault14(); - postConfigure(); - } - - // /////////////////////////////////////////////////////////////////////// - // CHECK - // /////////////////////////////////////////////////////////////////////// - public boolean check(URL ivyFile, String resolvername) { - return checkEngine.check(ivyFile, resolvername); - } - - // /////////////////////////////////////////////////////////////////////// - // RESOLVE - // /////////////////////////////////////////////////////////////////////// - - public ResolveReport resolve(File ivySource) throws ParseException, IOException { - return resolveEngine.resolve(ivySource); - } - - public ResolveReport resolve(URL ivySource) throws ParseException, IOException { - return resolveEngine.resolve(ivySource); - } - - public ResolveReport resolve(ModuleRevisionId mrid, ResolveOptions options, boolean changing) - throws ParseException, IOException { - return resolveEngine.resolve(mrid, options, changing); - } - - public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException, - IOException { - return resolveEngine.resolve(ivySource, options); - } - - public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options) - throws ParseException, IOException { - return resolveEngine.resolve(md, options); - } - - // /////////////////////////////////////////////////////////////////////// - // INSTALL - // /////////////////////////////////////////////////////////////////////// - - public ResolveReport install(ModuleRevisionId mrid, String from, String to, boolean transitive, - boolean validate, boolean overwrite, Filter artifactFilter, File cache, - String matcherName) throws IOException { - return installEngine.install(mrid, from, to, transitive, validate, overwrite, - artifactFilter, cache, matcherName); - } - - // /////////////////////////////////////////////////////////////////////// - // RETRIEVE - // /////////////////////////////////////////////////////////////////////// - - public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) - throws IOException { - return retrieveEngine.retrieve(mrid, destFilePattern, options); - } - - // /////////////////////////////////////////////////////////////////////// - // DELIVER - // /////////////////////////////////////////////////////////////////////// - - public void deliver(ModuleRevisionId mrid, String revision, String destIvyPattern) - throws IOException, ParseException { - deliverEngine.deliver(mrid, revision, destIvyPattern, DeliverOptions.newInstance(settings)); - } - - public void deliver(String revision, String destIvyPattern, DeliverOptions options) - throws IOException, ParseException { - deliverEngine.deliver(revision, destIvyPattern, options); - } - - /** - * Example of use: deliver(mrid, "1.5", "target/ivy/ivy-[revision].xml", - * DeliverOptions.newInstance(settings).setStatus("release").setValidate(false)); - * - * @param mrid - * @param revision - * @param destIvyPattern - * @param options - * @throws IOException - * @throws ParseException - */ - public void deliver(ModuleRevisionId mrid, String revision, String destIvyPattern, - DeliverOptions options) throws IOException, ParseException { - deliverEngine.deliver(mrid, revision, destIvyPattern, options); - } - - // /////////////////////////////////////////////////////////////////////// - // PUBLISH - // /////////////////////////////////////////////////////////////////////// - - public Collection publish(ModuleRevisionId mrid, Collection srcArtifactPattern, - String resolverName, PublishOptions options) throws IOException { - return publishEngine.publish(mrid, srcArtifactPattern, resolverName, options); - } - - // /////////////////////////////////////////////////////////////////////// - // SORT - // /////////////////////////////////////////////////////////////////////// - - /** - * Sorts the collection of IvyNode from the less dependent to the more dependent - */ - public List sortNodes(Collection nodes) { - return sortEngine.sortNodes(nodes); - } - - /** - * Sorts the given ModuleDescriptors from the less dependent to the more dependent. This sort - * ensures that a ModuleDescriptor is always found in the list before all ModuleDescriptors - * depending directly on it. - * - * @param moduleDescriptors - * a Collection of ModuleDescriptor to sort - * @return a List of sorted ModuleDescriptors - */ - public List sortModuleDescriptors(Collection moduleDescriptors) { - return sortEngine.sortModuleDescriptors(moduleDescriptors); - } - - public List sortModuleDescriptors(Collection moduleDescriptors, - NonMatchingVersionReporter nonMatchingVersionReporter) { - return sortEngine.sortModuleDescriptors(moduleDescriptors, nonMatchingVersionReporter); - } - - // /////////////////////////////////////////////////////////////////////// - // SEARCH - // /////////////////////////////////////////////////////////////////////// - - public ResolvedModuleRevision findModule(ModuleRevisionId mrid) { - ResolveOptions options = new ResolveOptions(); - options.setValidate(false); - options.setCache(CacheManager.getInstance(settings)); - return resolveEngine.findModule(mrid, options); - } - - public ModuleEntry[] listModuleEntries(OrganisationEntry org) { - return searchEngine.listModuleEntries(org); - } - - public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) { - return searchEngine.listModules(criteria, matcher); - } - - public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) { - return searchEngine.listModules(criteria, matcher); - } - - public String[] listModules(String org) { - return searchEngine.listModules(org); - } - - public OrganisationEntry[] listOrganisationEntries() { - return searchEngine.listOrganisationEntries(); - } - - public String[] listOrganisations() { - return searchEngine.listOrganisations(); - } - - public RevisionEntry[] listRevisionEntries(ModuleEntry module) { - return searchEngine.listRevisionEntries(module); - } - - public String[] listRevisions(String org, String module) { - return searchEngine.listRevisions(org, module); - } - - public String[] listTokenValues(String token, Map otherTokenValues) { - return searchEngine.listTokenValues(token, otherTokenValues); - } - - // /////////////////////////////////////////////////////////////////////// - // INTERRUPTIONS - // /////////////////////////////////////////////////////////////////////// - - /** - * Interrupts the current running operation, no later than interruptTimeout milliseconds after - * the call - */ - public void interrupt() { - Thread operatingThread = IvyContext.getContext().getOperatingThread(); - interrupt(operatingThread); - } - - /** - * Interrupts the current running operation in the given operating thread, no later than - * interruptTimeout milliseconds after the call - */ - public void interrupt(Thread operatingThread) { - if (operatingThread != null && operatingThread.isAlive()) { - if (operatingThread == Thread.currentThread()) { - throw new IllegalStateException("cannot call interrupt from ivy operating thread"); - } - Message.verbose("interrupting operating thread..."); - operatingThread.interrupt(); - synchronized (this) { - interrupted = true; - } - try { - Message.verbose("waiting clean interruption of operating thread"); - operatingThread.join(settings.getInterruptTimeout()); - } catch (InterruptedException e) { - // reset thread interrupt status - Thread.currentThread().interrupt(); - } - if (operatingThread.isAlive()) { - Message.warn("waited clean interruption for too long: stopping operating thread"); - operatingThread.stop(); - } - synchronized (this) { - interrupted = false; - } - } - } - - public synchronized boolean isInterrupted() { - return interrupted; - } - - /** - * Check if the current operation has been interrupted, and if it is the case, throw a runtime - * exception - */ - public void checkInterrupted() { - if (isInterrupted()) { - Message.info("operation interrupted"); - throw new RuntimeException("operation interrupted"); - } - } - - public static String getWorkingRevision() { - return "working@" + HostUtil.getLocalHostName(); - } - - public CacheManager getCacheManager(File cache) { - // TODO : reuse instance - CacheManager cacheManager = new CacheManager(settings, cache); - return cacheManager; - } - - private void assertBound() { - if (!bound) { - bind(); - } - } - - private void postConfigure() { - Collection triggers = settings.getTriggers(); - for (Iterator iter = triggers.iterator(); iter.hasNext();) { - Trigger trigger = (Trigger) iter.next(); - eventManager.addIvyListener(trigger, trigger.getEventFilter()); - } - } - - public String getVariable(String name) { - assertBound(); - return settings.getVariable(name); - } - - public String substitute(String str) { - assertBound(); - return settings.substitute(str); - } - - public void setVariable(String varName, String value) { - assertBound(); - settings.setVariable(varName, value); - } - - // /////////////////////////////////////////////////////////////////// - // GETTERS / SETTERS - // /////////////////////////////////////////////////////////////////// - - public IvySettings getSettings() { - return settings; - } - - public EventManager getEventManager() { - return eventManager; - } - - public CheckEngine getCheckEngine() { - return checkEngine; - } - - public void setCheckEngine(CheckEngine checkEngine) { - this.checkEngine = checkEngine; - } - - public DeliverEngine getDeliverEngine() { - return deliverEngine; - } - - public void setDeliverEngine(DeliverEngine deliverEngine) { - this.deliverEngine = deliverEngine; - } - - public InstallEngine getInstallEngine() { - return installEngine; - } - - public void setInstallEngine(InstallEngine installEngine) { - this.installEngine = installEngine; - } - - public PublishEngine getPublishEngine() { - return publishEngine; - } - - public void setPublishEngine(PublishEngine publishEngine) { - this.publishEngine = publishEngine; - } - - public ResolveEngine getResolveEngine() { - return resolveEngine; - } - - public void setResolveEngine(ResolveEngine resolveEngine) { - this.resolveEngine = resolveEngine; - } - - public RetrieveEngine getRetrieveEngine() { - return retrieveEngine; - } - - public void setRetrieveEngine(RetrieveEngine retrieveEngine) { - this.retrieveEngine = retrieveEngine; - } - - public SearchEngine getSearchEngine() { - return searchEngine; - } - - public void setSearchEngine(SearchEngine searchEngine) { - this.searchEngine = searchEngine; - } - - public SortEngine getSortEngine() { - return sortEngine; - } - - public void setSortEngine(SortEngine sortEngine) { - this.sortEngine = sortEngine; - } - - public void setEventManager(EventManager eventManager) { - this.eventManager = eventManager; - } - - public void setSettings(IvySettings settings) { - this.settings = settings; - } - -} +/* + * 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; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.check.CheckEngine; +import org.apache.ivy.core.deliver.DeliverEngine; +import org.apache.ivy.core.deliver.DeliverOptions; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.install.InstallEngine; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.publish.PublishEngine; +import org.apache.ivy.core.publish.PublishOptions; +import org.apache.ivy.core.report.ResolveReport; +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.retrieve.RetrieveEngine; +import org.apache.ivy.core.retrieve.RetrieveOptions; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.core.search.SearchEngine; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.core.sort.NonMatchingVersionReporter; +import org.apache.ivy.core.sort.SortEngine; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.repository.TransferEvent; +import org.apache.ivy.plugins.repository.TransferListener; +import org.apache.ivy.plugins.trigger.Trigger; +import org.apache.ivy.util.HostUtil; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.filter.Filter; + +/** + * Ivy is a free java based dependency manager. + *

    + * This class is the main class of Ivy, which acts as a Facade to all services offered by Ivy: + *

      + *
    • resolve dependencies
    • + *
    • retrieve artifacts to a local location
    • + *
    • deliver and publish modules
    • + *
    • repository search and listing
    • + * + * Here is one typical usage: + * + *
      + * Ivy ivy = Ivy.newInstance();
      + * ivy.configure(new URL("ivysettings.xml"));
      + * ivy.resolve(new URL("ivy.xml"));
      + * 
      + */ +public class Ivy { + private static final int KILO = 1024; + + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); + + public static Ivy newInstance() { + Ivy ivy = new Ivy(); + ivy.bind(); + return ivy; + } + + public static Ivy newInstance(IvySettings settings) { + Ivy ivy = new Ivy(); + ivy.setSettings(settings); + ivy.bind(); + return ivy; + } + + /** + * True if the current processing has been requested to be interrupted, false otherwise + */ + private boolean interrupted; + + /** + * True if this instance of Ivy hass already been bound to its dependencies, false otherwise. + * + * @see bind() + */ + private boolean bound; + + /* + * Following are dependencies of the Ivy instance on instances of engines and manager which + * actually do the work The attributes can be set either manually using the corresponding + * setters, or all at once with the default implementations using the bind method + */ + private IvySettings settings; + + private EventManager eventManager; + + private SortEngine sortEngine; + + private SearchEngine searchEngine; + + private CheckEngine checkEngine; + + private ResolveEngine resolveEngine; + + private RetrieveEngine retrieveEngine; + + private DeliverEngine deliverEngine; + + private PublishEngine publishEngine; + + private InstallEngine installEngine; + + /** + * The default constructor of Ivy allows to create an instance of Ivy with none of its + * dependencies (engines, settings, ...) created. If you use this constructor, it's your + * responsibility to set the dependencies of Ivy using the appropriate setters + * (setResolveEngine, ...). You can also call the bind method to set all the dependencies except + * those that you have provided using the setters. If you want to get an instance ready to use, + * prefer the use of Ivy.newInstance(). + */ + public Ivy() { + } + + /** + * This method is used to bind this Ivy instance to required dependencies, i.e. instance of + * settings, engines, and so on. After thes call Ivy is still not configured, which means that + * the settings object is still empty. + */ + public void bind() { + IvyContext.getContext().setIvy(this); + if (settings == null) { + settings = new IvySettings(); + } + if (eventManager == null) { + eventManager = new EventManager(); + } + if (sortEngine == null) { + sortEngine = new SortEngine(settings); + } + if (searchEngine == null) { + searchEngine = new SearchEngine(settings); + } + if (resolveEngine == null) { + resolveEngine = new ResolveEngine(settings, eventManager, sortEngine); + } + if (retrieveEngine == null) { + retrieveEngine = new RetrieveEngine(settings); + } + if (deliverEngine == null) { + deliverEngine = new DeliverEngine(settings); + } + if (publishEngine == null) { + publishEngine = new PublishEngine(settings); + } + if (installEngine == null) { + installEngine = new InstallEngine(settings, searchEngine, resolveEngine, publishEngine); + } + + eventManager.addTransferListener(new TransferListener() { + public void transferProgress(TransferEvent evt) { + switch (evt.getEventType()) { + case TransferEvent.TRANSFER_PROGRESS: + Message.progress(); + break; + case TransferEvent.TRANSFER_COMPLETED: + Message.endProgress(" (" + (evt.getTotalLength() / KILO) + "kB)"); + break; + default: + break; + } + } + }); + + bound = true; + } + + // /////////////////////////////////////////////////////////////////////// + // LOAD SETTINGS + // /////////////////////////////////////////////////////////////////////// + public void configure(File settingsFile) throws ParseException, IOException { + assertBound(); + settings.load(settingsFile); + postConfigure(); + } + + public void configure(URL settingsURL) throws ParseException, IOException { + assertBound(); + settings.load(settingsURL); + postConfigure(); + } + + public void configureDefault() throws ParseException, IOException { + assertBound(); + settings.loadDefault(); + postConfigure(); + } + + /** + * Configures Ivy with 1.4 compatible default settings + */ + public void configureDefault14() throws ParseException, IOException { + assertBound(); + settings.loadDefault14(); + postConfigure(); + } + + // /////////////////////////////////////////////////////////////////////// + // CHECK + // /////////////////////////////////////////////////////////////////////// + public boolean check(URL ivyFile, String resolvername) { + return checkEngine.check(ivyFile, resolvername); + } + + // /////////////////////////////////////////////////////////////////////// + // RESOLVE + // /////////////////////////////////////////////////////////////////////// + + public ResolveReport resolve(File ivySource) throws ParseException, IOException { + return resolveEngine.resolve(ivySource); + } + + public ResolveReport resolve(URL ivySource) throws ParseException, IOException { + return resolveEngine.resolve(ivySource); + } + + public ResolveReport resolve(ModuleRevisionId mrid, ResolveOptions options, boolean changing) + throws ParseException, IOException { + return resolveEngine.resolve(mrid, options, changing); + } + + public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException, + IOException { + return resolveEngine.resolve(ivySource, options); + } + + public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options) + throws ParseException, IOException { + return resolveEngine.resolve(md, options); + } + + // /////////////////////////////////////////////////////////////////////// + // INSTALL + // /////////////////////////////////////////////////////////////////////// + + public ResolveReport install(ModuleRevisionId mrid, String from, String to, boolean transitive, + boolean validate, boolean overwrite, Filter artifactFilter, File cache, + String matcherName) throws IOException { + return installEngine.install(mrid, from, to, transitive, validate, overwrite, + artifactFilter, cache, matcherName); + } + + // /////////////////////////////////////////////////////////////////////// + // RETRIEVE + // /////////////////////////////////////////////////////////////////////// + + public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) + throws IOException { + return retrieveEngine.retrieve(mrid, destFilePattern, options); + } + + // /////////////////////////////////////////////////////////////////////// + // DELIVER + // /////////////////////////////////////////////////////////////////////// + + public void deliver(ModuleRevisionId mrid, String revision, String destIvyPattern) + throws IOException, ParseException { + deliverEngine.deliver(mrid, revision, destIvyPattern, DeliverOptions.newInstance(settings)); + } + + public void deliver(String revision, String destIvyPattern, DeliverOptions options) + throws IOException, ParseException { + deliverEngine.deliver(revision, destIvyPattern, options); + } + + /** + * Example of use: deliver(mrid, "1.5", "target/ivy/ivy-[revision].xml", + * DeliverOptions.newInstance(settings).setStatus("release").setValidate(false)); + * + * @param mrid + * @param revision + * @param destIvyPattern + * @param options + * @throws IOException + * @throws ParseException + */ + public void deliver(ModuleRevisionId mrid, String revision, String destIvyPattern, + DeliverOptions options) throws IOException, ParseException { + deliverEngine.deliver(mrid, revision, destIvyPattern, options); + } + + // /////////////////////////////////////////////////////////////////////// + // PUBLISH + // /////////////////////////////////////////////////////////////////////// + + public Collection publish(ModuleRevisionId mrid, Collection srcArtifactPattern, + String resolverName, PublishOptions options) throws IOException { + return publishEngine.publish(mrid, srcArtifactPattern, resolverName, options); + } + + // /////////////////////////////////////////////////////////////////////// + // SORT + // /////////////////////////////////////////////////////////////////////// + + /** + * Sorts the collection of IvyNode from the less dependent to the more dependent + */ + public List sortNodes(Collection nodes) { + return sortEngine.sortNodes(nodes); + } + + /** + * Sorts the given ModuleDescriptors from the less dependent to the more dependent. This sort + * ensures that a ModuleDescriptor is always found in the list before all ModuleDescriptors + * depending directly on it. + * + * @param moduleDescriptors + * a Collection of ModuleDescriptor to sort + * @return a List of sorted ModuleDescriptors + */ + public List sortModuleDescriptors(Collection moduleDescriptors) { + return sortEngine.sortModuleDescriptors(moduleDescriptors); + } + + public List sortModuleDescriptors(Collection moduleDescriptors, + NonMatchingVersionReporter nonMatchingVersionReporter) { + return sortEngine.sortModuleDescriptors(moduleDescriptors, nonMatchingVersionReporter); + } + + // /////////////////////////////////////////////////////////////////////// + // SEARCH + // /////////////////////////////////////////////////////////////////////// + + public ResolvedModuleRevision findModule(ModuleRevisionId mrid) { + ResolveOptions options = new ResolveOptions(); + options.setValidate(false); + options.setCache(CacheManager.getInstance(settings)); + return resolveEngine.findModule(mrid, options); + } + + public ModuleEntry[] listModuleEntries(OrganisationEntry org) { + return searchEngine.listModuleEntries(org); + } + + public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) { + return searchEngine.listModules(criteria, matcher); + } + + public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) { + return searchEngine.listModules(criteria, matcher); + } + + public String[] listModules(String org) { + return searchEngine.listModules(org); + } + + public OrganisationEntry[] listOrganisationEntries() { + return searchEngine.listOrganisationEntries(); + } + + public String[] listOrganisations() { + return searchEngine.listOrganisations(); + } + + public RevisionEntry[] listRevisionEntries(ModuleEntry module) { + return searchEngine.listRevisionEntries(module); + } + + public String[] listRevisions(String org, String module) { + return searchEngine.listRevisions(org, module); + } + + public String[] listTokenValues(String token, Map otherTokenValues) { + return searchEngine.listTokenValues(token, otherTokenValues); + } + + // /////////////////////////////////////////////////////////////////////// + // INTERRUPTIONS + // /////////////////////////////////////////////////////////////////////// + + /** + * Interrupts the current running operation, no later than interruptTimeout milliseconds after + * the call + */ + public void interrupt() { + Thread operatingThread = IvyContext.getContext().getOperatingThread(); + interrupt(operatingThread); + } + + /** + * Interrupts the current running operation in the given operating thread, no later than + * interruptTimeout milliseconds after the call + */ + public void interrupt(Thread operatingThread) { + if (operatingThread != null && operatingThread.isAlive()) { + if (operatingThread == Thread.currentThread()) { + throw new IllegalStateException("cannot call interrupt from ivy operating thread"); + } + Message.verbose("interrupting operating thread..."); + operatingThread.interrupt(); + synchronized (this) { + interrupted = true; + } + try { + Message.verbose("waiting clean interruption of operating thread"); + operatingThread.join(settings.getInterruptTimeout()); + } catch (InterruptedException e) { + // reset thread interrupt status + Thread.currentThread().interrupt(); + } + if (operatingThread.isAlive()) { + Message.warn("waited clean interruption for too long: stopping operating thread"); + operatingThread.stop(); + } + synchronized (this) { + interrupted = false; + } + } + } + + public synchronized boolean isInterrupted() { + return interrupted; + } + + /** + * Check if the current operation has been interrupted, and if it is the case, throw a runtime + * exception + */ + public void checkInterrupted() { + if (isInterrupted()) { + Message.info("operation interrupted"); + throw new RuntimeException("operation interrupted"); + } + } + + public static String getWorkingRevision() { + return "working@" + HostUtil.getLocalHostName(); + } + + public CacheManager getCacheManager(File cache) { + // TODO : reuse instance + CacheManager cacheManager = new CacheManager(settings, cache); + return cacheManager; + } + + private void assertBound() { + if (!bound) { + bind(); + } + } + + private void postConfigure() { + Collection triggers = settings.getTriggers(); + for (Iterator iter = triggers.iterator(); iter.hasNext();) { + Trigger trigger = (Trigger) iter.next(); + eventManager.addIvyListener(trigger, trigger.getEventFilter()); + } + } + + public String getVariable(String name) { + assertBound(); + return settings.getVariable(name); + } + + public String substitute(String str) { + assertBound(); + return settings.substitute(str); + } + + public void setVariable(String varName, String value) { + assertBound(); + settings.setVariable(varName, value); + } + + // /////////////////////////////////////////////////////////////////// + // GETTERS / SETTERS + // /////////////////////////////////////////////////////////////////// + + public IvySettings getSettings() { + return settings; + } + + public EventManager getEventManager() { + return eventManager; + } + + public CheckEngine getCheckEngine() { + return checkEngine; + } + + public void setCheckEngine(CheckEngine checkEngine) { + this.checkEngine = checkEngine; + } + + public DeliverEngine getDeliverEngine() { + return deliverEngine; + } + + public void setDeliverEngine(DeliverEngine deliverEngine) { + this.deliverEngine = deliverEngine; + } + + public InstallEngine getInstallEngine() { + return installEngine; + } + + public void setInstallEngine(InstallEngine installEngine) { + this.installEngine = installEngine; + } + + public PublishEngine getPublishEngine() { + return publishEngine; + } + + public void setPublishEngine(PublishEngine publishEngine) { + this.publishEngine = publishEngine; + } + + public ResolveEngine getResolveEngine() { + return resolveEngine; + } + + public void setResolveEngine(ResolveEngine resolveEngine) { + this.resolveEngine = resolveEngine; + } + + public RetrieveEngine getRetrieveEngine() { + return retrieveEngine; + } + + public void setRetrieveEngine(RetrieveEngine retrieveEngine) { + this.retrieveEngine = retrieveEngine; + } + + public SearchEngine getSearchEngine() { + return searchEngine; + } + + public void setSearchEngine(SearchEngine searchEngine) { + this.searchEngine = searchEngine; + } + + public SortEngine getSortEngine() { + return sortEngine; + } + + public void setSortEngine(SortEngine sortEngine) { + this.sortEngine = sortEngine; + } + + public void setEventManager(EventManager eventManager) { + this.eventManager = eventManager; + } + + public void setSettings(IvySettings settings) { + this.settings = settings; + } + +} diff --git a/src/java/org/apache/ivy/Ivy14.java b/src/java/org/apache/ivy/Ivy14.java index dc64fad3..1f973100 100644 --- a/src/java/org/apache/ivy/Ivy14.java +++ b/src/java/org/apache/ivy/Ivy14.java @@ -1,485 +1,485 @@ -/* - * 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; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.text.ParseException; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.deliver.DeliverOptions; -import org.apache.ivy.core.deliver.PublishingDependencyRevisionResolver; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.publish.PublishOptions; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.retrieve.RetrieveOptions; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.filter.Filter; -import org.apache.ivy.util.filter.FilterHelper; - -/** - * This class can be used for easy migration from Ivy 1.4 API. - *

      - * Indeed, Ivy 2.0 API has changed substantially, so it can take time to migrate existing code using - * Ivy 1.4 API to the new API. Using this class it's really easy: replace your instance of Ivy by an - * instance of this class. - *

      - * For instance, where you were doing: - * - *

      - * Ivy ivy = new Ivy();
      - * 
      - * - * do instead: - * - *
      - * Ivy14 ivy = new Ivy14();
      - * 
      - * - * And that should be enough in most cases! - */ -public class Ivy14 { - //CheckStyle:ParameterNumberCheck OFF - // don't check parameter numbers, since this class is here for backward compatibility - - - private Ivy ivy; - - public Ivy14() { - this(Ivy.newInstance()); - } - - public Ivy14(Ivy ivy) { - this.ivy = ivy; - } - - public boolean check(URL ivyFile, String resolvername) { - return ivy.check(ivyFile, resolvername); - } - - public void configure(File settingsFile) throws ParseException, IOException { - ivy.configure(settingsFile); - } - - public void configure(URL settingsURL) throws ParseException, IOException { - ivy.configure(settingsURL); - } - - public void configureDefault() throws ParseException, IOException { - ivy.configureDefault(); - } - - public void deliver(ModuleRevisionId mrid, String revision, File cache, String destIvyPattern, - String status, Date pubdate, PublishingDependencyRevisionResolver pdrResolver, - boolean validate, boolean resolveDynamicRevisions) throws IOException, ParseException { - ivy.deliver(mrid, revision, destIvyPattern, new DeliverOptions(status, pubdate, - CacheManager.getInstance(ivy.getSettings(), cache), pdrResolver, validate, - resolveDynamicRevisions, null)); - } - - public void deliver(ModuleRevisionId mrid, String revision, File cache, String destIvyPattern, - String status, Date pubdate, PublishingDependencyRevisionResolver pdrResolver, - boolean validate) throws IOException, ParseException { - deliver(mrid, revision, cache, destIvyPattern, status, - pubdate, pdrResolver, validate, true); - } - - public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, - String destFilePattern, String destIvyPattern, Filter artifactFilter) - throws ParseException, IOException { - return ivy.getRetrieveEngine().determineArtifactsToCopy( - new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), - destFilePattern, - new RetrieveOptions().setConfs(confs).setCache( - CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( - destIvyPattern).setArtifactFilter(artifactFilter)); - } - - public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, - String destFilePattern, String destIvyPattern) throws ParseException, IOException { - return ivy.getRetrieveEngine().determineArtifactsToCopy( - new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), - destFilePattern, - new RetrieveOptions().setConfs(confs).setCache( - CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( - destIvyPattern)); - } - - public ArtifactDownloadReport download(Artifact artifact, File cache, boolean useOrigin) { - return ivy.getResolveEngine().download(artifact, ivy.getCacheManager(cache), useOrigin); - } - - public void downloadArtifacts(ResolveReport report, CacheManager cacheManager, - boolean useOrigin, Filter artifactFilter) { - ivy.getResolveEngine().downloadArtifacts(report, cacheManager, useOrigin, artifactFilter); - } - - public ResolvedModuleRevision findModule(ModuleRevisionId id) { - ResolveOptions options = new ResolveOptions(); - options.setValidate(false); - options.setCache(CacheManager.getInstance(ivy.getSettings())); - return ivy.getResolveEngine().findModule(id, options); - } - - public IvyNode[] getDependencies(ModuleDescriptor md, String[] confs, File cache, Date date, - ResolveReport report, boolean validate, boolean transitive) { - return ivy.getResolveEngine().getDependencies( - md, - newResolveOptions(confs, null, cache, date, validate, false, transitive, false, true, - true, FilterHelper.NO_FILTER), report); - } - - public IvyNode[] getDependencies(ModuleDescriptor md, String[] confs, File cache, Date date, - ResolveReport report, boolean validate) { - return ivy.getResolveEngine().getDependencies( - md, - newResolveOptions(confs, null, cache, date, validate, false, true, false, true, true, - FilterHelper.NO_FILTER), report); - } - - public IvyNode[] getDependencies(URL ivySource, String[] confs, File cache, Date date, - boolean validate) throws ParseException, IOException { - return ivy.getResolveEngine().getDependencies( - ivySource, - newResolveOptions(confs, null, cache, date, validate, false, true, false, true, true, - FilterHelper.NO_FILTER)); - } - - public String getVariable(String name) { - return ivy.getVariable(name); - } - - public ResolveReport install(ModuleRevisionId mrid, String from, String to, boolean transitive, - boolean validate, boolean overwrite, Filter artifactFilter, File cache, - String matcherName) throws IOException { - return ivy.install(mrid, from, to, transitive, validate, overwrite, artifactFilter, cache, - matcherName); - } - - public void interrupt() { - ivy.interrupt(); - } - - public void interrupt(Thread operatingThread) { - ivy.interrupt(operatingThread); - } - - public boolean isInterrupted() { - return ivy.isInterrupted(); - } - - public ModuleEntry[] listModuleEntries(OrganisationEntry org) { - return ivy.listModuleEntries(org); - } - - public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) { - return ivy.listModules(criteria, matcher); - } - - public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) { - return ivy.listModules(criteria, matcher); - } - - public String[] listModules(String org) { - return ivy.listModules(org); - } - - public OrganisationEntry[] listOrganisationEntries() { - return ivy.listOrganisationEntries(); - } - - public String[] listOrganisations() { - return ivy.listOrganisations(); - } - - public RevisionEntry[] listRevisionEntries(ModuleEntry module) { - return ivy.listRevisionEntries(module); - } - - public String[] listRevisions(String org, String module) { - return ivy.listRevisions(org, module); - } - - public String[] listTokenValues(String token, Map otherTokenValues) { - return ivy.listTokenValues(token, otherTokenValues); - } - - public Collection publish(ModuleDescriptor md, DependencyResolver resolver, - Collection srcArtifactPattern, String srcIvyPattern, Artifact[] extraArtifacts, - boolean overwrite, String conf) throws IOException { - return ivy.getPublishEngine().publish( - md, - srcArtifactPattern, - resolver, - new PublishOptions().setSrcIvyPattern(srcIvyPattern).setExtraArtifacts(extraArtifacts) - .setOverwrite(overwrite).setConfs(splitConfs(conf))); - } - - public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, - Collection srcArtifactPattern, String resolverName, String srcIvyPattern, - String status, Date pubdate, Artifact[] extraArtifacts, boolean validate, - boolean overwrite, boolean update, String conf) throws IOException { - return ivy.publish(mrid, srcArtifactPattern, resolverName, new PublishOptions().setCache( - ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) - .setStatus(status).setPubdate(pubdate).setPubrevision(pubrevision) - .setSrcIvyPattern(srcIvyPattern).setExtraArtifacts(extraArtifacts) - .setUpdate(update).setValidate(validate).setOverwrite(overwrite).setConfs( - splitConfs(conf))); - } - - public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, - String srcArtifactPattern, String resolverName, String srcIvyPattern, boolean validate, - boolean overwrite) throws IOException { - return ivy.publish(mrid, Collections.singleton(srcArtifactPattern), resolverName, - new PublishOptions().setCache( - ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) - .setPubrevision(pubrevision).setSrcIvyPattern(srcIvyPattern).setValidate( - validate).setOverwrite(overwrite)); - } - - public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, - String srcArtifactPattern, String resolverName, String srcIvyPattern, boolean validate) - throws IOException { - return ivy.publish(mrid, Collections.singleton(srcArtifactPattern), resolverName, - new PublishOptions().setCache( - ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) - .setPubrevision(pubrevision).setSrcIvyPattern(srcIvyPattern).setValidate( - validate)); - } - - public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, - String srcArtifactPattern, String resolverName, String srcIvyPattern, String status, - Date pubdate, Artifact[] extraArtifacts, boolean validate, boolean overwrite, - boolean update, String conf) throws IOException { - return ivy.publish(mrid, Collections.singleton(srcArtifactPattern), resolverName, - new PublishOptions().setCache( - ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) - .setStatus(status).setPubdate(pubdate).setPubrevision(pubrevision) - .setSrcIvyPattern(srcIvyPattern).setExtraArtifacts(extraArtifacts).setUpdate( - update).setValidate(validate).setOverwrite(overwrite).setConfs( - splitConfs(conf))); - } - - public ResolveReport resolve(File ivySource) throws ParseException, IOException { - return ivy.resolve(ivySource); - } - - public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, - boolean validate, boolean useCacheOnly, boolean transitive, boolean useOrigin, - boolean download, boolean outputReport, Filter artifactFilter) throws ParseException, - IOException { - return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, - transitive, useOrigin, download, outputReport, artifactFilter)); - } - - private ResolveOptions newResolveOptions(String[] confs, String revision, File cache, - Date date, boolean validate, boolean useCacheOnly, boolean transitive, - boolean useOrigin, boolean download, boolean outputReport, Filter artifactFilter) { - return new ResolveOptions().setConfs(confs).setRevision(revision).setCache( - ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) - .setValidate(validate).setUseCacheOnly(useCacheOnly).setTransitive(transitive) - .setUseOrigin(useOrigin).setDownload(download).setOutputReport(outputReport) - .setArtifactFilter(artifactFilter); - } - - public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, - boolean validate, boolean useCacheOnly, boolean transitive, boolean download, - boolean outputReport, Filter artifactFilter) throws ParseException, IOException { - return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, - transitive, false, download, outputReport, artifactFilter)); - } - - public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, - boolean validate, boolean useCacheOnly, boolean transitive, Filter artifactFilter) - throws ParseException, IOException { - return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, - transitive, false, true, true, artifactFilter)); - } - - public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, - boolean validate, boolean useCacheOnly, Filter artifactFilter) throws ParseException, - IOException { - return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, - true, false, true, true, artifactFilter)); - } - - public ResolveReport resolve(ModuleRevisionId mrid, String[] confs, boolean transitive, - boolean changing, File cache, Date date, boolean validate, boolean useCacheOnly, - boolean useOrigin, Filter artifactFilter) throws ParseException, IOException { - return ivy.resolve(mrid, newResolveOptions(confs, null, cache, date, validate, - useCacheOnly, transitive, useOrigin, true, true, artifactFilter), changing); - } - - public ResolveReport resolve(ModuleRevisionId mrid, String[] confs, boolean transitive, - boolean changing, File cache, Date date, boolean validate, boolean useCacheOnly, - Filter artifactFilter) throws ParseException, IOException { - return ivy.resolve(mrid, newResolveOptions(confs, null, cache, date, validate, - useCacheOnly, transitive, false, true, true, artifactFilter), changing); - } - - public ResolveReport resolve(ModuleRevisionId mrid, String[] confs) throws ParseException, - IOException { - return ivy.resolve(mrid, newResolveOptions(confs, null, - ivy.getSettings().getDefaultCache(), null, true, false, true, false, true, true, - FilterHelper.NO_FILTER), false); - } - - public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, - Date date, boolean validate, boolean useCacheOnly, boolean transitive, - boolean useOrigin, Filter artifactFilter) throws ParseException, IOException { - return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, - useCacheOnly, transitive, useOrigin, true, true, artifactFilter)); - } - - public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, - Date date, boolean validate, boolean useCacheOnly, boolean transitive, - Filter artifactFilter) throws ParseException, IOException { - return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, - useCacheOnly, transitive, false, true, true, artifactFilter)); - } - - public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, - Date date, boolean validate, boolean useCacheOnly, Filter artifactFilter) - throws ParseException, IOException { - return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, - useCacheOnly, true, false, true, true, artifactFilter)); - } - - public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, - Date date, boolean validate, boolean useCacheOnly) throws ParseException, IOException { - return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, - useCacheOnly, true, false, true, true, FilterHelper.NO_FILTER)); - } - - public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, - Date date, boolean validate) throws ParseException, IOException { - return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, - false, true, false, true, true, FilterHelper.NO_FILTER)); - } - - public ResolveReport resolve(URL ivySource) throws ParseException, IOException { - return ivy.resolve(ivySource); - } - - public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, - String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin, - boolean makeSymlinks) { - try { - return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), - destFilePattern, new RetrieveOptions().setConfs(confs).setCache( - CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( - destIvyPattern).setArtifactFilter(artifactFilter).setSync(sync).setUseOrigin( - useOrigin).setMakeSymlinks(makeSymlinks)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, - String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin) { - try { - return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), - destFilePattern, new RetrieveOptions().setConfs(confs).setCache( - CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( - destIvyPattern).setArtifactFilter(artifactFilter).setSync(sync).setUseOrigin( - useOrigin)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, - String destIvyPattern, Filter artifactFilter) { - try { - return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), - destFilePattern, new RetrieveOptions().setConfs(confs).setCache( - CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( - destIvyPattern).setArtifactFilter(artifactFilter)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, - String destIvyPattern) { - try { - return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), - destFilePattern, new RetrieveOptions().setConfs(confs).setCache( - CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( - destIvyPattern)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern) { - try { - return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), - destFilePattern, new RetrieveOptions().setConfs(confs).setCache( - CacheManager.getInstance(ivy.getSettings(), cache))); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void setVariable(String varName, String value) { - ivy.setVariable(varName, value); - } - - public List sortModuleDescriptors(Collection moduleDescriptors) { - return ivy.sortModuleDescriptors(moduleDescriptors); - } - - public List sortNodes(Collection nodes) { - return ivy.sortNodes(nodes); - } - - public String substitute(String str) { - return ivy.substitute(str); - } - - private String[] splitConfs(String conf) { - if (conf == null || "".equals(conf)) { - return null; - } - String[] confs = conf.split(","); - for (int i = 0; i < confs.length; i++) { - confs[i] = confs[i].trim(); - } - return confs; - } - - //CheckStyle:ParameterNumberCheck ON -} +/* + * 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; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.text.ParseException; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.deliver.DeliverOptions; +import org.apache.ivy.core.deliver.PublishingDependencyRevisionResolver; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.publish.PublishOptions; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.retrieve.RetrieveOptions; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.filter.Filter; +import org.apache.ivy.util.filter.FilterHelper; + +/** + * This class can be used for easy migration from Ivy 1.4 API. + *

      + * Indeed, Ivy 2.0 API has changed substantially, so it can take time to migrate existing code using + * Ivy 1.4 API to the new API. Using this class it's really easy: replace your instance of Ivy by an + * instance of this class. + *

      + * For instance, where you were doing: + * + *

      + * Ivy ivy = new Ivy();
      + * 
      + * + * do instead: + * + *
      + * Ivy14 ivy = new Ivy14();
      + * 
      + * + * And that should be enough in most cases! + */ +public class Ivy14 { + //CheckStyle:ParameterNumberCheck OFF + // don't check parameter numbers, since this class is here for backward compatibility + + + private Ivy ivy; + + public Ivy14() { + this(Ivy.newInstance()); + } + + public Ivy14(Ivy ivy) { + this.ivy = ivy; + } + + public boolean check(URL ivyFile, String resolvername) { + return ivy.check(ivyFile, resolvername); + } + + public void configure(File settingsFile) throws ParseException, IOException { + ivy.configure(settingsFile); + } + + public void configure(URL settingsURL) throws ParseException, IOException { + ivy.configure(settingsURL); + } + + public void configureDefault() throws ParseException, IOException { + ivy.configureDefault(); + } + + public void deliver(ModuleRevisionId mrid, String revision, File cache, String destIvyPattern, + String status, Date pubdate, PublishingDependencyRevisionResolver pdrResolver, + boolean validate, boolean resolveDynamicRevisions) throws IOException, ParseException { + ivy.deliver(mrid, revision, destIvyPattern, new DeliverOptions(status, pubdate, + CacheManager.getInstance(ivy.getSettings(), cache), pdrResolver, validate, + resolveDynamicRevisions, null)); + } + + public void deliver(ModuleRevisionId mrid, String revision, File cache, String destIvyPattern, + String status, Date pubdate, PublishingDependencyRevisionResolver pdrResolver, + boolean validate) throws IOException, ParseException { + deliver(mrid, revision, cache, destIvyPattern, status, + pubdate, pdrResolver, validate, true); + } + + public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, + String destFilePattern, String destIvyPattern, Filter artifactFilter) + throws ParseException, IOException { + return ivy.getRetrieveEngine().determineArtifactsToCopy( + new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), + destFilePattern, + new RetrieveOptions().setConfs(confs).setCache( + CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( + destIvyPattern).setArtifactFilter(artifactFilter)); + } + + public Map determineArtifactsToCopy(ModuleId moduleId, String[] confs, File cache, + String destFilePattern, String destIvyPattern) throws ParseException, IOException { + return ivy.getRetrieveEngine().determineArtifactsToCopy( + new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), + destFilePattern, + new RetrieveOptions().setConfs(confs).setCache( + CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( + destIvyPattern)); + } + + public ArtifactDownloadReport download(Artifact artifact, File cache, boolean useOrigin) { + return ivy.getResolveEngine().download(artifact, ivy.getCacheManager(cache), useOrigin); + } + + public void downloadArtifacts(ResolveReport report, CacheManager cacheManager, + boolean useOrigin, Filter artifactFilter) { + ivy.getResolveEngine().downloadArtifacts(report, cacheManager, useOrigin, artifactFilter); + } + + public ResolvedModuleRevision findModule(ModuleRevisionId id) { + ResolveOptions options = new ResolveOptions(); + options.setValidate(false); + options.setCache(CacheManager.getInstance(ivy.getSettings())); + return ivy.getResolveEngine().findModule(id, options); + } + + public IvyNode[] getDependencies(ModuleDescriptor md, String[] confs, File cache, Date date, + ResolveReport report, boolean validate, boolean transitive) { + return ivy.getResolveEngine().getDependencies( + md, + newResolveOptions(confs, null, cache, date, validate, false, transitive, false, true, + true, FilterHelper.NO_FILTER), report); + } + + public IvyNode[] getDependencies(ModuleDescriptor md, String[] confs, File cache, Date date, + ResolveReport report, boolean validate) { + return ivy.getResolveEngine().getDependencies( + md, + newResolveOptions(confs, null, cache, date, validate, false, true, false, true, true, + FilterHelper.NO_FILTER), report); + } + + public IvyNode[] getDependencies(URL ivySource, String[] confs, File cache, Date date, + boolean validate) throws ParseException, IOException { + return ivy.getResolveEngine().getDependencies( + ivySource, + newResolveOptions(confs, null, cache, date, validate, false, true, false, true, true, + FilterHelper.NO_FILTER)); + } + + public String getVariable(String name) { + return ivy.getVariable(name); + } + + public ResolveReport install(ModuleRevisionId mrid, String from, String to, boolean transitive, + boolean validate, boolean overwrite, Filter artifactFilter, File cache, + String matcherName) throws IOException { + return ivy.install(mrid, from, to, transitive, validate, overwrite, artifactFilter, cache, + matcherName); + } + + public void interrupt() { + ivy.interrupt(); + } + + public void interrupt(Thread operatingThread) { + ivy.interrupt(operatingThread); + } + + public boolean isInterrupted() { + return ivy.isInterrupted(); + } + + public ModuleEntry[] listModuleEntries(OrganisationEntry org) { + return ivy.listModuleEntries(org); + } + + public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) { + return ivy.listModules(criteria, matcher); + } + + public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) { + return ivy.listModules(criteria, matcher); + } + + public String[] listModules(String org) { + return ivy.listModules(org); + } + + public OrganisationEntry[] listOrganisationEntries() { + return ivy.listOrganisationEntries(); + } + + public String[] listOrganisations() { + return ivy.listOrganisations(); + } + + public RevisionEntry[] listRevisionEntries(ModuleEntry module) { + return ivy.listRevisionEntries(module); + } + + public String[] listRevisions(String org, String module) { + return ivy.listRevisions(org, module); + } + + public String[] listTokenValues(String token, Map otherTokenValues) { + return ivy.listTokenValues(token, otherTokenValues); + } + + public Collection publish(ModuleDescriptor md, DependencyResolver resolver, + Collection srcArtifactPattern, String srcIvyPattern, Artifact[] extraArtifacts, + boolean overwrite, String conf) throws IOException { + return ivy.getPublishEngine().publish( + md, + srcArtifactPattern, + resolver, + new PublishOptions().setSrcIvyPattern(srcIvyPattern).setExtraArtifacts(extraArtifacts) + .setOverwrite(overwrite).setConfs(splitConfs(conf))); + } + + public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, + Collection srcArtifactPattern, String resolverName, String srcIvyPattern, + String status, Date pubdate, Artifact[] extraArtifacts, boolean validate, + boolean overwrite, boolean update, String conf) throws IOException { + return ivy.publish(mrid, srcArtifactPattern, resolverName, new PublishOptions().setCache( + ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) + .setStatus(status).setPubdate(pubdate).setPubrevision(pubrevision) + .setSrcIvyPattern(srcIvyPattern).setExtraArtifacts(extraArtifacts) + .setUpdate(update).setValidate(validate).setOverwrite(overwrite).setConfs( + splitConfs(conf))); + } + + public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, + String srcArtifactPattern, String resolverName, String srcIvyPattern, boolean validate, + boolean overwrite) throws IOException { + return ivy.publish(mrid, Collections.singleton(srcArtifactPattern), resolverName, + new PublishOptions().setCache( + ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) + .setPubrevision(pubrevision).setSrcIvyPattern(srcIvyPattern).setValidate( + validate).setOverwrite(overwrite)); + } + + public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, + String srcArtifactPattern, String resolverName, String srcIvyPattern, boolean validate) + throws IOException { + return ivy.publish(mrid, Collections.singleton(srcArtifactPattern), resolverName, + new PublishOptions().setCache( + ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) + .setPubrevision(pubrevision).setSrcIvyPattern(srcIvyPattern).setValidate( + validate)); + } + + public Collection publish(ModuleRevisionId mrid, String pubrevision, File cache, + String srcArtifactPattern, String resolverName, String srcIvyPattern, String status, + Date pubdate, Artifact[] extraArtifacts, boolean validate, boolean overwrite, + boolean update, String conf) throws IOException { + return ivy.publish(mrid, Collections.singleton(srcArtifactPattern), resolverName, + new PublishOptions().setCache( + ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) + .setStatus(status).setPubdate(pubdate).setPubrevision(pubrevision) + .setSrcIvyPattern(srcIvyPattern).setExtraArtifacts(extraArtifacts).setUpdate( + update).setValidate(validate).setOverwrite(overwrite).setConfs( + splitConfs(conf))); + } + + public ResolveReport resolve(File ivySource) throws ParseException, IOException { + return ivy.resolve(ivySource); + } + + public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, + boolean validate, boolean useCacheOnly, boolean transitive, boolean useOrigin, + boolean download, boolean outputReport, Filter artifactFilter) throws ParseException, + IOException { + return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, + transitive, useOrigin, download, outputReport, artifactFilter)); + } + + private ResolveOptions newResolveOptions(String[] confs, String revision, File cache, + Date date, boolean validate, boolean useCacheOnly, boolean transitive, + boolean useOrigin, boolean download, boolean outputReport, Filter artifactFilter) { + return new ResolveOptions().setConfs(confs).setRevision(revision).setCache( + ivy.getCacheManager(cache == null ? ivy.getSettings().getDefaultCache() : cache)) + .setValidate(validate).setUseCacheOnly(useCacheOnly).setTransitive(transitive) + .setUseOrigin(useOrigin).setDownload(download).setOutputReport(outputReport) + .setArtifactFilter(artifactFilter); + } + + public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, + boolean validate, boolean useCacheOnly, boolean transitive, boolean download, + boolean outputReport, Filter artifactFilter) throws ParseException, IOException { + return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, + transitive, false, download, outputReport, artifactFilter)); + } + + public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, + boolean validate, boolean useCacheOnly, boolean transitive, Filter artifactFilter) + throws ParseException, IOException { + return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, + transitive, false, true, true, artifactFilter)); + } + + public ResolveReport resolve(ModuleDescriptor md, String[] confs, File cache, Date date, + boolean validate, boolean useCacheOnly, Filter artifactFilter) throws ParseException, + IOException { + return ivy.resolve(md, newResolveOptions(confs, null, cache, date, validate, useCacheOnly, + true, false, true, true, artifactFilter)); + } + + public ResolveReport resolve(ModuleRevisionId mrid, String[] confs, boolean transitive, + boolean changing, File cache, Date date, boolean validate, boolean useCacheOnly, + boolean useOrigin, Filter artifactFilter) throws ParseException, IOException { + return ivy.resolve(mrid, newResolveOptions(confs, null, cache, date, validate, + useCacheOnly, transitive, useOrigin, true, true, artifactFilter), changing); + } + + public ResolveReport resolve(ModuleRevisionId mrid, String[] confs, boolean transitive, + boolean changing, File cache, Date date, boolean validate, boolean useCacheOnly, + Filter artifactFilter) throws ParseException, IOException { + return ivy.resolve(mrid, newResolveOptions(confs, null, cache, date, validate, + useCacheOnly, transitive, false, true, true, artifactFilter), changing); + } + + public ResolveReport resolve(ModuleRevisionId mrid, String[] confs) throws ParseException, + IOException { + return ivy.resolve(mrid, newResolveOptions(confs, null, + ivy.getSettings().getDefaultCache(), null, true, false, true, false, true, true, + FilterHelper.NO_FILTER), false); + } + + public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, + Date date, boolean validate, boolean useCacheOnly, boolean transitive, + boolean useOrigin, Filter artifactFilter) throws ParseException, IOException { + return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, + useCacheOnly, transitive, useOrigin, true, true, artifactFilter)); + } + + public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, + Date date, boolean validate, boolean useCacheOnly, boolean transitive, + Filter artifactFilter) throws ParseException, IOException { + return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, + useCacheOnly, transitive, false, true, true, artifactFilter)); + } + + public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, + Date date, boolean validate, boolean useCacheOnly, Filter artifactFilter) + throws ParseException, IOException { + return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, + useCacheOnly, true, false, true, true, artifactFilter)); + } + + public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, + Date date, boolean validate, boolean useCacheOnly) throws ParseException, IOException { + return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, + useCacheOnly, true, false, true, true, FilterHelper.NO_FILTER)); + } + + public ResolveReport resolve(URL ivySource, String revision, String[] confs, File cache, + Date date, boolean validate) throws ParseException, IOException { + return ivy.resolve(ivySource, newResolveOptions(confs, revision, cache, date, validate, + false, true, false, true, true, FilterHelper.NO_FILTER)); + } + + public ResolveReport resolve(URL ivySource) throws ParseException, IOException { + return ivy.resolve(ivySource); + } + + public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, + String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin, + boolean makeSymlinks) { + try { + return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), + destFilePattern, new RetrieveOptions().setConfs(confs).setCache( + CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( + destIvyPattern).setArtifactFilter(artifactFilter).setSync(sync).setUseOrigin( + useOrigin).setMakeSymlinks(makeSymlinks)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, + String destIvyPattern, Filter artifactFilter, boolean sync, boolean useOrigin) { + try { + return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), + destFilePattern, new RetrieveOptions().setConfs(confs).setCache( + CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( + destIvyPattern).setArtifactFilter(artifactFilter).setSync(sync).setUseOrigin( + useOrigin)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, + String destIvyPattern, Filter artifactFilter) { + try { + return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), + destFilePattern, new RetrieveOptions().setConfs(confs).setCache( + CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( + destIvyPattern).setArtifactFilter(artifactFilter)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern, + String destIvyPattern) { + try { + return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), + destFilePattern, new RetrieveOptions().setConfs(confs).setCache( + CacheManager.getInstance(ivy.getSettings(), cache)).setDestIvyPattern( + destIvyPattern)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern) { + try { + return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()), + destFilePattern, new RetrieveOptions().setConfs(confs).setCache( + CacheManager.getInstance(ivy.getSettings(), cache))); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void setVariable(String varName, String value) { + ivy.setVariable(varName, value); + } + + public List sortModuleDescriptors(Collection moduleDescriptors) { + return ivy.sortModuleDescriptors(moduleDescriptors); + } + + public List sortNodes(Collection nodes) { + return ivy.sortNodes(nodes); + } + + public String substitute(String str) { + return ivy.substitute(str); + } + + private String[] splitConfs(String conf) { + if (conf == null || "".equals(conf)) { + return null; + } + String[] confs = conf.split(","); + for (int i = 0; i < confs.length; i++) { + confs[i] = confs[i].trim(); + } + return confs; + } + + //CheckStyle:ParameterNumberCheck ON +} diff --git a/src/java/org/apache/ivy/Main.java b/src/java/org/apache/ivy/Main.java index 68e27c45..9a7dcda0 100644 --- a/src/java/org/apache/ivy/Main.java +++ b/src/java/org/apache/ivy/Main.java @@ -1,447 +1,447 @@ -/* - * 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; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.GnuParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.deliver.DeliverOptions; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.publish.PublishOptions; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.retrieve.RetrieveOptions; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; -import org.apache.ivy.plugins.report.XmlReportParser; -import org.apache.ivy.util.DefaultMessageImpl; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.url.CredentialsStore; -import org.apache.ivy.util.url.URLHandler; -import org.apache.ivy.util.url.URLHandlerDispatcher; -import org.apache.ivy.util.url.URLHandlerRegistry; - -/** - * Class used to launch ivy as a standalone tool. - *

      - * Valid arguments can be obtained with the -? argument. - */ -public final class Main { - private static final int DEPENDENCY_ARG_COUNT = 3; - - private static Options getOptions() { - Option settings = OptionBuilder.withArgName("settingsfile").hasArg().withDescription( - "use given file for settings").create("settings"); - Option conf = OptionBuilder.withArgName("settingsfile").hasArg().withDescription( - "DEPRECATED - use given file for settings").create("conf"); - Option cache = OptionBuilder.withArgName("cachedir").hasArg().withDescription( - "use given directory for cache").create("cache"); - Option ivyfile = OptionBuilder.withArgName("ivyfile").hasArg().withDescription( - "use given file as ivy file").create("ivy"); - Option dependency = OptionBuilder - .withArgName("organisation module revision") - .hasArgs() - .withDescription( - "use this instead of ivy file to do the rest " - + "of the work with this as a dependency.") - .create("dependency"); - Option confs = OptionBuilder.withArgName("configurations").hasArgs().withDescription( - "resolve given configurations").create("confs"); - Option retrieve = OptionBuilder.withArgName("retrievepattern").hasArg().withDescription( - "use given pattern as retrieve pattern").create("retrieve"); - Option cachepath = OptionBuilder - .withArgName("cachepathfile") - .hasArg() - .withDescription( - "outputs a classpath consisting of all dependencies in cache " - + "(including transitive ones) " - + "of the given ivy file to the given cachepathfile") - .create("cachepath"); - Option revision = OptionBuilder.withArgName("revision").hasArg().withDescription( - "use given revision to publish the module").create("revision"); - Option status = OptionBuilder.withArgName("status").hasArg().withDescription( - "use given status to publish the module").create("status"); - Option deliver = OptionBuilder.withArgName("ivypattern").hasArg().withDescription( - "use given pattern as resolved ivy file pattern").create("deliverto"); - Option publishResolver = OptionBuilder.withArgName("resolvername").hasArg() - .withDescription("use given resolver to publish to").create("publish"); - Option publishPattern = OptionBuilder.withArgName("artpattern").hasArg().withDescription( - "use given pattern to find artifacts to publish").create("publishpattern"); - Option realm = OptionBuilder.withArgName("realm").hasArg().withDescription( - "use given realm for HTTP AUTH").create("realm"); - Option host = OptionBuilder.withArgName("host").hasArg().withDescription( - "use given host for HTTP AUTH").create("host"); - Option username = OptionBuilder.withArgName("username").hasArg().withDescription( - "use given username for HTTP AUTH").create("username"); - Option passwd = OptionBuilder.withArgName("passwd").hasArg().withDescription( - "use given password for HTTP AUTH").create("passwd"); - Option main = OptionBuilder.withArgName("main").hasArg().withDescription( - "the main class to runtime process").create("main"); - Option args = OptionBuilder.withArgName("args").hasArgs().withDescription( - "the arguments to runtime process").create("args"); - - Options options = new Options(); - - options.addOption("debug", false, "set message level to debug"); - options.addOption("verbose", false, "set message level to verbose"); - options.addOption("warn", false, "set message level to warn"); - options.addOption("error", false, "set message level to error"); - options.addOption("novalidate", false, "do not validate ivy files against xsd"); - options.addOption("useOrigin", false, - "use original artifact location with local resolvers instead of copying to the cache"); - options.addOption("sync", false, "in conjonction with -retrieve, does a synced retrieve"); - options.addOption("m2compatible", false, "use maven2 compatibility"); - options.addOption("?", false, "display this help"); - options.addOption(conf); - options.addOption(settings); - options.addOption(confs); - options.addOption(cache); - options.addOption(ivyfile); - options.addOption(dependency); - options.addOption(retrieve); - options.addOption(cachepath); - options.addOption(revision); - options.addOption(status); - options.addOption(deliver); - options.addOption(publishResolver); - options.addOption(publishPattern); - options.addOption(realm); - options.addOption(host); - options.addOption(username); - options.addOption(passwd); - options.addOption(main); - options.addOption(args); - - return options; - } - - public static void main(String[] args) throws Exception { - Options options = getOptions(); - - CommandLineParser parser = new GnuParser(); - try { - // parse the command line arguments - CommandLine line = parser.parse(options, args); - - if (line.hasOption("?")) { - usage(options); - return; - } - - initMessage(line); - - boolean validate = line.hasOption("novalidate") ? false : true; - - Ivy ivy = Ivy.newInstance(); - IvySettings settings = initSettings(line, options, ivy); - - File cache = new File(settings.substitute(line.getOptionValue("cache", settings - .getDefaultCache().getAbsolutePath()))); - if (!cache.exists()) { - cache.mkdirs(); - } else if (!cache.isDirectory()) { - error(options, cache + " is not a directory"); - } - CacheManager cacheManager = CacheManager.getInstance(settings, cache); - - String[] confs; - if (line.hasOption("confs")) { - confs = line.getOptionValues("confs"); - } else { - confs = new String[] {"*"}; - } - - File ivyfile; - if (line.hasOption("dependency")) { - String[] dep = line.getOptionValues("dependency"); - if (dep.length != DEPENDENCY_ARG_COUNT) { - error(options, - "dependency should be expressed with exactly 3 arguments: " - + "organisation module revision"); - } - ivyfile = File.createTempFile("ivy", ".xml"); - ivyfile.deleteOnExit(); - DefaultModuleDescriptor md = DefaultModuleDescriptor - .newDefaultInstance(ModuleRevisionId.newInstance(dep[0], - dep[1] + "-caller", "working")); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, - ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true); - for (int i = 0; i < confs.length; i++) { - dd.addDependencyConfiguration("default", confs[i]); - } - md.addDependency(dd); - XmlModuleDescriptorWriter.write(md, ivyfile); - confs = new String[] {"default"}; - } else { - ivyfile = new File(settings.substitute(line.getOptionValue("ivy", "ivy.xml"))); - if (!ivyfile.exists()) { - error(options, "ivy file not found: " + ivyfile); - } else if (ivyfile.isDirectory()) { - error(options, "ivy file is not a file: " + ivyfile); - } - } - - ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs).setCache( - cacheManager).setValidate(validate).setUseOrigin(line.hasOption("useOrigin")); - ResolveReport report = ivy.resolve(ivyfile.toURL(), resolveOptions); - if (report.hasError()) { - System.exit(1); - } - ModuleDescriptor md = report.getModuleDescriptor(); - - if (confs.length == 1 && "*".equals(confs[0])) { - confs = md.getConfigurationsNames(); - } - if (line.hasOption("retrieve")) { - String retrievePattern = settings.substitute(line.getOptionValue("retrieve")); - if (retrievePattern.indexOf("[") == -1) { - retrievePattern = retrievePattern + "/lib/[conf]/[artifact].[ext]"; - } - ivy.retrieve(md.getModuleRevisionId(), retrievePattern, new RetrieveOptions() - .setConfs(confs).setCache(cacheManager).setSync(line.hasOption("sync")) - .setUseOrigin(line.hasOption("useOrigin"))); - } - if (line.hasOption("cachepath")) { - outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath", - "ivycachepath.txt")); - } - - if (line.hasOption("revision")) { - ivy.deliver(md.getResolvedModuleRevisionId(), settings.substitute(line - .getOptionValue("revision")), settings.substitute(line.getOptionValue( - "deliverto", "ivy-[revision].xml")), DeliverOptions.newInstance(settings) - .setStatus(settings.substitute(line.getOptionValue("status", "release"))) - .setValidate(validate).setCache(cacheManager)); - if (line.hasOption("publish")) { - ivy.publish(md.getResolvedModuleRevisionId(), Collections.singleton(settings - .substitute(line.getOptionValue("publishpattern", - "distrib/[type]s/[artifact]-[revision].[ext]"))), line - .getOptionValue("publish"), new PublishOptions().setCache(cacheManager) - .setPubrevision(settings.substitute(line.getOptionValue("revision"))) - .setValidate(validate).setSrcIvyPattern( - settings.substitute(line.getOptionValue("deliverto", - "ivy-[revision].xml")))); - } - } - if (line.hasOption("main")) { - // merge -args and left over args - String[] fargs = line.getOptionValues("args"); - if (fargs == null) { - fargs = new String[0]; - } - String[] extra = line.getArgs(); - if (extra == null) { - extra = new String[0]; - } - String[] params = new String[fargs.length + extra.length]; - System.arraycopy(fargs, 0, params, 0, fargs.length); - System.arraycopy(extra, 0, params, fargs.length, extra.length); - // invoke with given main class and merged params - invoke(ivy, cache, md, confs, line.getOptionValue("main"), params); - } - } catch (ParseException exp) { - // oops, something went wrong - System.err.println("Parsing failed. Reason: " + exp.getMessage()); - - usage(options); - } - } - - private static IvySettings initSettings(CommandLine line, Options options, Ivy ivy) - throws java.text.ParseException, IOException { - IvySettings settings = ivy.getSettings(); - settings.addAllVariables(System.getProperties()); - if (line.hasOption("m2compatible")) { - settings.setVariable("ivy.default.configuration.m2compatible", "true"); - } - - configureURLHandler(line.getOptionValue("realm", null), line.getOptionValue("host", - null), line.getOptionValue("username", null), line.getOptionValue("passwd", null)); - - String settingsPath = line.getOptionValue("settings", ""); - if ("".equals(settingsPath)) { - settingsPath = line.getOptionValue("conf", ""); - if (!"".equals(settingsPath)) { - Message.deprecated("-conf is deprecated, use -settings instead"); - } - } - if ("".equals(settingsPath)) { - ivy.configureDefault(); - } else { - File conffile = new File(settingsPath); - if (!conffile.exists()) { - error(options, "ivy configuration file not found: " + conffile); - } else if (conffile.isDirectory()) { - error(options, "ivy configuration file is not a file: " + conffile); - } - ivy.configure(conffile); - } - return settings; - } - - private static void initMessage(CommandLine line) { - if (line.hasOption("debug")) { - Message.init(new DefaultMessageImpl(Message.MSG_DEBUG)); - } else if (line.hasOption("verbose")) { - Message.init(new DefaultMessageImpl(Message.MSG_VERBOSE)); - } else if (line.hasOption("warn")) { - Message.init(new DefaultMessageImpl(Message.MSG_WARN)); - } else if (line.hasOption("error")) { - Message.init(new DefaultMessageImpl(Message.MSG_ERR)); - } else { - Message.init(new DefaultMessageImpl(Message.MSG_INFO)); - } - } - - private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, - String outFile) { - try { - String pathSeparator = System.getProperty("path.separator"); - StringBuffer buf = new StringBuffer(); - Collection all = new LinkedHashSet(); - CacheManager cacheMgr = ivy.getCacheManager(cache); - XmlReportParser parser = new XmlReportParser(); - for (int i = 0; i < confs.length; i++) { - String resolveId = ResolveOptions.getDefaultResolveId(md); - File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]); - parser.parse(report); - - Artifact[] artifacts = parser.getArtifacts(); - all.addAll(Arrays.asList(artifacts)); - } - for (Iterator iter = all.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - buf.append(ivy.getCacheManager(cache).getArchiveFileInCache(artifact) - .getCanonicalPath()); - if (iter.hasNext()) { - buf.append(pathSeparator); - } - } - PrintWriter writer = new PrintWriter(new FileOutputStream(outFile)); - writer.println(buf.toString()); - writer.close(); - System.out.println("cachepath output to " + outFile); - - } catch (Exception ex) { - throw new RuntimeException( - "impossible to build ivy cache path: " + ex.getMessage(), ex); - } - } - - private static void invoke(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, - String mainclass, String[] args) { - List urls = new ArrayList(); - - try { - Collection all = new LinkedHashSet(); - CacheManager cacheMgr = ivy.getCacheManager(cache); - XmlReportParser parser = new XmlReportParser(); - for (int i = 0; i < confs.length; i++) { - String resolveId = ResolveOptions.getDefaultResolveId(md); - File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]); - parser.parse(report); - - Artifact[] artifacts = parser.getArtifacts(); - all.addAll(Arrays.asList(artifacts)); - } - for (Iterator iter = all.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - - urls.add(cacheMgr.getArchiveFileInCache(artifact).toURL()); - } - } catch (Exception ex) { - throw new RuntimeException( - "impossible to build ivy cache path: " + ex.getMessage(), ex); - } - - URLClassLoader classLoader = new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]), - Main.class.getClassLoader()); - - try { - Class c = classLoader.loadClass(mainclass); - - Method mainMethod = c.getMethod("main", new Class[] {String[].class}); - - Thread.currentThread().setContextClassLoader(classLoader); - mainMethod.invoke(null, new Object[] {(args == null ? new String[0] : args)}); - } catch (ClassNotFoundException cnfe) { - throw new RuntimeException("Could not find class: " + mainclass, cnfe); - } catch (SecurityException e) { - throw new RuntimeException("Could not find main method: " + mainclass, e); - } catch (NoSuchMethodException e) { - throw new RuntimeException("Could not find main method: " + mainclass, e); - } catch (IllegalAccessException e) { - throw new RuntimeException("No permissions to invoke main method: " + mainclass, e); - } catch (InvocationTargetException e) { - throw new RuntimeException( - "Unexpected exception invoking main method: " + mainclass, e); - } - } - - private static void configureURLHandler(String realm, String host, String username, - String passwd) { - CredentialsStore.INSTANCE.addCredentials(realm, host, username, passwd); - - URLHandlerDispatcher dispatcher = new URLHandlerDispatcher(); - URLHandler httpHandler = URLHandlerRegistry.getHttp(); - dispatcher.setDownloader("http", httpHandler); - dispatcher.setDownloader("https", httpHandler); - URLHandlerRegistry.setDefault(dispatcher); - } - - private static void error(Options options, String msg) { - System.err.println(msg); - usage(options); - System.exit(1); - } - - private static void usage(Options options) { - // automatically generate the help statement - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("ivy", options); - } - - private Main() { - } -} +/* + * 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; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.deliver.DeliverOptions; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.publish.PublishOptions; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.retrieve.RetrieveOptions; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; +import org.apache.ivy.plugins.report.XmlReportParser; +import org.apache.ivy.util.DefaultMessageImpl; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.url.CredentialsStore; +import org.apache.ivy.util.url.URLHandler; +import org.apache.ivy.util.url.URLHandlerDispatcher; +import org.apache.ivy.util.url.URLHandlerRegistry; + +/** + * Class used to launch ivy as a standalone tool. + *

      + * Valid arguments can be obtained with the -? argument. + */ +public final class Main { + private static final int DEPENDENCY_ARG_COUNT = 3; + + private static Options getOptions() { + Option settings = OptionBuilder.withArgName("settingsfile").hasArg().withDescription( + "use given file for settings").create("settings"); + Option conf = OptionBuilder.withArgName("settingsfile").hasArg().withDescription( + "DEPRECATED - use given file for settings").create("conf"); + Option cache = OptionBuilder.withArgName("cachedir").hasArg().withDescription( + "use given directory for cache").create("cache"); + Option ivyfile = OptionBuilder.withArgName("ivyfile").hasArg().withDescription( + "use given file as ivy file").create("ivy"); + Option dependency = OptionBuilder + .withArgName("organisation module revision") + .hasArgs() + .withDescription( + "use this instead of ivy file to do the rest " + + "of the work with this as a dependency.") + .create("dependency"); + Option confs = OptionBuilder.withArgName("configurations").hasArgs().withDescription( + "resolve given configurations").create("confs"); + Option retrieve = OptionBuilder.withArgName("retrievepattern").hasArg().withDescription( + "use given pattern as retrieve pattern").create("retrieve"); + Option cachepath = OptionBuilder + .withArgName("cachepathfile") + .hasArg() + .withDescription( + "outputs a classpath consisting of all dependencies in cache " + + "(including transitive ones) " + + "of the given ivy file to the given cachepathfile") + .create("cachepath"); + Option revision = OptionBuilder.withArgName("revision").hasArg().withDescription( + "use given revision to publish the module").create("revision"); + Option status = OptionBuilder.withArgName("status").hasArg().withDescription( + "use given status to publish the module").create("status"); + Option deliver = OptionBuilder.withArgName("ivypattern").hasArg().withDescription( + "use given pattern as resolved ivy file pattern").create("deliverto"); + Option publishResolver = OptionBuilder.withArgName("resolvername").hasArg() + .withDescription("use given resolver to publish to").create("publish"); + Option publishPattern = OptionBuilder.withArgName("artpattern").hasArg().withDescription( + "use given pattern to find artifacts to publish").create("publishpattern"); + Option realm = OptionBuilder.withArgName("realm").hasArg().withDescription( + "use given realm for HTTP AUTH").create("realm"); + Option host = OptionBuilder.withArgName("host").hasArg().withDescription( + "use given host for HTTP AUTH").create("host"); + Option username = OptionBuilder.withArgName("username").hasArg().withDescription( + "use given username for HTTP AUTH").create("username"); + Option passwd = OptionBuilder.withArgName("passwd").hasArg().withDescription( + "use given password for HTTP AUTH").create("passwd"); + Option main = OptionBuilder.withArgName("main").hasArg().withDescription( + "the main class to runtime process").create("main"); + Option args = OptionBuilder.withArgName("args").hasArgs().withDescription( + "the arguments to runtime process").create("args"); + + Options options = new Options(); + + options.addOption("debug", false, "set message level to debug"); + options.addOption("verbose", false, "set message level to verbose"); + options.addOption("warn", false, "set message level to warn"); + options.addOption("error", false, "set message level to error"); + options.addOption("novalidate", false, "do not validate ivy files against xsd"); + options.addOption("useOrigin", false, + "use original artifact location with local resolvers instead of copying to the cache"); + options.addOption("sync", false, "in conjonction with -retrieve, does a synced retrieve"); + options.addOption("m2compatible", false, "use maven2 compatibility"); + options.addOption("?", false, "display this help"); + options.addOption(conf); + options.addOption(settings); + options.addOption(confs); + options.addOption(cache); + options.addOption(ivyfile); + options.addOption(dependency); + options.addOption(retrieve); + options.addOption(cachepath); + options.addOption(revision); + options.addOption(status); + options.addOption(deliver); + options.addOption(publishResolver); + options.addOption(publishPattern); + options.addOption(realm); + options.addOption(host); + options.addOption(username); + options.addOption(passwd); + options.addOption(main); + options.addOption(args); + + return options; + } + + public static void main(String[] args) throws Exception { + Options options = getOptions(); + + CommandLineParser parser = new GnuParser(); + try { + // parse the command line arguments + CommandLine line = parser.parse(options, args); + + if (line.hasOption("?")) { + usage(options); + return; + } + + initMessage(line); + + boolean validate = line.hasOption("novalidate") ? false : true; + + Ivy ivy = Ivy.newInstance(); + IvySettings settings = initSettings(line, options, ivy); + + File cache = new File(settings.substitute(line.getOptionValue("cache", settings + .getDefaultCache().getAbsolutePath()))); + if (!cache.exists()) { + cache.mkdirs(); + } else if (!cache.isDirectory()) { + error(options, cache + " is not a directory"); + } + CacheManager cacheManager = CacheManager.getInstance(settings, cache); + + String[] confs; + if (line.hasOption("confs")) { + confs = line.getOptionValues("confs"); + } else { + confs = new String[] {"*"}; + } + + File ivyfile; + if (line.hasOption("dependency")) { + String[] dep = line.getOptionValues("dependency"); + if (dep.length != DEPENDENCY_ARG_COUNT) { + error(options, + "dependency should be expressed with exactly 3 arguments: " + + "organisation module revision"); + } + ivyfile = File.createTempFile("ivy", ".xml"); + ivyfile.deleteOnExit(); + DefaultModuleDescriptor md = DefaultModuleDescriptor + .newDefaultInstance(ModuleRevisionId.newInstance(dep[0], + dep[1] + "-caller", "working")); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, + ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true); + for (int i = 0; i < confs.length; i++) { + dd.addDependencyConfiguration("default", confs[i]); + } + md.addDependency(dd); + XmlModuleDescriptorWriter.write(md, ivyfile); + confs = new String[] {"default"}; + } else { + ivyfile = new File(settings.substitute(line.getOptionValue("ivy", "ivy.xml"))); + if (!ivyfile.exists()) { + error(options, "ivy file not found: " + ivyfile); + } else if (ivyfile.isDirectory()) { + error(options, "ivy file is not a file: " + ivyfile); + } + } + + ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs).setCache( + cacheManager).setValidate(validate).setUseOrigin(line.hasOption("useOrigin")); + ResolveReport report = ivy.resolve(ivyfile.toURL(), resolveOptions); + if (report.hasError()) { + System.exit(1); + } + ModuleDescriptor md = report.getModuleDescriptor(); + + if (confs.length == 1 && "*".equals(confs[0])) { + confs = md.getConfigurationsNames(); + } + if (line.hasOption("retrieve")) { + String retrievePattern = settings.substitute(line.getOptionValue("retrieve")); + if (retrievePattern.indexOf("[") == -1) { + retrievePattern = retrievePattern + "/lib/[conf]/[artifact].[ext]"; + } + ivy.retrieve(md.getModuleRevisionId(), retrievePattern, new RetrieveOptions() + .setConfs(confs).setCache(cacheManager).setSync(line.hasOption("sync")) + .setUseOrigin(line.hasOption("useOrigin"))); + } + if (line.hasOption("cachepath")) { + outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath", + "ivycachepath.txt")); + } + + if (line.hasOption("revision")) { + ivy.deliver(md.getResolvedModuleRevisionId(), settings.substitute(line + .getOptionValue("revision")), settings.substitute(line.getOptionValue( + "deliverto", "ivy-[revision].xml")), DeliverOptions.newInstance(settings) + .setStatus(settings.substitute(line.getOptionValue("status", "release"))) + .setValidate(validate).setCache(cacheManager)); + if (line.hasOption("publish")) { + ivy.publish(md.getResolvedModuleRevisionId(), Collections.singleton(settings + .substitute(line.getOptionValue("publishpattern", + "distrib/[type]s/[artifact]-[revision].[ext]"))), line + .getOptionValue("publish"), new PublishOptions().setCache(cacheManager) + .setPubrevision(settings.substitute(line.getOptionValue("revision"))) + .setValidate(validate).setSrcIvyPattern( + settings.substitute(line.getOptionValue("deliverto", + "ivy-[revision].xml")))); + } + } + if (line.hasOption("main")) { + // merge -args and left over args + String[] fargs = line.getOptionValues("args"); + if (fargs == null) { + fargs = new String[0]; + } + String[] extra = line.getArgs(); + if (extra == null) { + extra = new String[0]; + } + String[] params = new String[fargs.length + extra.length]; + System.arraycopy(fargs, 0, params, 0, fargs.length); + System.arraycopy(extra, 0, params, fargs.length, extra.length); + // invoke with given main class and merged params + invoke(ivy, cache, md, confs, line.getOptionValue("main"), params); + } + } catch (ParseException exp) { + // oops, something went wrong + System.err.println("Parsing failed. Reason: " + exp.getMessage()); + + usage(options); + } + } + + private static IvySettings initSettings(CommandLine line, Options options, Ivy ivy) + throws java.text.ParseException, IOException { + IvySettings settings = ivy.getSettings(); + settings.addAllVariables(System.getProperties()); + if (line.hasOption("m2compatible")) { + settings.setVariable("ivy.default.configuration.m2compatible", "true"); + } + + configureURLHandler(line.getOptionValue("realm", null), line.getOptionValue("host", + null), line.getOptionValue("username", null), line.getOptionValue("passwd", null)); + + String settingsPath = line.getOptionValue("settings", ""); + if ("".equals(settingsPath)) { + settingsPath = line.getOptionValue("conf", ""); + if (!"".equals(settingsPath)) { + Message.deprecated("-conf is deprecated, use -settings instead"); + } + } + if ("".equals(settingsPath)) { + ivy.configureDefault(); + } else { + File conffile = new File(settingsPath); + if (!conffile.exists()) { + error(options, "ivy configuration file not found: " + conffile); + } else if (conffile.isDirectory()) { + error(options, "ivy configuration file is not a file: " + conffile); + } + ivy.configure(conffile); + } + return settings; + } + + private static void initMessage(CommandLine line) { + if (line.hasOption("debug")) { + Message.init(new DefaultMessageImpl(Message.MSG_DEBUG)); + } else if (line.hasOption("verbose")) { + Message.init(new DefaultMessageImpl(Message.MSG_VERBOSE)); + } else if (line.hasOption("warn")) { + Message.init(new DefaultMessageImpl(Message.MSG_WARN)); + } else if (line.hasOption("error")) { + Message.init(new DefaultMessageImpl(Message.MSG_ERR)); + } else { + Message.init(new DefaultMessageImpl(Message.MSG_INFO)); + } + } + + private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, + String outFile) { + try { + String pathSeparator = System.getProperty("path.separator"); + StringBuffer buf = new StringBuffer(); + Collection all = new LinkedHashSet(); + CacheManager cacheMgr = ivy.getCacheManager(cache); + XmlReportParser parser = new XmlReportParser(); + for (int i = 0; i < confs.length; i++) { + String resolveId = ResolveOptions.getDefaultResolveId(md); + File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]); + parser.parse(report); + + Artifact[] artifacts = parser.getArtifacts(); + all.addAll(Arrays.asList(artifacts)); + } + for (Iterator iter = all.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + buf.append(ivy.getCacheManager(cache).getArchiveFileInCache(artifact) + .getCanonicalPath()); + if (iter.hasNext()) { + buf.append(pathSeparator); + } + } + PrintWriter writer = new PrintWriter(new FileOutputStream(outFile)); + writer.println(buf.toString()); + writer.close(); + System.out.println("cachepath output to " + outFile); + + } catch (Exception ex) { + throw new RuntimeException( + "impossible to build ivy cache path: " + ex.getMessage(), ex); + } + } + + private static void invoke(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, + String mainclass, String[] args) { + List urls = new ArrayList(); + + try { + Collection all = new LinkedHashSet(); + CacheManager cacheMgr = ivy.getCacheManager(cache); + XmlReportParser parser = new XmlReportParser(); + for (int i = 0; i < confs.length; i++) { + String resolveId = ResolveOptions.getDefaultResolveId(md); + File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]); + parser.parse(report); + + Artifact[] artifacts = parser.getArtifacts(); + all.addAll(Arrays.asList(artifacts)); + } + for (Iterator iter = all.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + + urls.add(cacheMgr.getArchiveFileInCache(artifact).toURL()); + } + } catch (Exception ex) { + throw new RuntimeException( + "impossible to build ivy cache path: " + ex.getMessage(), ex); + } + + URLClassLoader classLoader = new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]), + Main.class.getClassLoader()); + + try { + Class c = classLoader.loadClass(mainclass); + + Method mainMethod = c.getMethod("main", new Class[] {String[].class}); + + Thread.currentThread().setContextClassLoader(classLoader); + mainMethod.invoke(null, new Object[] {(args == null ? new String[0] : args)}); + } catch (ClassNotFoundException cnfe) { + throw new RuntimeException("Could not find class: " + mainclass, cnfe); + } catch (SecurityException e) { + throw new RuntimeException("Could not find main method: " + mainclass, e); + } catch (NoSuchMethodException e) { + throw new RuntimeException("Could not find main method: " + mainclass, e); + } catch (IllegalAccessException e) { + throw new RuntimeException("No permissions to invoke main method: " + mainclass, e); + } catch (InvocationTargetException e) { + throw new RuntimeException( + "Unexpected exception invoking main method: " + mainclass, e); + } + } + + private static void configureURLHandler(String realm, String host, String username, + String passwd) { + CredentialsStore.INSTANCE.addCredentials(realm, host, username, passwd); + + URLHandlerDispatcher dispatcher = new URLHandlerDispatcher(); + URLHandler httpHandler = URLHandlerRegistry.getHttp(); + dispatcher.setDownloader("http", httpHandler); + dispatcher.setDownloader("https", httpHandler); + URLHandlerRegistry.setDefault(dispatcher); + } + + private static void error(Options options, String msg) { + System.err.println(msg); + usage(options); + System.exit(1); + } + + private static void usage(Options options) { + // automatically generate the help statement + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("ivy", options); + } + + private Main() { + } +} diff --git a/src/java/org/apache/ivy/ant/AddPathTask.java b/src/java/org/apache/ivy/ant/AddPathTask.java index ab1d0884..b736877c 100644 --- a/src/java/org/apache/ivy/ant/AddPathTask.java +++ b/src/java/org/apache/ivy/ant/AddPathTask.java @@ -1,103 +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.ant; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.DirSet; -import org.apache.tools.ant.types.FileList; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Path.PathElement; - -/** - * This task is not directly related to ivy, but is useful in some modular build systems. The idea - * is to be able to contribute new sub path elements to an existing path. - */ -public class AddPathTask extends Task { - private String _topath; - - private boolean _first = false; - - private Path _toadd; - - public String getTopath() { - return _topath; - } - - public void setTopath(String topath) { - _topath = topath; - } - - public void setProject(Project project) { - super.setProject(project); - _toadd = new Path(project); - } - - public void execute() throws BuildException { - Object element = getProject().getReference(_topath); - if (element == null) { - throw new BuildException("destination path not found: " + _topath); - } - if (!(element instanceof Path)) { - throw new BuildException("destination path is not a path: " + element.getClass()); - } - Path dest = (Path) element; - if (_first) { - // now way to add path elements at te beginning of the existing path: we do the opposite - // and replace the reference - _toadd.append(dest); - getProject().addReference(_topath, _toadd); - } else { - dest.append(_toadd); - } - } - - public void add(Path path) throws BuildException { - _toadd.add(path); - } - - public void addDirset(DirSet dset) throws BuildException { - _toadd.addDirset(dset); - } - - public void addFilelist(FileList fl) throws BuildException { - _toadd.addFilelist(fl); - } - - public void addFileset(FileSet fs) throws BuildException { - _toadd.addFileset(fs); - } - - public Path createPath() throws BuildException { - return _toadd.createPath(); - } - - public PathElement createPathElement() throws BuildException { - return _toadd.createPathElement(); - } - - public boolean isFirst() { - return _first; - } - - public void setFirst(boolean first) { - _first = first; - } -} +/* + * 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 org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.DirSet; +import org.apache.tools.ant.types.FileList; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Path.PathElement; + +/** + * This task is not directly related to ivy, but is useful in some modular build systems. The idea + * is to be able to contribute new sub path elements to an existing path. + */ +public class AddPathTask extends Task { + private String _topath; + + private boolean _first = false; + + private Path _toadd; + + public String getTopath() { + return _topath; + } + + public void setTopath(String topath) { + _topath = topath; + } + + public void setProject(Project project) { + super.setProject(project); + _toadd = new Path(project); + } + + public void execute() throws BuildException { + Object element = getProject().getReference(_topath); + if (element == null) { + throw new BuildException("destination path not found: " + _topath); + } + if (!(element instanceof Path)) { + throw new BuildException("destination path is not a path: " + element.getClass()); + } + Path dest = (Path) element; + if (_first) { + // now way to add path elements at te beginning of the existing path: we do the opposite + // and replace the reference + _toadd.append(dest); + getProject().addReference(_topath, _toadd); + } else { + dest.append(_toadd); + } + } + + public void add(Path path) throws BuildException { + _toadd.add(path); + } + + public void addDirset(DirSet dset) throws BuildException { + _toadd.addDirset(dset); + } + + public void addFilelist(FileList fl) throws BuildException { + _toadd.addFilelist(fl); + } + + public void addFileset(FileSet fs) throws BuildException { + _toadd.addFileset(fs); + } + + public Path createPath() throws BuildException { + return _toadd.createPath(); + } + + public PathElement createPathElement() throws BuildException { + return _toadd.createPathElement(); + } + + public boolean isFirst() { + return _first; + } + + public void setFirst(boolean first) { + _first = first; + } +} diff --git a/src/java/org/apache/ivy/ant/AntBuildTrigger.java b/src/java/org/apache/ivy/ant/AntBuildTrigger.java index 83b858ab..c6a922de 100644 --- a/src/java/org/apache/ivy/ant/AntBuildTrigger.java +++ b/src/java/org/apache/ivy/ant/AntBuildTrigger.java @@ -1,161 +1,161 @@ -/* - * 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.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.plugins.trigger.AbstractTrigger; -import org.apache.ivy.plugins.trigger.Trigger; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.MessageImpl; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Ant; -import org.apache.tools.ant.taskdefs.Property; - -/** - * Triggers an ant build on an event occurence. Example of use: Triggers an ant build for any dependency - * in asked in latest.integration, just before resolving the dependency. - * - * @see AntCallTrigger - * @since 1.4 - */ -public class AntBuildTrigger extends AbstractTrigger implements Trigger { - private boolean _onlyonce = true; - - private String _target = null; - - private Collection _builds = new ArrayList(); - - private String _buildFilePattern; - - private String _prefix; - - public void progress(IvyEvent event) { - File f = getBuildFile(event); - if (f.exists()) { - if (_onlyonce && isBuilt(f)) { - Message.verbose("target build file already built, skipping: " + f); - } else { - Ant ant = new Ant(); - Project project = (Project) IvyContext.getContext().peek( - IvyTask.ANT_PROJECT_CONTEXT_KEY); - if (project == null) { - project = new Project(); - project.init(); - } - - ant.setProject(project); - ant.setTaskName("ant"); - - ant.setAntfile(f.getAbsolutePath()); - ant.setInheritAll(false); - String target = getTarget(); - if (target != null) { - ant.setTarget(target); - } - Map atts = event.getAttributes(); - for (Iterator iter = atts.keySet().iterator(); iter.hasNext();) { - String key = (String) iter.next(); - String value = (String) atts.get(key); - Property p = ant.createProperty(); - p.setName(_prefix == null ? key : _prefix + key); - p.setValue(value); - } - - Message.verbose("triggering build: " + f + " target=" + target + " for " + event); - MessageImpl impl = IvyContext.getContext().getMessageImpl(); - try { - IvyContext.getContext().setMessageImpl(null); - try { - ant.execute(); - } catch (BuildException e) { - Message.verbose("Exception occurred while executing target " + target); - e.printStackTrace(); // TODO: remove when finished debugging - throw e; - } - markBuilt(f); - } finally { - IvyContext.getContext().setMessageImpl(impl); - } - - Message.debug("triggered build finished: " + f + " target=" + target + " for " - + event); - } - } else { - Message.verbose("no build file found for dependency, skipping: " + f); - } - } - - private void markBuilt(File f) { - _builds.add(f.getAbsolutePath()); - } - - private boolean isBuilt(File f) { - return _builds.contains(f.getAbsolutePath()); - } - - private File getBuildFile(IvyEvent event) { - return new File(IvyPatternHelper.substituteTokens(getBuildFilePattern(), event - .getAttributes())); - } - - public String getBuildFilePattern() { - return _buildFilePattern; - } - - public void setAntfile(String pattern) { - _buildFilePattern = pattern; - } - - public String getTarget() { - return _target; - } - - public void setTarget(String target) { - _target = target; - } - - public boolean isOnlyonce() { - return _onlyonce; - } - - public void setOnlyonce(boolean onlyonce) { - _onlyonce = onlyonce; - } - - public String getPrefix() { - return _prefix; - } - - public void setPrefix(String prefix) { - _prefix = prefix; - if (!prefix.endsWith(".")) { - _prefix += "."; - } - } -} +/* + * 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.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.plugins.trigger.AbstractTrigger; +import org.apache.ivy.plugins.trigger.Trigger; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.MessageImpl; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Ant; +import org.apache.tools.ant.taskdefs.Property; + +/** + * Triggers an ant build on an event occurence. Example of use: Triggers an ant build for any dependency + * in asked in latest.integration, just before resolving the dependency. + * + * @see AntCallTrigger + * @since 1.4 + */ +public class AntBuildTrigger extends AbstractTrigger implements Trigger { + private boolean _onlyonce = true; + + private String _target = null; + + private Collection _builds = new ArrayList(); + + private String _buildFilePattern; + + private String _prefix; + + public void progress(IvyEvent event) { + File f = getBuildFile(event); + if (f.exists()) { + if (_onlyonce && isBuilt(f)) { + Message.verbose("target build file already built, skipping: " + f); + } else { + Ant ant = new Ant(); + Project project = (Project) IvyContext.getContext().peek( + IvyTask.ANT_PROJECT_CONTEXT_KEY); + if (project == null) { + project = new Project(); + project.init(); + } + + ant.setProject(project); + ant.setTaskName("ant"); + + ant.setAntfile(f.getAbsolutePath()); + ant.setInheritAll(false); + String target = getTarget(); + if (target != null) { + ant.setTarget(target); + } + Map atts = event.getAttributes(); + for (Iterator iter = atts.keySet().iterator(); iter.hasNext();) { + String key = (String) iter.next(); + String value = (String) atts.get(key); + Property p = ant.createProperty(); + p.setName(_prefix == null ? key : _prefix + key); + p.setValue(value); + } + + Message.verbose("triggering build: " + f + " target=" + target + " for " + event); + MessageImpl impl = IvyContext.getContext().getMessageImpl(); + try { + IvyContext.getContext().setMessageImpl(null); + try { + ant.execute(); + } catch (BuildException e) { + Message.verbose("Exception occurred while executing target " + target); + e.printStackTrace(); // TODO: remove when finished debugging + throw e; + } + markBuilt(f); + } finally { + IvyContext.getContext().setMessageImpl(impl); + } + + Message.debug("triggered build finished: " + f + " target=" + target + " for " + + event); + } + } else { + Message.verbose("no build file found for dependency, skipping: " + f); + } + } + + private void markBuilt(File f) { + _builds.add(f.getAbsolutePath()); + } + + private boolean isBuilt(File f) { + return _builds.contains(f.getAbsolutePath()); + } + + private File getBuildFile(IvyEvent event) { + return new File(IvyPatternHelper.substituteTokens(getBuildFilePattern(), event + .getAttributes())); + } + + public String getBuildFilePattern() { + return _buildFilePattern; + } + + public void setAntfile(String pattern) { + _buildFilePattern = pattern; + } + + public String getTarget() { + return _target; + } + + public void setTarget(String target) { + _target = target; + } + + public boolean isOnlyonce() { + return _onlyonce; + } + + public void setOnlyonce(boolean onlyonce) { + _onlyonce = onlyonce; + } + + public String getPrefix() { + return _prefix; + } + + public void setPrefix(String prefix) { + _prefix = prefix; + if (!prefix.endsWith(".")) { + _prefix += "."; + } + } +} diff --git a/src/java/org/apache/ivy/ant/AntCallTrigger.java b/src/java/org/apache/ivy/ant/AntCallTrigger.java index e71dae67..ae6f01de 100644 --- a/src/java/org/apache/ivy/ant/AntCallTrigger.java +++ b/src/java/org/apache/ivy/ant/AntCallTrigger.java @@ -1,128 +1,128 @@ -/* - * 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.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.plugins.trigger.AbstractTrigger; -import org.apache.ivy.plugins.trigger.Trigger; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.MessageImpl; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.CallTarget; -import org.apache.tools.ant.taskdefs.Property; - -/** - * Triggers an call to an ant target on an event occurence. This trigger only works when ivy is - * called from an ant build file, otherwise the trigger only log a failure. Example of use in an - * ivysettings file: Triggers a call to the target "unzip" for any downloaded artifact of type zip - * - * @see AntBuildTrigger - * @since 1.4 - */ -public class AntCallTrigger extends AbstractTrigger implements Trigger { - private boolean _onlyonce = true; - - private String _target = null; - - private Collection _calls = new ArrayList(); - - private String _prefix; - - public void progress(IvyEvent event) { - Project project = (Project) IvyContext.getContext().peek(IvyTask.ANT_PROJECT_CONTEXT_KEY); - if (project == null) { - Message.info("ant call trigger can only be used from an ant build. Ignoring."); - return; - } - if (_onlyonce && isTriggered(event)) { - Message.verbose("call already triggered for this event, skipping: " + event); - } else { - CallTarget call = new CallTarget(); - - call.setProject(project); - call.setTaskName("antcall"); - - Map attributes = event.getAttributes(); - String target = IvyPatternHelper.substituteTokens(getTarget(), attributes); - call.setTarget(target); - - for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { - String key = (String) iter.next(); - String value = (String) attributes.get(key); - Property p = call.createParam(); - p.setName(_prefix == null ? key : _prefix + key); - p.setValue(value == null ? "" : value); - } - - Message.verbose("triggering ant call: target=" + target + " for " + event); - MessageImpl impl = IvyContext.getContext().getMessageImpl(); - try { - IvyContext.getContext().setMessageImpl(null); - call.execute(); - markTriggered(event); - } finally { - IvyContext.getContext().setMessageImpl(impl); - } - - Message.debug("triggered ant call finished: target=" + target + " for " + event); - } - } - - private void markTriggered(IvyEvent event) { - _calls.add(event); - } - - private boolean isTriggered(IvyEvent event) { - return _calls.contains(event); - } - - public String getTarget() { - return _target; - } - - public void setTarget(String target) { - _target = target; - } - - public boolean isOnlyonce() { - return _onlyonce; - } - - public void setOnlyonce(boolean onlyonce) { - _onlyonce = onlyonce; - } - - public String getPrefix() { - return _prefix; - } - - public void setPrefix(String prefix) { - _prefix = prefix; - if (!prefix.endsWith(".")) { - _prefix += "."; - } - } -} +/* + * 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.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.plugins.trigger.AbstractTrigger; +import org.apache.ivy.plugins.trigger.Trigger; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.MessageImpl; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.CallTarget; +import org.apache.tools.ant.taskdefs.Property; + +/** + * Triggers an call to an ant target on an event occurence. This trigger only works when ivy is + * called from an ant build file, otherwise the trigger only log a failure. Example of use in an + * ivysettings file: Triggers a call to the target "unzip" for any downloaded artifact of type zip + * + * @see AntBuildTrigger + * @since 1.4 + */ +public class AntCallTrigger extends AbstractTrigger implements Trigger { + private boolean _onlyonce = true; + + private String _target = null; + + private Collection _calls = new ArrayList(); + + private String _prefix; + + public void progress(IvyEvent event) { + Project project = (Project) IvyContext.getContext().peek(IvyTask.ANT_PROJECT_CONTEXT_KEY); + if (project == null) { + Message.info("ant call trigger can only be used from an ant build. Ignoring."); + return; + } + if (_onlyonce && isTriggered(event)) { + Message.verbose("call already triggered for this event, skipping: " + event); + } else { + CallTarget call = new CallTarget(); + + call.setProject(project); + call.setTaskName("antcall"); + + Map attributes = event.getAttributes(); + String target = IvyPatternHelper.substituteTokens(getTarget(), attributes); + call.setTarget(target); + + for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { + String key = (String) iter.next(); + String value = (String) attributes.get(key); + Property p = call.createParam(); + p.setName(_prefix == null ? key : _prefix + key); + p.setValue(value == null ? "" : value); + } + + Message.verbose("triggering ant call: target=" + target + " for " + event); + MessageImpl impl = IvyContext.getContext().getMessageImpl(); + try { + IvyContext.getContext().setMessageImpl(null); + call.execute(); + markTriggered(event); + } finally { + IvyContext.getContext().setMessageImpl(impl); + } + + Message.debug("triggered ant call finished: target=" + target + " for " + event); + } + } + + private void markTriggered(IvyEvent event) { + _calls.add(event); + } + + private boolean isTriggered(IvyEvent event) { + return _calls.contains(event); + } + + public String getTarget() { + return _target; + } + + public void setTarget(String target) { + _target = target; + } + + public boolean isOnlyonce() { + return _onlyonce; + } + + public void setOnlyonce(boolean onlyonce) { + _onlyonce = onlyonce; + } + + public String getPrefix() { + return _prefix; + } + + public void setPrefix(String prefix) { + _prefix = prefix; + if (!prefix.endsWith(".")) { + _prefix += "."; + } + } +} diff --git a/src/java/org/apache/ivy/ant/AntMessageImpl.java b/src/java/org/apache/ivy/ant/AntMessageImpl.java index a7ef8ffa..3c48cec8 100644 --- a/src/java/org/apache/ivy/ant/AntMessageImpl.java +++ b/src/java/org/apache/ivy/ant/AntMessageImpl.java @@ -1,106 +1,106 @@ -/* - * 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 org.apache.ivy.util.Message; -import org.apache.ivy.util.MessageImpl; -import org.apache.tools.ant.BuildEvent; -import org.apache.tools.ant.BuildListener; -import org.apache.tools.ant.Task; - -/** - * Implementation of the simple message facility for ant. - */ -public class AntMessageImpl implements MessageImpl { - private Task _task; - - private static long _lastProgressFlush = 0; - - private static StringBuffer _buf = new StringBuffer(); - - /** - * @param task - */ - public AntMessageImpl(Task task) { - _task = task; - task.getProject().addBuildListener(new BuildListener() { - private int stackDepth = 0; - - public void buildFinished(BuildEvent event) { - } - - public void buildStarted(BuildEvent event) { - } - - public void targetStarted(BuildEvent event) { - } - - public void targetFinished(BuildEvent event) { - } - - public void taskStarted(BuildEvent event) { - stackDepth++; - } - - public void taskFinished(BuildEvent event) { - // NB: There is somtimes task created by an other task - // in that case, we should not uninit Message. The log should stay associated - // with the initial task, except if it was an antcall, ant or subant target - // NB2 : Testing the identity of the task is not enought, event.getTask() return - // an instance of UnknownElement is wrapping the concrete instance - if (stackDepth == 0) { - Message.uninit(); - event.getProject().removeBuildListener(this); - } - stackDepth--; - } - - public void messageLogged(BuildEvent event) { - } - }); - } - - public void log(String msg, int level) { - _task.log(msg, level); - } - - public void rawlog(String msg, int level) { - _task.getProject().log(msg, level); - } - - public void progress() { - _buf.append("."); - if (_lastProgressFlush == 0) { - _lastProgressFlush = System.currentTimeMillis(); - } - if (_task != null) { - // log with ant causes a new line -> we do it only once in a while - if (System.currentTimeMillis() - _lastProgressFlush > 1500) { - _task.log(_buf.toString()); - _buf.setLength(0); - _lastProgressFlush = System.currentTimeMillis(); - } - } - } - - public void endProgress(String msg) { - _task.log(_buf + msg); - _buf.setLength(0); - _lastProgressFlush = 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. + * + */ +package org.apache.ivy.ant; + +import org.apache.ivy.util.Message; +import org.apache.ivy.util.MessageImpl; +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildListener; +import org.apache.tools.ant.Task; + +/** + * Implementation of the simple message facility for ant. + */ +public class AntMessageImpl implements MessageImpl { + private Task _task; + + private static long _lastProgressFlush = 0; + + private static StringBuffer _buf = new StringBuffer(); + + /** + * @param task + */ + public AntMessageImpl(Task task) { + _task = task; + task.getProject().addBuildListener(new BuildListener() { + private int stackDepth = 0; + + public void buildFinished(BuildEvent event) { + } + + public void buildStarted(BuildEvent event) { + } + + public void targetStarted(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + } + + public void taskStarted(BuildEvent event) { + stackDepth++; + } + + public void taskFinished(BuildEvent event) { + // NB: There is somtimes task created by an other task + // in that case, we should not uninit Message. The log should stay associated + // with the initial task, except if it was an antcall, ant or subant target + // NB2 : Testing the identity of the task is not enought, event.getTask() return + // an instance of UnknownElement is wrapping the concrete instance + if (stackDepth == 0) { + Message.uninit(); + event.getProject().removeBuildListener(this); + } + stackDepth--; + } + + public void messageLogged(BuildEvent event) { + } + }); + } + + public void log(String msg, int level) { + _task.log(msg, level); + } + + public void rawlog(String msg, int level) { + _task.getProject().log(msg, level); + } + + public void progress() { + _buf.append("."); + if (_lastProgressFlush == 0) { + _lastProgressFlush = System.currentTimeMillis(); + } + if (_task != null) { + // log with ant causes a new line -> we do it only once in a while + if (System.currentTimeMillis() - _lastProgressFlush > 1500) { + _task.log(_buf.toString()); + _buf.setLength(0); + _lastProgressFlush = System.currentTimeMillis(); + } + } + } + + public void endProgress(String msg) { + _task.log(_buf + msg); + _buf.setLength(0); + _lastProgressFlush = 0; + } +} diff --git a/src/java/org/apache/ivy/ant/IvyArtifactProperty.java b/src/java/org/apache/ivy/ant/IvyArtifactProperty.java index 06a81fe6..71f522a5 100644 --- a/src/java/org/apache/ivy/ant/IvyArtifactProperty.java +++ b/src/java/org/apache/ivy/ant/IvyArtifactProperty.java @@ -1,82 +1,82 @@ -/* - * 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 org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.plugins.report.XmlReportParser; -import org.apache.tools.ant.BuildException; - -/** - * Set a set of ant properties according to the last artifact resolved - */ -public class IvyArtifactProperty extends IvyPostResolveTask { - private String _name; - - private String _value; - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public String getValue() { - return _value; - } - - public void setValue(String value) { - _value = value; - } - - public void doExecute() throws BuildException { - prepareAndCheck(); - - try { - CacheManager cacheMgr = getIvyInstance().getCacheManager(getCache()); - String[] confs = splitConfs(getConf()); - String resolveId = getResolveId(); - if (resolveId == null) { - resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId()); - } - XmlReportParser parser = new XmlReportParser(); - for (int i = 0; i < confs.length; i++) { - File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]); - parser.parse(report); - - Artifact[] artifacts = parser.getArtifacts(); - for (int j = 0; j < artifacts.length; j++) { - Artifact artifact = artifacts[j]; - String name = IvyPatternHelper.substitute(getSettings().substitute(getName()), - artifact, confs[i]); - String value = IvyPatternHelper.substitute( - getSettings().substitute(getValue()), artifact, confs[i]); - getProject().setProperty(name, value); - } - } - } catch (Exception ex) { - throw new BuildException("impossible to add artifact properties: " + ex, ex); - } - } -} +/* + * 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 org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.plugins.report.XmlReportParser; +import org.apache.tools.ant.BuildException; + +/** + * Set a set of ant properties according to the last artifact resolved + */ +public class IvyArtifactProperty extends IvyPostResolveTask { + private String _name; + + private String _value; + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public String getValue() { + return _value; + } + + public void setValue(String value) { + _value = value; + } + + public void doExecute() throws BuildException { + prepareAndCheck(); + + try { + CacheManager cacheMgr = getIvyInstance().getCacheManager(getCache()); + String[] confs = splitConfs(getConf()); + String resolveId = getResolveId(); + if (resolveId == null) { + resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId()); + } + XmlReportParser parser = new XmlReportParser(); + for (int i = 0; i < confs.length; i++) { + File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]); + parser.parse(report); + + Artifact[] artifacts = parser.getArtifacts(); + for (int j = 0; j < artifacts.length; j++) { + Artifact artifact = artifacts[j]; + String name = IvyPatternHelper.substitute(getSettings().substitute(getName()), + artifact, confs[i]); + String value = IvyPatternHelper.substitute( + getSettings().substitute(getValue()), artifact, confs[i]); + getProject().setProperty(name, value); + } + } + } catch (Exception ex) { + throw new BuildException("impossible to add artifact properties: " + ex, ex); + } + } +} diff --git a/src/java/org/apache/ivy/ant/IvyArtifactReport.java b/src/java/org/apache/ivy/ant/IvyArtifactReport.java index 222829e4..71f2534f 100644 --- a/src/java/org/apache/ivy/ant/IvyArtifactReport.java +++ b/src/java/org/apache/ivy/ant/IvyArtifactReport.java @@ -1,299 +1,299 @@ -/* - * 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.FileOutputStream; -import java.io.IOException; -import java.text.ParseException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import javax.xml.transform.OutputKeys; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamResult; - -import org.apache.ivy.core.cache.ArtifactOrigin; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.retrieve.RetrieveOptions; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; - -/** - * Generates a report of all artifacts involved during the last resolve. - */ -public class IvyArtifactReport extends IvyPostResolveTask { - private File _tofile; - - private String _pattern; - - public File getTofile() { - return _tofile; - } - - public void setTofile(File tofile) { - _tofile = tofile; - } - - public String getPattern() { - return _pattern; - } - - public void setPattern(String pattern) { - _pattern = pattern; - } - - public void doExecute() throws BuildException { - prepareAndCheck(); - if (_tofile == null) { - throw new BuildException( - "no destination file name: please provide it through parameter 'tofile'"); - } - - _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern"); - - try { - String[] confs = splitConfs(getConf()); - CacheManager cacheManager = CacheManager.getInstance(getSettings(), getCache()); - ModuleDescriptor md = null; - if (getResolveId() != null) { - md = (ModuleDescriptor) getResolvedDescriptor(getResolveId()); - } else { - md = (ModuleDescriptor) getResolvedDescriptor(getOrganisation(), getModule(), false); - } - IvyNode[] dependencies = getIvyInstance().getResolveEngine().getDependencies( - md, - new ResolveOptions().setConfs(confs).setCache(cacheManager).setResolveId( - getResolveId()).setValidate(doValidate(getSettings())), null); - - Map artifactsToCopy = getIvyInstance().getRetrieveEngine().determineArtifactsToCopy( - ModuleRevisionId.newInstance(getOrganisation(), getModule(), getRevision()), - _pattern, - new RetrieveOptions().setConfs(confs).setResolveId(getResolveId()).setCache( - cacheManager)); - - Map moduleRevToArtifactsMap = new HashMap(); - for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - Set moduleRevArtifacts = (Set) moduleRevToArtifactsMap.get(artifact - .getModuleRevisionId()); - if (moduleRevArtifacts == null) { - moduleRevArtifacts = new HashSet(); - moduleRevToArtifactsMap.put(artifact.getModuleRevisionId(), moduleRevArtifacts); - } - moduleRevArtifacts.add(artifact); - } - - generateXml(cacheManager, dependencies, moduleRevToArtifactsMap, artifactsToCopy); - } catch (ParseException e) { - log(e.getMessage(), Project.MSG_ERR); - throw new BuildException("syntax errors in ivy file: " + e, e); - } catch (IOException e) { - throw new BuildException("impossible to generate report: " + e, e); - } - } - - private void generateXml(CacheManager cache, IvyNode[] dependencies, - Map moduleRevToArtifactsMap, Map artifactsToCopy) { - try { - FileOutputStream fileOuputStream = new FileOutputStream(_tofile); - try { - TransformerHandler saxHandler = createTransformerHandler(fileOuputStream); - - saxHandler.startDocument(); - saxHandler.startElement(null, "modules", "modules", new AttributesImpl()); - - for (int i = 0; i < dependencies.length; i++) { - IvyNode dependency = dependencies[i]; - if (dependency.getModuleRevision() == null || dependency.isCompletelyEvicted()) { - continue; - } - - startModule(saxHandler, dependency); - - Set artifactsOfModuleRev = (Set) moduleRevToArtifactsMap.get(dependency - .getModuleRevision().getId()); - if (artifactsOfModuleRev != null) { - for (Iterator iter = artifactsOfModuleRev.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - - startArtifact(saxHandler, artifact); - - writeOriginLocationIfPresent(cache, saxHandler, artifact); - - writeCacheLocation(cache, saxHandler, artifact); - - Set artifactDestPaths = (Set) artifactsToCopy.get(artifact); - for (Iterator iterator = artifactDestPaths.iterator(); iterator - .hasNext();) { - String artifactDestPath = (String) iterator.next(); - writeRetrieveLocation(saxHandler, artifactDestPath); - } - saxHandler.endElement(null, "artifact", "artifact"); - } - } - saxHandler.endElement(null, "module", "module"); - } - saxHandler.endElement(null, "modules", "modules"); - saxHandler.endDocument(); - } finally { - fileOuputStream.close(); - } - } catch (SAXException e) { - throw new BuildException("impossible to generate report", e); - } catch (TransformerConfigurationException e) { - throw new BuildException("impossible to generate report", e); - } catch (IOException e) { - throw new BuildException("impossible to generate report", e); - } - } - - private TransformerHandler createTransformerHandler(FileOutputStream fileOuputStream) - throws TransformerFactoryConfigurationError, TransformerConfigurationException, - SAXException { - SAXTransformerFactory transformerFact = (SAXTransformerFactory) SAXTransformerFactory - .newInstance(); - TransformerHandler saxHandler = transformerFact.newTransformerHandler(); - saxHandler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - saxHandler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes"); - saxHandler.setResult(new StreamResult(fileOuputStream)); - return saxHandler; - } - - private void startModule(TransformerHandler saxHandler, IvyNode dependency) throws SAXException { - AttributesImpl moduleAttrs = new AttributesImpl(); - moduleAttrs.addAttribute(null, "organisation", "organisation", "CDATA", dependency - .getModuleId().getOrganisation()); - moduleAttrs.addAttribute(null, "name", "name", "CDATA", dependency.getModuleId().getName()); - moduleAttrs.addAttribute(null, "rev", "rev", "CDATA", dependency.getModuleRevision() - .getId().getRevision()); - moduleAttrs.addAttribute(null, "status", "status", "CDATA", dependency.getModuleRevision() - .getDescriptor().getStatus()); - saxHandler.startElement(null, "module", "module", moduleAttrs); - } - - private void startArtifact(TransformerHandler saxHandler, Artifact artifact) - throws SAXException { - AttributesImpl artifactAttrs = new AttributesImpl(); - artifactAttrs.addAttribute(null, "name", "name", "CDATA", artifact.getName()); - artifactAttrs.addAttribute(null, "ext", "ext", "CDATA", artifact.getExt()); - artifactAttrs.addAttribute(null, "type", "type", "CDATA", artifact.getType()); - saxHandler.startElement(null, "artifact", "artifact", artifactAttrs); - } - - private void writeOriginLocationIfPresent(CacheManager cache, TransformerHandler saxHandler, - Artifact artifact) throws IOException, SAXException { - ArtifactOrigin origin = cache.getSavedArtifactOrigin(artifact); - if (origin != null) { - String originName = origin.getLocation(); - boolean isOriginLocal = origin.isLocal(); - - String originLocation; - AttributesImpl originLocationAttrs = new AttributesImpl(); - if (isOriginLocal) { - originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "true"); - File originNameFile = new File(originName); - StringBuffer originNameWithSlashes = new StringBuffer(1000); - replaceFileSeparatorWithSlash(originNameFile, originNameWithSlashes); - originLocation = originNameWithSlashes.toString(); - } else { - originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "false"); - originLocation = originName; - } - saxHandler - .startElement(null, "origin-location", "origin-location", originLocationAttrs); - char[] originLocationAsChars = originLocation.toCharArray(); - saxHandler.characters(originLocationAsChars, 0, originLocationAsChars.length); - saxHandler.endElement(null, "origin-location", "origin-location"); - } - } - - private void writeCacheLocation(CacheManager cache, TransformerHandler saxHandler, - Artifact artifact) throws SAXException { - ArtifactOrigin origin = cache.getSavedArtifactOrigin(artifact); - File archiveInCacheFile = cache.getArchiveFileInCache(artifact, origin, false); - StringBuffer archiveInCachePathWithSlashes = new StringBuffer(1000); - replaceFileSeparatorWithSlash(archiveInCacheFile, archiveInCachePathWithSlashes); - - saxHandler.startElement(null, "cache-location", "cache-location", new AttributesImpl()); - char[] archiveInCachePathAsChars = archiveInCachePathWithSlashes.toString().toCharArray(); - saxHandler.characters(archiveInCachePathAsChars, 0, archiveInCachePathAsChars.length); - saxHandler.endElement(null, "cache-location", "cache-location"); - } - - private void writeRetrieveLocation(TransformerHandler saxHandler, String artifactDestPath) - throws SAXException { - artifactDestPath = removeLeadingPath(getProject().getBaseDir(), new File(artifactDestPath)); - StringBuffer artifactDestPathWithSlashes = new StringBuffer(1000); - replaceFileSeparatorWithSlash(new File(artifactDestPath), artifactDestPathWithSlashes); - - saxHandler.startElement(null, "retrieve-location", "retrieve-location", - new AttributesImpl()); - char[] artifactDestPathAsChars = artifactDestPathWithSlashes.toString().toCharArray(); - saxHandler.characters(artifactDestPathAsChars, 0, artifactDestPathAsChars.length); - saxHandler.endElement(null, "retrieve-location", "retrieve-location"); - } - - private void replaceFileSeparatorWithSlash(File file, StringBuffer resultPath) { - if (file.getParentFile() != null) { - replaceFileSeparatorWithSlash(file.getParentFile(), resultPath); - resultPath.append('/'); - } - - if (file.getName().equals("")) { - String fileSeparator = System.getProperty("file.separator"); - String path = file.getPath(); - while (path.endsWith(fileSeparator)) { - path = path.substring(0, path.length() - fileSeparator.length()); - } - resultPath.append(path); - } else { - resultPath.append(file.getName()); - } - } - - // method largely inspired by ant 1.6.5 FileUtils method - public String removeLeadingPath(File leading, File path) { - String l = leading.getAbsolutePath(); - String p = path.getAbsolutePath(); - if (l.equals(p)) { - return ""; - } - - // ensure that l ends with a / - // so we never think /foo was a parent directory of /foobar - if (!l.endsWith(File.separator)) { - l += File.separator; - } - return (p.startsWith(l)) ? p.substring(l.length()) : p; - } - -} +/* + * 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.FileOutputStream; +import java.io.IOException; +import java.text.ParseException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamResult; + +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.retrieve.RetrieveOptions; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Generates a report of all artifacts involved during the last resolve. + */ +public class IvyArtifactReport extends IvyPostResolveTask { + private File _tofile; + + private String _pattern; + + public File getTofile() { + return _tofile; + } + + public void setTofile(File tofile) { + _tofile = tofile; + } + + public String getPattern() { + return _pattern; + } + + public void setPattern(String pattern) { + _pattern = pattern; + } + + public void doExecute() throws BuildException { + prepareAndCheck(); + if (_tofile == null) { + throw new BuildException( + "no destination file name: please provide it through parameter 'tofile'"); + } + + _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern"); + + try { + String[] confs = splitConfs(getConf()); + CacheManager cacheManager = CacheManager.getInstance(getSettings(), getCache()); + ModuleDescriptor md = null; + if (getResolveId() != null) { + md = (ModuleDescriptor) getResolvedDescriptor(getResolveId()); + } else { + md = (ModuleDescriptor) getResolvedDescriptor(getOrganisation(), getModule(), false); + } + IvyNode[] dependencies = getIvyInstance().getResolveEngine().getDependencies( + md, + new ResolveOptions().setConfs(confs).setCache(cacheManager).setResolveId( + getResolveId()).setValidate(doValidate(getSettings())), null); + + Map artifactsToCopy = getIvyInstance().getRetrieveEngine().determineArtifactsToCopy( + ModuleRevisionId.newInstance(getOrganisation(), getModule(), getRevision()), + _pattern, + new RetrieveOptions().setConfs(confs).setResolveId(getResolveId()).setCache( + cacheManager)); + + Map moduleRevToArtifactsMap = new HashMap(); + for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + Set moduleRevArtifacts = (Set) moduleRevToArtifactsMap.get(artifact + .getModuleRevisionId()); + if (moduleRevArtifacts == null) { + moduleRevArtifacts = new HashSet(); + moduleRevToArtifactsMap.put(artifact.getModuleRevisionId(), moduleRevArtifacts); + } + moduleRevArtifacts.add(artifact); + } + + generateXml(cacheManager, dependencies, moduleRevToArtifactsMap, artifactsToCopy); + } catch (ParseException e) { + log(e.getMessage(), Project.MSG_ERR); + throw new BuildException("syntax errors in ivy file: " + e, e); + } catch (IOException e) { + throw new BuildException("impossible to generate report: " + e, e); + } + } + + private void generateXml(CacheManager cache, IvyNode[] dependencies, + Map moduleRevToArtifactsMap, Map artifactsToCopy) { + try { + FileOutputStream fileOuputStream = new FileOutputStream(_tofile); + try { + TransformerHandler saxHandler = createTransformerHandler(fileOuputStream); + + saxHandler.startDocument(); + saxHandler.startElement(null, "modules", "modules", new AttributesImpl()); + + for (int i = 0; i < dependencies.length; i++) { + IvyNode dependency = dependencies[i]; + if (dependency.getModuleRevision() == null || dependency.isCompletelyEvicted()) { + continue; + } + + startModule(saxHandler, dependency); + + Set artifactsOfModuleRev = (Set) moduleRevToArtifactsMap.get(dependency + .getModuleRevision().getId()); + if (artifactsOfModuleRev != null) { + for (Iterator iter = artifactsOfModuleRev.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + + startArtifact(saxHandler, artifact); + + writeOriginLocationIfPresent(cache, saxHandler, artifact); + + writeCacheLocation(cache, saxHandler, artifact); + + Set artifactDestPaths = (Set) artifactsToCopy.get(artifact); + for (Iterator iterator = artifactDestPaths.iterator(); iterator + .hasNext();) { + String artifactDestPath = (String) iterator.next(); + writeRetrieveLocation(saxHandler, artifactDestPath); + } + saxHandler.endElement(null, "artifact", "artifact"); + } + } + saxHandler.endElement(null, "module", "module"); + } + saxHandler.endElement(null, "modules", "modules"); + saxHandler.endDocument(); + } finally { + fileOuputStream.close(); + } + } catch (SAXException e) { + throw new BuildException("impossible to generate report", e); + } catch (TransformerConfigurationException e) { + throw new BuildException("impossible to generate report", e); + } catch (IOException e) { + throw new BuildException("impossible to generate report", e); + } + } + + private TransformerHandler createTransformerHandler(FileOutputStream fileOuputStream) + throws TransformerFactoryConfigurationError, TransformerConfigurationException, + SAXException { + SAXTransformerFactory transformerFact = (SAXTransformerFactory) SAXTransformerFactory + .newInstance(); + TransformerHandler saxHandler = transformerFact.newTransformerHandler(); + saxHandler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + saxHandler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes"); + saxHandler.setResult(new StreamResult(fileOuputStream)); + return saxHandler; + } + + private void startModule(TransformerHandler saxHandler, IvyNode dependency) throws SAXException { + AttributesImpl moduleAttrs = new AttributesImpl(); + moduleAttrs.addAttribute(null, "organisation", "organisation", "CDATA", dependency + .getModuleId().getOrganisation()); + moduleAttrs.addAttribute(null, "name", "name", "CDATA", dependency.getModuleId().getName()); + moduleAttrs.addAttribute(null, "rev", "rev", "CDATA", dependency.getModuleRevision() + .getId().getRevision()); + moduleAttrs.addAttribute(null, "status", "status", "CDATA", dependency.getModuleRevision() + .getDescriptor().getStatus()); + saxHandler.startElement(null, "module", "module", moduleAttrs); + } + + private void startArtifact(TransformerHandler saxHandler, Artifact artifact) + throws SAXException { + AttributesImpl artifactAttrs = new AttributesImpl(); + artifactAttrs.addAttribute(null, "name", "name", "CDATA", artifact.getName()); + artifactAttrs.addAttribute(null, "ext", "ext", "CDATA", artifact.getExt()); + artifactAttrs.addAttribute(null, "type", "type", "CDATA", artifact.getType()); + saxHandler.startElement(null, "artifact", "artifact", artifactAttrs); + } + + private void writeOriginLocationIfPresent(CacheManager cache, TransformerHandler saxHandler, + Artifact artifact) throws IOException, SAXException { + ArtifactOrigin origin = cache.getSavedArtifactOrigin(artifact); + if (origin != null) { + String originName = origin.getLocation(); + boolean isOriginLocal = origin.isLocal(); + + String originLocation; + AttributesImpl originLocationAttrs = new AttributesImpl(); + if (isOriginLocal) { + originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "true"); + File originNameFile = new File(originName); + StringBuffer originNameWithSlashes = new StringBuffer(1000); + replaceFileSeparatorWithSlash(originNameFile, originNameWithSlashes); + originLocation = originNameWithSlashes.toString(); + } else { + originLocationAttrs.addAttribute(null, "is-local", "is-local", "CDATA", "false"); + originLocation = originName; + } + saxHandler + .startElement(null, "origin-location", "origin-location", originLocationAttrs); + char[] originLocationAsChars = originLocation.toCharArray(); + saxHandler.characters(originLocationAsChars, 0, originLocationAsChars.length); + saxHandler.endElement(null, "origin-location", "origin-location"); + } + } + + private void writeCacheLocation(CacheManager cache, TransformerHandler saxHandler, + Artifact artifact) throws SAXException { + ArtifactOrigin origin = cache.getSavedArtifactOrigin(artifact); + File archiveInCacheFile = cache.getArchiveFileInCache(artifact, origin, false); + StringBuffer archiveInCachePathWithSlashes = new StringBuffer(1000); + replaceFileSeparatorWithSlash(archiveInCacheFile, archiveInCachePathWithSlashes); + + saxHandler.startElement(null, "cache-location", "cache-location", new AttributesImpl()); + char[] archiveInCachePathAsChars = archiveInCachePathWithSlashes.toString().toCharArray(); + saxHandler.characters(archiveInCachePathAsChars, 0, archiveInCachePathAsChars.length); + saxHandler.endElement(null, "cache-location", "cache-location"); + } + + private void writeRetrieveLocation(TransformerHandler saxHandler, String artifactDestPath) + throws SAXException { + artifactDestPath = removeLeadingPath(getProject().getBaseDir(), new File(artifactDestPath)); + StringBuffer artifactDestPathWithSlashes = new StringBuffer(1000); + replaceFileSeparatorWithSlash(new File(artifactDestPath), artifactDestPathWithSlashes); + + saxHandler.startElement(null, "retrieve-location", "retrieve-location", + new AttributesImpl()); + char[] artifactDestPathAsChars = artifactDestPathWithSlashes.toString().toCharArray(); + saxHandler.characters(artifactDestPathAsChars, 0, artifactDestPathAsChars.length); + saxHandler.endElement(null, "retrieve-location", "retrieve-location"); + } + + private void replaceFileSeparatorWithSlash(File file, StringBuffer resultPath) { + if (file.getParentFile() != null) { + replaceFileSeparatorWithSlash(file.getParentFile(), resultPath); + resultPath.append('/'); + } + + if (file.getName().equals("")) { + String fileSeparator = System.getProperty("file.separator"); + String path = file.getPath(); + while (path.endsWith(fileSeparator)) { + path = path.substring(0, path.length() - fileSeparator.length()); + } + resultPath.append(path); + } else { + resultPath.append(file.getName()); + } + } + + // method largely inspired by ant 1.6.5 FileUtils method + public String removeLeadingPath(File leading, File path) { + String l = leading.getAbsolutePath(); + String p = path.getAbsolutePath(); + if (l.equals(p)) { + return ""; + } + + // ensure that l ends with a / + // so we never think /foo was a parent directory of /foobar + if (!l.endsWith(File.separator)) { + l += File.separator; + } + return (p.startsWith(l)) ? p.substring(l.length()) : p; + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyBuildList.java b/src/java/org/apache/ivy/ant/IvyBuildList.java index 7a8795a0..bbdc1ffd 100644 --- a/src/java/org/apache/ivy/ant/IvyBuildList.java +++ b/src/java/org/apache/ivy/ant/IvyBuildList.java @@ -1,434 +1,434 @@ -/* - * 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.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.ivy.util.Message; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.types.FileList; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Path; - -/** - * Creates an ant filelist of files (usually build.xml) ordered according to the dependencies - * declared in ivy files. - */ -public class IvyBuildList extends IvyTask { - private List buildFileSets = new ArrayList(); // List (FileSet) - - private String reference; - - private boolean haltOnError = true; - - private boolean skipBuildWithoutIvy = false; - - private boolean reverse = false; - - private String ivyFilePath; - - private String root = "*"; - - private boolean excludeRoot = false; - - private String leaf = "*"; - - private String delimiter = ","; - - private boolean excludeLeaf = false; - - public void addFileset(FileSet buildFiles) { - buildFileSets.add(buildFiles); - } - - public String getReference() { - return reference; - } - - public void setReference(String reference) { - this.reference = reference; - } - - public String getRoot() { - return root; - } - - public void setRoot(String root) { - this.root = root; - } - - public boolean isExcludeRoot() { - return excludeRoot; - } - - public void setExcludeRoot(boolean root) { - excludeRoot = root; - } - - public String getLeaf() { - return leaf; - } - - public void setLeaf(String leaf) { - this.leaf = leaf; - } - - public boolean isExcludeLeaf() { - return excludeLeaf; - } - - public void setExcludeLeaf(boolean excludeLeaf) { - this.excludeLeaf = excludeLeaf; - } - - public String getDelimiter() { - return delimiter; - } - - public void setDelimiter(String delimiter) { - this.delimiter = delimiter; - } - - public void doExecute() throws BuildException { - if (reference == null) { - throw new BuildException("reference should be provided in ivy build list"); - } - if (buildFileSets.isEmpty()) { - throw new BuildException( - "at least one nested fileset should be provided in ivy build list"); - } - - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - - ivyFilePath = getProperty(ivyFilePath, settings, "ivy.buildlist.ivyfilepath"); - - Path path = new Path(getProject()); - - Map buildFiles = new HashMap(); // Map (ModuleDescriptor -> File buildFile) - Map mdsMap = new LinkedHashMap(); // Map (String moduleName -> ModuleDescriptor) - List independent = new ArrayList(); - - Set rootModuleNames = new LinkedHashSet(); - if (!"*".equals(root)) { - StringTokenizer st = new StringTokenizer(root, delimiter); - while (st.hasMoreTokens()) { - rootModuleNames.add(st.nextToken()); - } - } - - Set leafModuleNames = new LinkedHashSet(); - if (!"*".equals(leaf)) { - StringTokenizer st = new StringTokenizer(leaf, delimiter); - while (st.hasMoreTokens()) { - leafModuleNames.add(st.nextToken()); - } - } - - for (ListIterator iter = buildFileSets.listIterator(); iter.hasNext();) { - FileSet fs = (FileSet) iter.next(); - DirectoryScanner ds = fs.getDirectoryScanner(getProject()); - String[] builds = ds.getIncludedFiles(); - for (int i = 0; i < builds.length; i++) { - File buildFile = new File(ds.getBasedir(), builds[i]); - File ivyFile = getIvyFileFor(buildFile); - if (!ivyFile.exists()) { - if (skipBuildWithoutIvy) { - Message.debug("skipping " + buildFile + ": ivy file " + ivyFile - + " doesn't exist"); - } else { - Message.verbose("no ivy file for " + buildFile + ": ivyfile=" + ivyFile - + ": adding it at the beginning of the path"); - Message - .verbose("\t(set skipbuildwithoutivy to true if you don't want this file to be added to the path)"); - independent.add(buildFile); - } - } else { - try { - ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance() - .parseDescriptor(settings, ivyFile.toURL(), doValidate(settings)); - buildFiles.put(md, buildFile); - mdsMap.put(md.getModuleRevisionId().getModuleId().getName(), md); - Message.debug("Add " + md.getModuleRevisionId().getModuleId()); - } catch (Exception ex) { - if (haltOnError) { - throw new BuildException("impossible to parse ivy file for " - + buildFile + ": ivyfile=" + ivyFile + " exception=" + ex, ex); - } else { - Message.warn("impossible to parse ivy file for " + buildFile - + ": ivyfile=" + ivyFile + " exception=" + ex.getMessage()); - Message.info("\t=> adding it at the beginning of the path"); - independent.add(buildFile); - } - } - } - } - } - - List leafModuleDescriptors = convertModuleNamesToModuleDescriptors(mdsMap, leafModuleNames, - "leaf"); - List rootModuleDescriptors = convertModuleNamesToModuleDescriptors(mdsMap, rootModuleNames, - "root"); - - Collection mds = new ArrayList(mdsMap.values()); - if (!rootModuleDescriptors.isEmpty()) { - Message.info("Filtering modules based on roots " + rootModuleNames); - mds = filterModulesFromRoot(mds, rootModuleDescriptors); - } - if (!leafModuleDescriptors.isEmpty()) { - Message.info("Filtering modules based on leafs " + leafModuleNames); - mds = filterModulesFromLeaf(mds, leafModuleDescriptors); - } - - List sortedModules = ivy.sortModuleDescriptors(mds); - - for (ListIterator iter = independent.listIterator(); iter.hasNext();) { - File buildFile = (File) iter.next(); - addBuildFile(path, buildFile); - } - if (isReverse()) { - Collections.reverse(sortedModules); - } - StringBuffer order = new StringBuffer(); - for (ListIterator iter = sortedModules.listIterator(); iter.hasNext();) { - ModuleDescriptor md = (ModuleDescriptor) iter.next(); - order.append(md.getModuleRevisionId().getModuleId()); - if (iter.hasNext()) { - order.append(", "); - } - File buildFile = (File) buildFiles.get(md); - addBuildFile(path, buildFile); - } - - getProject().addReference(getReference(), path); - getProject().setProperty("ivy.sorted.modules", order.toString()); - } - - private List convertModuleNamesToModuleDescriptors(Map mdsMap, Set moduleNames, String kind) { - List mds = new ArrayList(); - for (Iterator iter = moduleNames.iterator(); iter.hasNext();) { - String name = (String) iter.next(); - ModuleDescriptor md = (ModuleDescriptor) mdsMap.get(name); - if (md == null) { - throw new BuildException("unable to find " + kind + " module " + name - + " in build fileset"); - } - mds.add(md); - } - return mds; - } - - /** - * Returns a collection of ModuleDescriptors that are conatined in the input collection of - * ModuleDescriptors and upon which the root module depends - * - * @param mds - * input collection of ModuleDescriptors - * @param rootmd - * root module - * @return filtered list of modules - */ - private Collection filterModulesFromRoot(Collection mds, List rootmds) { - // Make a map of ModuleId objects -> ModuleDescriptors - Map moduleIdMap = new HashMap(); - for (Iterator iter = mds.iterator(); iter.hasNext();) { - ModuleDescriptor md = ((ModuleDescriptor) iter.next()); - moduleIdMap.put(md.getModuleRevisionId().getModuleId(), md); - } - - // recursively process the nodes - Set toKeep = new LinkedHashSet(); - - Iterator it = rootmds.iterator(); - while (it.hasNext()) { - ModuleDescriptor rootmd = (ModuleDescriptor) it.next(); - processFilterNodeFromRoot(rootmd, toKeep, moduleIdMap); - // With the excluderoot attribute set to true, take the rootmd out of the toKeep set. - if (excludeRoot) { - Message.verbose("Excluded module " - + rootmd.getModuleRevisionId().getModuleId().getName()); - toKeep.remove(rootmd); - } - } - - // just for logging - for (Iterator iter = toKeep.iterator(); iter.hasNext();) { - ModuleDescriptor md = ((ModuleDescriptor) iter.next()); - Message.verbose("Kept module " + md.getModuleRevisionId().getModuleId().getName()); - } - - return toKeep; - } - - /** - * Adds the current node to the toKeep collection and then processes the each of the direct - * dependencies of this node that appear in the moduleIdMap (indicating that the dependency is - * part of this BuildList) - * - * @param node - * the node to be processed - * @param toKeep - * the set of ModuleDescriptors that should be kept - * @param moduleIdMap - * reference mapping of moduleId to ModuleDescriptor that are part of the BuildList - */ - private void processFilterNodeFromRoot(ModuleDescriptor node, Set toKeep, Map moduleIdMap) { - toKeep.add(node); - - DependencyDescriptor[] deps = node.getDependencies(); - for (int i = 0; i < deps.length; i++) { - ModuleId id = deps[i].getDependencyId(); - if (moduleIdMap.get(id) != null) { - processFilterNodeFromRoot((ModuleDescriptor) moduleIdMap.get(id), toKeep, - moduleIdMap); - } - } - } - - /** - * Returns a collection of ModuleDescriptors that are conatined in the input collection of - * ModuleDescriptors which depends on the leaf module - * - * @param mds - * input collection of ModuleDescriptors - * @param leafmd - * leaf module - * @return filtered list of modules - */ - private Collection filterModulesFromLeaf(Collection mds, List leafmds) { - // Make a map of ModuleId objects -> ModuleDescriptors - Map moduleIdMap = new HashMap(); - for (Iterator iter = mds.iterator(); iter.hasNext();) { - ModuleDescriptor md = ((ModuleDescriptor) iter.next()); - moduleIdMap.put(md.getModuleRevisionId().getModuleId(), md); - } - - // recursively process the nodes - Set toKeep = new LinkedHashSet(); - Iterator it = leafmds.iterator(); - while (it.hasNext()) { - ModuleDescriptor leafmd = (ModuleDescriptor) it.next(); - // With the excludeleaf attribute set to true, take the rootmd out of the toKeep set. - if (excludeLeaf) { - Message.verbose("Excluded module " - + leafmd.getModuleRevisionId().getModuleId().getName()); - } else { - toKeep.add(leafmd); - } - processFilterNodeFromLeaf(leafmd, toKeep, moduleIdMap); - } - - // just for logging - for (Iterator iter = toKeep.iterator(); iter.hasNext();) { - ModuleDescriptor md = ((ModuleDescriptor) iter.next()); - Message.verbose("Kept module " + md.getModuleRevisionId().getModuleId().getName()); - } - - return toKeep; - } - - /** - * Search in the moduleIdMap modules depending on node, add them to the toKeep set and process - * them recursively. - * - * @param node - * the node to be processed - * @param toKeep - * the set of ModuleDescriptors that should be kept - * @param moduleIdMap - * reference mapping of moduleId to ModuleDescriptor that are part of the BuildList - */ - private void processFilterNodeFromLeaf(ModuleDescriptor node, Set toKeep, Map moduleIdMap) { - for (Iterator iter = moduleIdMap.values().iterator(); iter.hasNext();) { - ModuleDescriptor md = (ModuleDescriptor) iter.next(); - DependencyDescriptor[] deps = md.getDependencies(); - for (int i = 0; i < deps.length; i++) { - ModuleId id = deps[i].getDependencyId(); - if (node.getModuleRevisionId().getModuleId().equals(id) && !toKeep.contains(md)) { - toKeep.add(md); - processFilterNodeFromLeaf(md, toKeep, moduleIdMap); - } - } - } - } - - private void addBuildFile(Path path, File buildFile) { - FileList fl = new FileList(); - fl.setDir(buildFile.getParentFile()); - FileList.FileName fileName = new FileList.FileName(); - fileName.setName(buildFile.getName()); - fl.addConfiguredFile(fileName); - path.addFilelist(fl); - } - - private File getIvyFileFor(File buildFile) { - return new File(buildFile.getParentFile(), ivyFilePath); - } - - public boolean isHaltonerror() { - return haltOnError; - } - - public void setHaltonerror(boolean haltOnError) { - this.haltOnError = haltOnError; - } - - public String getIvyfilepath() { - return ivyFilePath; - } - - public void setIvyfilepath(String ivyFilePath) { - this.ivyFilePath = ivyFilePath; - } - - public boolean isSkipbuildwithoutivy() { - return skipBuildWithoutIvy; - } - - public void setSkipbuildwithoutivy(boolean skipBuildFilesWithoutIvy) { - this.skipBuildWithoutIvy = skipBuildFilesWithoutIvy; - } - - public boolean isReverse() { - return reverse; - } - - public void setReverse(boolean reverse) { - this.reverse = reverse; - } - -} +/* + * 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.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.ivy.util.Message; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.FileList; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Path; + +/** + * Creates an ant filelist of files (usually build.xml) ordered according to the dependencies + * declared in ivy files. + */ +public class IvyBuildList extends IvyTask { + private List buildFileSets = new ArrayList(); // List (FileSet) + + private String reference; + + private boolean haltOnError = true; + + private boolean skipBuildWithoutIvy = false; + + private boolean reverse = false; + + private String ivyFilePath; + + private String root = "*"; + + private boolean excludeRoot = false; + + private String leaf = "*"; + + private String delimiter = ","; + + private boolean excludeLeaf = false; + + public void addFileset(FileSet buildFiles) { + buildFileSets.add(buildFiles); + } + + public String getReference() { + return reference; + } + + public void setReference(String reference) { + this.reference = reference; + } + + public String getRoot() { + return root; + } + + public void setRoot(String root) { + this.root = root; + } + + public boolean isExcludeRoot() { + return excludeRoot; + } + + public void setExcludeRoot(boolean root) { + excludeRoot = root; + } + + public String getLeaf() { + return leaf; + } + + public void setLeaf(String leaf) { + this.leaf = leaf; + } + + public boolean isExcludeLeaf() { + return excludeLeaf; + } + + public void setExcludeLeaf(boolean excludeLeaf) { + this.excludeLeaf = excludeLeaf; + } + + public String getDelimiter() { + return delimiter; + } + + public void setDelimiter(String delimiter) { + this.delimiter = delimiter; + } + + public void doExecute() throws BuildException { + if (reference == null) { + throw new BuildException("reference should be provided in ivy build list"); + } + if (buildFileSets.isEmpty()) { + throw new BuildException( + "at least one nested fileset should be provided in ivy build list"); + } + + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + + ivyFilePath = getProperty(ivyFilePath, settings, "ivy.buildlist.ivyfilepath"); + + Path path = new Path(getProject()); + + Map buildFiles = new HashMap(); // Map (ModuleDescriptor -> File buildFile) + Map mdsMap = new LinkedHashMap(); // Map (String moduleName -> ModuleDescriptor) + List independent = new ArrayList(); + + Set rootModuleNames = new LinkedHashSet(); + if (!"*".equals(root)) { + StringTokenizer st = new StringTokenizer(root, delimiter); + while (st.hasMoreTokens()) { + rootModuleNames.add(st.nextToken()); + } + } + + Set leafModuleNames = new LinkedHashSet(); + if (!"*".equals(leaf)) { + StringTokenizer st = new StringTokenizer(leaf, delimiter); + while (st.hasMoreTokens()) { + leafModuleNames.add(st.nextToken()); + } + } + + for (ListIterator iter = buildFileSets.listIterator(); iter.hasNext();) { + FileSet fs = (FileSet) iter.next(); + DirectoryScanner ds = fs.getDirectoryScanner(getProject()); + String[] builds = ds.getIncludedFiles(); + for (int i = 0; i < builds.length; i++) { + File buildFile = new File(ds.getBasedir(), builds[i]); + File ivyFile = getIvyFileFor(buildFile); + if (!ivyFile.exists()) { + if (skipBuildWithoutIvy) { + Message.debug("skipping " + buildFile + ": ivy file " + ivyFile + + " doesn't exist"); + } else { + Message.verbose("no ivy file for " + buildFile + ": ivyfile=" + ivyFile + + ": adding it at the beginning of the path"); + Message + .verbose("\t(set skipbuildwithoutivy to true if you don't want this file to be added to the path)"); + independent.add(buildFile); + } + } else { + try { + ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance() + .parseDescriptor(settings, ivyFile.toURL(), doValidate(settings)); + buildFiles.put(md, buildFile); + mdsMap.put(md.getModuleRevisionId().getModuleId().getName(), md); + Message.debug("Add " + md.getModuleRevisionId().getModuleId()); + } catch (Exception ex) { + if (haltOnError) { + throw new BuildException("impossible to parse ivy file for " + + buildFile + ": ivyfile=" + ivyFile + " exception=" + ex, ex); + } else { + Message.warn("impossible to parse ivy file for " + buildFile + + ": ivyfile=" + ivyFile + " exception=" + ex.getMessage()); + Message.info("\t=> adding it at the beginning of the path"); + independent.add(buildFile); + } + } + } + } + } + + List leafModuleDescriptors = convertModuleNamesToModuleDescriptors(mdsMap, leafModuleNames, + "leaf"); + List rootModuleDescriptors = convertModuleNamesToModuleDescriptors(mdsMap, rootModuleNames, + "root"); + + Collection mds = new ArrayList(mdsMap.values()); + if (!rootModuleDescriptors.isEmpty()) { + Message.info("Filtering modules based on roots " + rootModuleNames); + mds = filterModulesFromRoot(mds, rootModuleDescriptors); + } + if (!leafModuleDescriptors.isEmpty()) { + Message.info("Filtering modules based on leafs " + leafModuleNames); + mds = filterModulesFromLeaf(mds, leafModuleDescriptors); + } + + List sortedModules = ivy.sortModuleDescriptors(mds); + + for (ListIterator iter = independent.listIterator(); iter.hasNext();) { + File buildFile = (File) iter.next(); + addBuildFile(path, buildFile); + } + if (isReverse()) { + Collections.reverse(sortedModules); + } + StringBuffer order = new StringBuffer(); + for (ListIterator iter = sortedModules.listIterator(); iter.hasNext();) { + ModuleDescriptor md = (ModuleDescriptor) iter.next(); + order.append(md.getModuleRevisionId().getModuleId()); + if (iter.hasNext()) { + order.append(", "); + } + File buildFile = (File) buildFiles.get(md); + addBuildFile(path, buildFile); + } + + getProject().addReference(getReference(), path); + getProject().setProperty("ivy.sorted.modules", order.toString()); + } + + private List convertModuleNamesToModuleDescriptors(Map mdsMap, Set moduleNames, String kind) { + List mds = new ArrayList(); + for (Iterator iter = moduleNames.iterator(); iter.hasNext();) { + String name = (String) iter.next(); + ModuleDescriptor md = (ModuleDescriptor) mdsMap.get(name); + if (md == null) { + throw new BuildException("unable to find " + kind + " module " + name + + " in build fileset"); + } + mds.add(md); + } + return mds; + } + + /** + * Returns a collection of ModuleDescriptors that are conatined in the input collection of + * ModuleDescriptors and upon which the root module depends + * + * @param mds + * input collection of ModuleDescriptors + * @param rootmd + * root module + * @return filtered list of modules + */ + private Collection filterModulesFromRoot(Collection mds, List rootmds) { + // Make a map of ModuleId objects -> ModuleDescriptors + Map moduleIdMap = new HashMap(); + for (Iterator iter = mds.iterator(); iter.hasNext();) { + ModuleDescriptor md = ((ModuleDescriptor) iter.next()); + moduleIdMap.put(md.getModuleRevisionId().getModuleId(), md); + } + + // recursively process the nodes + Set toKeep = new LinkedHashSet(); + + Iterator it = rootmds.iterator(); + while (it.hasNext()) { + ModuleDescriptor rootmd = (ModuleDescriptor) it.next(); + processFilterNodeFromRoot(rootmd, toKeep, moduleIdMap); + // With the excluderoot attribute set to true, take the rootmd out of the toKeep set. + if (excludeRoot) { + Message.verbose("Excluded module " + + rootmd.getModuleRevisionId().getModuleId().getName()); + toKeep.remove(rootmd); + } + } + + // just for logging + for (Iterator iter = toKeep.iterator(); iter.hasNext();) { + ModuleDescriptor md = ((ModuleDescriptor) iter.next()); + Message.verbose("Kept module " + md.getModuleRevisionId().getModuleId().getName()); + } + + return toKeep; + } + + /** + * Adds the current node to the toKeep collection and then processes the each of the direct + * dependencies of this node that appear in the moduleIdMap (indicating that the dependency is + * part of this BuildList) + * + * @param node + * the node to be processed + * @param toKeep + * the set of ModuleDescriptors that should be kept + * @param moduleIdMap + * reference mapping of moduleId to ModuleDescriptor that are part of the BuildList + */ + private void processFilterNodeFromRoot(ModuleDescriptor node, Set toKeep, Map moduleIdMap) { + toKeep.add(node); + + DependencyDescriptor[] deps = node.getDependencies(); + for (int i = 0; i < deps.length; i++) { + ModuleId id = deps[i].getDependencyId(); + if (moduleIdMap.get(id) != null) { + processFilterNodeFromRoot((ModuleDescriptor) moduleIdMap.get(id), toKeep, + moduleIdMap); + } + } + } + + /** + * Returns a collection of ModuleDescriptors that are conatined in the input collection of + * ModuleDescriptors which depends on the leaf module + * + * @param mds + * input collection of ModuleDescriptors + * @param leafmd + * leaf module + * @return filtered list of modules + */ + private Collection filterModulesFromLeaf(Collection mds, List leafmds) { + // Make a map of ModuleId objects -> ModuleDescriptors + Map moduleIdMap = new HashMap(); + for (Iterator iter = mds.iterator(); iter.hasNext();) { + ModuleDescriptor md = ((ModuleDescriptor) iter.next()); + moduleIdMap.put(md.getModuleRevisionId().getModuleId(), md); + } + + // recursively process the nodes + Set toKeep = new LinkedHashSet(); + Iterator it = leafmds.iterator(); + while (it.hasNext()) { + ModuleDescriptor leafmd = (ModuleDescriptor) it.next(); + // With the excludeleaf attribute set to true, take the rootmd out of the toKeep set. + if (excludeLeaf) { + Message.verbose("Excluded module " + + leafmd.getModuleRevisionId().getModuleId().getName()); + } else { + toKeep.add(leafmd); + } + processFilterNodeFromLeaf(leafmd, toKeep, moduleIdMap); + } + + // just for logging + for (Iterator iter = toKeep.iterator(); iter.hasNext();) { + ModuleDescriptor md = ((ModuleDescriptor) iter.next()); + Message.verbose("Kept module " + md.getModuleRevisionId().getModuleId().getName()); + } + + return toKeep; + } + + /** + * Search in the moduleIdMap modules depending on node, add them to the toKeep set and process + * them recursively. + * + * @param node + * the node to be processed + * @param toKeep + * the set of ModuleDescriptors that should be kept + * @param moduleIdMap + * reference mapping of moduleId to ModuleDescriptor that are part of the BuildList + */ + private void processFilterNodeFromLeaf(ModuleDescriptor node, Set toKeep, Map moduleIdMap) { + for (Iterator iter = moduleIdMap.values().iterator(); iter.hasNext();) { + ModuleDescriptor md = (ModuleDescriptor) iter.next(); + DependencyDescriptor[] deps = md.getDependencies(); + for (int i = 0; i < deps.length; i++) { + ModuleId id = deps[i].getDependencyId(); + if (node.getModuleRevisionId().getModuleId().equals(id) && !toKeep.contains(md)) { + toKeep.add(md); + processFilterNodeFromLeaf(md, toKeep, moduleIdMap); + } + } + } + } + + private void addBuildFile(Path path, File buildFile) { + FileList fl = new FileList(); + fl.setDir(buildFile.getParentFile()); + FileList.FileName fileName = new FileList.FileName(); + fileName.setName(buildFile.getName()); + fl.addConfiguredFile(fileName); + path.addFilelist(fl); + } + + private File getIvyFileFor(File buildFile) { + return new File(buildFile.getParentFile(), ivyFilePath); + } + + public boolean isHaltonerror() { + return haltOnError; + } + + public void setHaltonerror(boolean haltOnError) { + this.haltOnError = haltOnError; + } + + public String getIvyfilepath() { + return ivyFilePath; + } + + public void setIvyfilepath(String ivyFilePath) { + this.ivyFilePath = ivyFilePath; + } + + public boolean isSkipbuildwithoutivy() { + return skipBuildWithoutIvy; + } + + public void setSkipbuildwithoutivy(boolean skipBuildFilesWithoutIvy) { + this.skipBuildWithoutIvy = skipBuildFilesWithoutIvy; + } + + public boolean isReverse() { + return reverse; + } + + public void setReverse(boolean reverse) { + this.reverse = reverse; + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyBuildNumber.java b/src/java/org/apache/ivy/ant/IvyBuildNumber.java index c8d77828..cd2736d8 100644 --- a/src/java/org/apache/ivy/ant/IvyBuildNumber.java +++ b/src/java/org/apache/ivy/ant/IvyBuildNumber.java @@ -1,256 +1,256 @@ -/* - * 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 org.apache.ivy.Ivy; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.tools.ant.BuildException; - -/** - * Look for the latest module in the repository matching the given criteria, and sets a set of - * properties according to what was found. - */ -public class IvyBuildNumber extends IvyTask { - private String _organisation; - - private String _module; - - private String _branch; - - private String _revision; - - private String _revSep = "."; - - private String _prefix = "ivy."; - - private String _default = "0"; - - private String _defaultBuildNumber = "0"; - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getBranch() { - return _branch; - } - - public void setBranch(String branch) { - _branch = branch; - } - - public String getDefault() { - return _default; - } - - public void setDefault(String default1) { - _default = default1; - } - - public String getPrefix() { - return _prefix; - } - - public void setPrefix(String prefix) { - _prefix = prefix; - } - - public void doExecute() throws BuildException { - if (_organisation == null) { - throw new BuildException("no organisation provided for ivy findmodules"); - } - if (_module == null) { - throw new BuildException("no module name provided for ivy findmodules"); - } - if (_prefix == null) { - throw new BuildException("null prefix not allowed"); - } - - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - if (_branch == null) { - settings.getDefaultBranch(new ModuleId(_organisation, _module)); - } - if (_revision == null || _revision.length() == 0) { - _revision = "latest.integration"; - } else if (!_revision.endsWith("+")) { - _revision = _revision + "+"; - } - if (!_prefix.endsWith(".") && _prefix.length() > 0) { - _prefix = _prefix + "."; - } - ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(_organisation, - _module, _branch, _revision)); - String revision = rmr == null ? null : rmr.getId().getRevision(); - NewRevision newRevision = computeNewRevision(revision); - setProperty("revision", newRevision.revision); - setProperty("new.revision", newRevision.newRevision); - setProperty("build.number", newRevision.buildNumber); - setProperty("new.build.number", newRevision.newBuildNumber); - } - - private void setProperty(String propertyName, String value) { - if (value != null) { - getProject().setProperty(_prefix + propertyName, value); - } - } - - private NewRevision computeNewRevision(String revision) { - String revPrefix = "latest.integration".equals(_revision) ? "" : _revision.substring(0, - _revision.length() - 1); - if (revision != null && !revision.startsWith(revPrefix)) { - throw new BuildException("invalid exception found in repository: '" + revision - + "' for '" + revPrefix + "'"); - } - if (revision == null) { - if (revPrefix.length() > 0) { - return new NewRevision(revision, revPrefix - + (revPrefix.endsWith(_revSep) ? _defaultBuildNumber : _revSep - + _defaultBuildNumber), null, _defaultBuildNumber); - } else { - Range r = findLastNumber(_default); - if (r == null) { // no number found - return new NewRevision(revision, _default, null, null); - } else { - long n = Long.parseLong(_default.substring(r.startIndex, r.endIndex)); - return new NewRevision(revision, _default, null, String.valueOf(n)); - } - } - } - Range r; - if (revPrefix.length() == 0) { - r = findLastNumber(revision); - if (r == null) { - return new NewRevision(revision, revision - + (revision.endsWith(_revSep) ? "1" : _revSep + "1"), null, "1"); - } - } else { - r = findFirstNumber(revision, revPrefix.length()); - if (r == null) { - return new NewRevision(revision, revPrefix - + (revPrefix.endsWith(_revSep) ? "1" : _revSep + "1"), null, "1"); - } - } - long n = Long.parseLong(revision.substring(r.startIndex, r.endIndex)) + 1; - return new NewRevision(revision, revision.substring(0, r.startIndex) + n, String - .valueOf(n - 1), String.valueOf(n)); - } - - private Range findFirstNumber(String str, int startIndex) { - // let's find the first digit in the string - int startNumberIndex = startIndex; - while (startNumberIndex < str.length() && !Character.isDigit(str.charAt(startNumberIndex))) { - startNumberIndex++; - } - if (startNumberIndex == str.length()) { - return null; - } - // let's find the end of the number - int endNumberIndex = startNumberIndex + 1; - while (endNumberIndex < str.length() && Character.isDigit(str.charAt(endNumberIndex))) { - endNumberIndex++; - } - return new Range(startNumberIndex, endNumberIndex); - } - - private Range findLastNumber(String str) { - int endNumberIndex = str.length() - 1; - while (endNumberIndex >= 0 && !Character.isDigit(str.charAt(endNumberIndex))) { - endNumberIndex--; - } - int startNumberIndex = endNumberIndex == -1 ? -1 : endNumberIndex - 1; - while (startNumberIndex >= 0 && Character.isDigit(str.charAt(startNumberIndex))) { - startNumberIndex--; - } - endNumberIndex++; - startNumberIndex++; - if (startNumberIndex == endNumberIndex) { // no number found - return null; - } else { - return new Range(startNumberIndex, endNumberIndex); - } - } - - private static class Range { - private int startIndex; - - private int endIndex; - - public Range(int startIndex, int endIndex) { - this.startIndex = startIndex; - this.endIndex = endIndex; - } - } - - private static class NewRevision { - private String revision; - - private String newRevision; - - private String buildNumber; - - private String newBuildNumber; - - public NewRevision(String revision, String newRevision, String buildNumber, - String newBuildNumber) { - this.revision = revision; - this.newRevision = newRevision; - this.buildNumber = buildNumber; - this.newBuildNumber = newBuildNumber; - } - } - - public String getRevSep() { - return _revSep; - } - - public void setRevSep(String revSep) { - _revSep = revSep; - } - - public String getDefaultBuildNumber() { - return _defaultBuildNumber; - } - - public void setDefaultBuildNumber(String defaultBuildNumber) { - _defaultBuildNumber = defaultBuildNumber; - } -} +/* + * 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 org.apache.ivy.Ivy; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.tools.ant.BuildException; + +/** + * Look for the latest module in the repository matching the given criteria, and sets a set of + * properties according to what was found. + */ +public class IvyBuildNumber extends IvyTask { + private String _organisation; + + private String _module; + + private String _branch; + + private String _revision; + + private String _revSep = "."; + + private String _prefix = "ivy."; + + private String _default = "0"; + + private String _defaultBuildNumber = "0"; + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getBranch() { + return _branch; + } + + public void setBranch(String branch) { + _branch = branch; + } + + public String getDefault() { + return _default; + } + + public void setDefault(String default1) { + _default = default1; + } + + public String getPrefix() { + return _prefix; + } + + public void setPrefix(String prefix) { + _prefix = prefix; + } + + public void doExecute() throws BuildException { + if (_organisation == null) { + throw new BuildException("no organisation provided for ivy findmodules"); + } + if (_module == null) { + throw new BuildException("no module name provided for ivy findmodules"); + } + if (_prefix == null) { + throw new BuildException("null prefix not allowed"); + } + + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + if (_branch == null) { + settings.getDefaultBranch(new ModuleId(_organisation, _module)); + } + if (_revision == null || _revision.length() == 0) { + _revision = "latest.integration"; + } else if (!_revision.endsWith("+")) { + _revision = _revision + "+"; + } + if (!_prefix.endsWith(".") && _prefix.length() > 0) { + _prefix = _prefix + "."; + } + ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(_organisation, + _module, _branch, _revision)); + String revision = rmr == null ? null : rmr.getId().getRevision(); + NewRevision newRevision = computeNewRevision(revision); + setProperty("revision", newRevision.revision); + setProperty("new.revision", newRevision.newRevision); + setProperty("build.number", newRevision.buildNumber); + setProperty("new.build.number", newRevision.newBuildNumber); + } + + private void setProperty(String propertyName, String value) { + if (value != null) { + getProject().setProperty(_prefix + propertyName, value); + } + } + + private NewRevision computeNewRevision(String revision) { + String revPrefix = "latest.integration".equals(_revision) ? "" : _revision.substring(0, + _revision.length() - 1); + if (revision != null && !revision.startsWith(revPrefix)) { + throw new BuildException("invalid exception found in repository: '" + revision + + "' for '" + revPrefix + "'"); + } + if (revision == null) { + if (revPrefix.length() > 0) { + return new NewRevision(revision, revPrefix + + (revPrefix.endsWith(_revSep) ? _defaultBuildNumber : _revSep + + _defaultBuildNumber), null, _defaultBuildNumber); + } else { + Range r = findLastNumber(_default); + if (r == null) { // no number found + return new NewRevision(revision, _default, null, null); + } else { + long n = Long.parseLong(_default.substring(r.startIndex, r.endIndex)); + return new NewRevision(revision, _default, null, String.valueOf(n)); + } + } + } + Range r; + if (revPrefix.length() == 0) { + r = findLastNumber(revision); + if (r == null) { + return new NewRevision(revision, revision + + (revision.endsWith(_revSep) ? "1" : _revSep + "1"), null, "1"); + } + } else { + r = findFirstNumber(revision, revPrefix.length()); + if (r == null) { + return new NewRevision(revision, revPrefix + + (revPrefix.endsWith(_revSep) ? "1" : _revSep + "1"), null, "1"); + } + } + long n = Long.parseLong(revision.substring(r.startIndex, r.endIndex)) + 1; + return new NewRevision(revision, revision.substring(0, r.startIndex) + n, String + .valueOf(n - 1), String.valueOf(n)); + } + + private Range findFirstNumber(String str, int startIndex) { + // let's find the first digit in the string + int startNumberIndex = startIndex; + while (startNumberIndex < str.length() && !Character.isDigit(str.charAt(startNumberIndex))) { + startNumberIndex++; + } + if (startNumberIndex == str.length()) { + return null; + } + // let's find the end of the number + int endNumberIndex = startNumberIndex + 1; + while (endNumberIndex < str.length() && Character.isDigit(str.charAt(endNumberIndex))) { + endNumberIndex++; + } + return new Range(startNumberIndex, endNumberIndex); + } + + private Range findLastNumber(String str) { + int endNumberIndex = str.length() - 1; + while (endNumberIndex >= 0 && !Character.isDigit(str.charAt(endNumberIndex))) { + endNumberIndex--; + } + int startNumberIndex = endNumberIndex == -1 ? -1 : endNumberIndex - 1; + while (startNumberIndex >= 0 && Character.isDigit(str.charAt(startNumberIndex))) { + startNumberIndex--; + } + endNumberIndex++; + startNumberIndex++; + if (startNumberIndex == endNumberIndex) { // no number found + return null; + } else { + return new Range(startNumberIndex, endNumberIndex); + } + } + + private static class Range { + private int startIndex; + + private int endIndex; + + public Range(int startIndex, int endIndex) { + this.startIndex = startIndex; + this.endIndex = endIndex; + } + } + + private static class NewRevision { + private String revision; + + private String newRevision; + + private String buildNumber; + + private String newBuildNumber; + + public NewRevision(String revision, String newRevision, String buildNumber, + String newBuildNumber) { + this.revision = revision; + this.newRevision = newRevision; + this.buildNumber = buildNumber; + this.newBuildNumber = newBuildNumber; + } + } + + public String getRevSep() { + return _revSep; + } + + public void setRevSep(String revSep) { + _revSep = revSep; + } + + public String getDefaultBuildNumber() { + return _defaultBuildNumber; + } + + public void setDefaultBuildNumber(String defaultBuildNumber) { + _defaultBuildNumber = defaultBuildNumber; + } +} diff --git a/src/java/org/apache/ivy/ant/IvyCacheFileset.java b/src/java/org/apache/ivy/ant/IvyCacheFileset.java index 87e3f0ca..cd066ebe 100644 --- a/src/java/org/apache/ivy/ant/IvyCacheFileset.java +++ b/src/java/org/apache/ivy/ant/IvyCacheFileset.java @@ -1,79 +1,79 @@ -/* - * 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.util.Iterator; -import java.util.List; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.PatternSet.NameEntry; - -/** - * Creates an ant fileset consisting in all artifacts found during a resolve. Note that this task is - * not compatible with the useOrigin mode. - */ -public class IvyCacheFileset extends IvyCacheTask { - private String _setid; - - public String getSetid() { - return _setid; - } - - public void setSetid(String id) { - _setid = id; - } - - public void setUseOrigin(boolean useOrigin) { - if (useOrigin) { - throw new UnsupportedOperationException( - "the cachefileset task does not support the useOrigin mode, since filesets require to have only one root directory. Please use the the cachepath task instead"); - } - } - - public void doExecute() throws BuildException { - prepareAndCheck(); - if (_setid == null) { - throw new BuildException("setid is required in ivy cachefileset"); - } - try { - FileSet fileset = new FileSet(); - fileset.setProject(getProject()); - getProject().addReference(_setid, fileset); - fileset.setDir(getCache()); - - List paths = getArtifacts(); - if (paths.isEmpty()) { - NameEntry ne = fileset.createExclude(); - ne.setName("**/*"); - } else { - CacheManager cache = getCacheManager(); - for (Iterator iter = paths.iterator(); iter.hasNext();) { - Artifact a = (Artifact) iter.next(); - NameEntry ne = fileset.createInclude(); - ne.setName(cache.getArchivePathInCache(a, cache.getSavedArtifactOrigin(a))); - } - } - } catch (Exception ex) { - throw new BuildException("impossible to build ivy cache fileset: " + ex, ex); - } - } - -} +/* + * 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.util.Iterator; +import java.util.List; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.PatternSet.NameEntry; + +/** + * Creates an ant fileset consisting in all artifacts found during a resolve. Note that this task is + * not compatible with the useOrigin mode. + */ +public class IvyCacheFileset extends IvyCacheTask { + private String _setid; + + public String getSetid() { + return _setid; + } + + public void setSetid(String id) { + _setid = id; + } + + public void setUseOrigin(boolean useOrigin) { + if (useOrigin) { + throw new UnsupportedOperationException( + "the cachefileset task does not support the useOrigin mode, since filesets require to have only one root directory. Please use the the cachepath task instead"); + } + } + + public void doExecute() throws BuildException { + prepareAndCheck(); + if (_setid == null) { + throw new BuildException("setid is required in ivy cachefileset"); + } + try { + FileSet fileset = new FileSet(); + fileset.setProject(getProject()); + getProject().addReference(_setid, fileset); + fileset.setDir(getCache()); + + List paths = getArtifacts(); + if (paths.isEmpty()) { + NameEntry ne = fileset.createExclude(); + ne.setName("**/*"); + } else { + CacheManager cache = getCacheManager(); + for (Iterator iter = paths.iterator(); iter.hasNext();) { + Artifact a = (Artifact) iter.next(); + NameEntry ne = fileset.createInclude(); + ne.setName(cache.getArchivePathInCache(a, cache.getSavedArtifactOrigin(a))); + } + } + } catch (Exception ex) { + throw new BuildException("impossible to build ivy cache fileset: " + ex, ex); + } + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyCachePath.java b/src/java/org/apache/ivy/ant/IvyCachePath.java index d64723c8..d784519e 100644 --- a/src/java/org/apache/ivy/ant/IvyCachePath.java +++ b/src/java/org/apache/ivy/ant/IvyCachePath.java @@ -1,77 +1,77 @@ -/* - * 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.util.Iterator; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.Path; - -/** - * Creates an ant path consisting in all artifacts found during a resolve. - */ -public class IvyCachePath extends IvyCacheTask { - private String _pathid; - - private String _id; - - public String getPathid() { - return _pathid; - } - - public void setPathid(String id) { - _pathid = id; - } - - /** - * @deprecated use setPathid instead - * @param id - */ - public void setId(String id) { - _id = id; - } - - public void doExecute() throws BuildException { - prepareAndCheck(); - if (_pathid == null) { - if (_id != null) { - _pathid = _id; - log("ID IS DEPRECATED, PLEASE USE PATHID INSTEAD", Project.MSG_WARN); - } else { - throw new BuildException("pathid is required in ivy classpath"); - } - } - try { - Path path = new Path(getProject()); - getProject().addReference(_pathid, path); - CacheManager cache = getCacheManager(); - for (Iterator iter = getArtifacts().iterator(); iter.hasNext();) { - Artifact a = (Artifact) iter.next(); - path.createPathElement().setLocation( - cache.getArchiveFileInCache(a, cache.getSavedArtifactOrigin(a), isUseOrigin())); - } - } catch (Exception ex) { - throw new BuildException("impossible to build ivy path: " + ex, ex); - } - - } - -} +/* + * 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.util.Iterator; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; + +/** + * Creates an ant path consisting in all artifacts found during a resolve. + */ +public class IvyCachePath extends IvyCacheTask { + private String _pathid; + + private String _id; + + public String getPathid() { + return _pathid; + } + + public void setPathid(String id) { + _pathid = id; + } + + /** + * @deprecated use setPathid instead + * @param id + */ + public void setId(String id) { + _id = id; + } + + public void doExecute() throws BuildException { + prepareAndCheck(); + if (_pathid == null) { + if (_id != null) { + _pathid = _id; + log("ID IS DEPRECATED, PLEASE USE PATHID INSTEAD", Project.MSG_WARN); + } else { + throw new BuildException("pathid is required in ivy classpath"); + } + } + try { + Path path = new Path(getProject()); + getProject().addReference(_pathid, path); + CacheManager cache = getCacheManager(); + for (Iterator iter = getArtifacts().iterator(); iter.hasNext();) { + Artifact a = (Artifact) iter.next(); + path.createPathElement().setLocation( + cache.getArchiveFileInCache(a, cache.getSavedArtifactOrigin(a), isUseOrigin())); + } + } catch (Exception ex) { + throw new BuildException("impossible to build ivy path: " + ex, ex); + } + + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyCacheTask.java b/src/java/org/apache/ivy/ant/IvyCacheTask.java index 1fc887d6..37f64572 100644 --- a/src/java/org/apache/ivy/ant/IvyCacheTask.java +++ b/src/java/org/apache/ivy/ant/IvyCacheTask.java @@ -1,104 +1,104 @@ -/* - * 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.IOException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.ConfigurationResolveReport; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.plugins.report.XmlReportParser; -import org.apache.ivy.util.Message; -import org.apache.tools.ant.BuildException; - -/** - * Base class for the cache path related classes: cachepath and cachefileset. Most of the behviour - * is common to the two, since only the produced element differs. - */ -public abstract class IvyCacheTask extends IvyPostResolveTask { - - protected List getArtifacts() throws BuildException, ParseException, IOException { - Collection artifacts = getAllArtifacts(); - List ret = new ArrayList(); - for (Iterator iter = artifacts.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - if (getArtifactFilter().accept(artifact)) { - ret.add(artifact); - } - } - - return ret; - } - - private Collection getAllArtifacts() throws ParseException, IOException { - String[] confs = splitConfs(getConf()); - Collection all = new LinkedHashSet(); - - ResolveReport report = getResolvedReport(); - if (report != null) { - Message.debug("using internal report instance to get artifacts list"); - for (int i = 0; i < confs.length; i++) { - ConfigurationResolveReport configurationReport = report - .getConfigurationReport(confs[i]); - if (configurationReport == null) { - throw new BuildException("bad confs provided: " + confs[i] - + " not found among " + Arrays.asList(report.getConfigurations())); - } - Set revisions = configurationReport.getModuleRevisionIds(); - for (Iterator it = revisions.iterator(); it.hasNext();) { - ModuleRevisionId revId = (ModuleRevisionId) it.next(); - ArtifactDownloadReport[] aReps = configurationReport.getDownloadReports(revId); - for (int j = 0; j < aReps.length; j++) { - all.add(aReps[j].getArtifact()); - } - } - } - } else { - Message.debug("using stored report to get artifacts list"); - - XmlReportParser parser = new XmlReportParser(); - CacheManager cacheMgr = getIvyInstance().getCacheManager(getCache()); - for (int i = 0; i < confs.length; i++) { - File reportFile = cacheMgr.getConfigurationResolveReportInCache(getResolveId(), - confs[i]); - parser.parse(reportFile); - - Artifact[] artifacts = parser.getArtifacts(); - all.addAll(Arrays.asList(artifacts)); - } - } - return all; - } - - protected CacheManager getCacheManager() { - CacheManager cache = new CacheManager(getSettings(), getCache()); - return cache; - } -} +/* + * 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.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.ConfigurationResolveReport; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.plugins.report.XmlReportParser; +import org.apache.ivy.util.Message; +import org.apache.tools.ant.BuildException; + +/** + * Base class for the cache path related classes: cachepath and cachefileset. Most of the behviour + * is common to the two, since only the produced element differs. + */ +public abstract class IvyCacheTask extends IvyPostResolveTask { + + protected List getArtifacts() throws BuildException, ParseException, IOException { + Collection artifacts = getAllArtifacts(); + List ret = new ArrayList(); + for (Iterator iter = artifacts.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + if (getArtifactFilter().accept(artifact)) { + ret.add(artifact); + } + } + + return ret; + } + + private Collection getAllArtifacts() throws ParseException, IOException { + String[] confs = splitConfs(getConf()); + Collection all = new LinkedHashSet(); + + ResolveReport report = getResolvedReport(); + if (report != null) { + Message.debug("using internal report instance to get artifacts list"); + for (int i = 0; i < confs.length; i++) { + ConfigurationResolveReport configurationReport = report + .getConfigurationReport(confs[i]); + if (configurationReport == null) { + throw new BuildException("bad confs provided: " + confs[i] + + " not found among " + Arrays.asList(report.getConfigurations())); + } + Set revisions = configurationReport.getModuleRevisionIds(); + for (Iterator it = revisions.iterator(); it.hasNext();) { + ModuleRevisionId revId = (ModuleRevisionId) it.next(); + ArtifactDownloadReport[] aReps = configurationReport.getDownloadReports(revId); + for (int j = 0; j < aReps.length; j++) { + all.add(aReps[j].getArtifact()); + } + } + } + } else { + Message.debug("using stored report to get artifacts list"); + + XmlReportParser parser = new XmlReportParser(); + CacheManager cacheMgr = getIvyInstance().getCacheManager(getCache()); + for (int i = 0; i < confs.length; i++) { + File reportFile = cacheMgr.getConfigurationResolveReportInCache(getResolveId(), + confs[i]); + parser.parse(reportFile); + + Artifact[] artifacts = parser.getArtifacts(); + all.addAll(Arrays.asList(artifacts)); + } + } + return all; + } + + protected CacheManager getCacheManager() { + CacheManager cache = new CacheManager(getSettings(), getCache()); + return cache; + } +} diff --git a/src/java/org/apache/ivy/ant/IvyCheck.java b/src/java/org/apache/ivy/ant/IvyCheck.java index aca6ca94..7dd815c1 100644 --- a/src/java/org/apache/ivy/ant/IvyCheck.java +++ b/src/java/org/apache/ivy/ant/IvyCheck.java @@ -1,98 +1,98 @@ -/* - * 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.net.MalformedURLException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.ivy.Ivy; -import org.apache.ivy.util.Message; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.types.FileSet; - -/** - * Checks the given ivy file using current configuration to see if all dependencies are available, - * with good confs. If a resolver name is given, it also checks that the declared publications are - * available in the corresponding resolver. Note that the check is not performed recursively, i.e. - * if a dependency has itself dependencies badly described or not available, this check will not - * discover it. - */ -public class IvyCheck extends IvyTask { - private File _file = null; - - private List _filesets = new ArrayList(); - - private String _resolvername; - - public File getFile() { - return _file; - } - - public void setFile(File file) { - _file = file; - } - - /** - * Adds a set of files to check. - * - * @param set - * a set of files to check - */ - public void addFileset(FileSet set) { - _filesets.add(set); - } - - public String getResolvername() { - return _resolvername; - } - - public void setResolvername(String resolverName) { - _resolvername = resolverName; - } - - public void doExecute() throws BuildException { - try { - Ivy ivy = getIvyInstance(); - if (_file != null) { - if (ivy.check(_file.toURL(), _resolvername)) { - Message.verbose("checked " + _file + ": OK"); - } - } - for (int i = 0; i < _filesets.size(); i++) { - FileSet fs = (FileSet) _filesets.get(i); - DirectoryScanner ds = fs.getDirectoryScanner(getProject()); - - File fromDir = fs.getDir(getProject()); - - String[] srcFiles = ds.getIncludedFiles(); - for (int j = 0; j < srcFiles.length; j++) { - File file = new File(fromDir, srcFiles[j]); - if (ivy.check(file.toURL(), _resolvername)) { - Message.verbose("checked " + file + ": OK"); - } - } - } - } catch (MalformedURLException e) { - throw new BuildException("impossible to convert a file to an url! " + e, e); - } - } - -} +/* + * 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.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.ivy.Ivy; +import org.apache.ivy.util.Message; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.FileSet; + +/** + * Checks the given ivy file using current configuration to see if all dependencies are available, + * with good confs. If a resolver name is given, it also checks that the declared publications are + * available in the corresponding resolver. Note that the check is not performed recursively, i.e. + * if a dependency has itself dependencies badly described or not available, this check will not + * discover it. + */ +public class IvyCheck extends IvyTask { + private File _file = null; + + private List _filesets = new ArrayList(); + + private String _resolvername; + + public File getFile() { + return _file; + } + + public void setFile(File file) { + _file = file; + } + + /** + * Adds a set of files to check. + * + * @param set + * a set of files to check + */ + public void addFileset(FileSet set) { + _filesets.add(set); + } + + public String getResolvername() { + return _resolvername; + } + + public void setResolvername(String resolverName) { + _resolvername = resolverName; + } + + public void doExecute() throws BuildException { + try { + Ivy ivy = getIvyInstance(); + if (_file != null) { + if (ivy.check(_file.toURL(), _resolvername)) { + Message.verbose("checked " + _file + ": OK"); + } + } + for (int i = 0; i < _filesets.size(); i++) { + FileSet fs = (FileSet) _filesets.get(i); + DirectoryScanner ds = fs.getDirectoryScanner(getProject()); + + File fromDir = fs.getDir(getProject()); + + String[] srcFiles = ds.getIncludedFiles(); + for (int j = 0; j < srcFiles.length; j++) { + File file = new File(fromDir, srcFiles[j]); + if (ivy.check(file.toURL(), _resolvername)) { + Message.verbose("checked " + file + ": OK"); + } + } + } + } catch (MalformedURLException e) { + throw new BuildException("impossible to convert a file to an url! " + e, e); + } + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyConfigure.java b/src/java/org/apache/ivy/ant/IvyConfigure.java index aa1733ce..79b536fb 100644 --- a/src/java/org/apache/ivy/ant/IvyConfigure.java +++ b/src/java/org/apache/ivy/ant/IvyConfigure.java @@ -1,96 +1,96 @@ -/* - * 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.net.MalformedURLException; -import java.util.Properties; - -import org.apache.ivy.ant.IvyAntSettings.Credentials; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Property; - -/** - * Configure Ivy with an ivysettings.xml file - * - * @deprecated Use the IvyAntSettings instead. - */ -public class IvyConfigure extends IvyTask { - - private IvyAntSettings antSettings = new IvyAntSettings(); - - public void doExecute() throws BuildException { - ensureMessageInitialised(); - log("ivy:configure is deprecated, please use the data type ivy:settings instead", - Project.MSG_WARN); - // ivyConfigure used to export properties in the ant script. - // ivy:settings doesn't. - try { - loadDefaultProperties(); - } catch (Exception ex) { - throw new BuildException("impossible to load ivy default properties file: " + ex, ex); - } - antSettings.registerAsDefault(); - } - - private void loadDefaultProperties() { - Property prop = new Property() { - public void execute() throws BuildException { - Properties props = antSettings.getDefaultProperties(); - addProperties(props); - } - }; - prop.setProject(getProject()); - prop.execute(); - } - - public void addConfiguredCredentials(Credentials c) { - antSettings.addConfiguredCredentials(c); - } - - public void setFile(File file) { - antSettings.setFile(file); - } - - public void setHost(String host) { - antSettings.setHost(host); - } - - public void setPasswd(String passwd) { - antSettings.setPasswd(passwd); - } - - public void setProject(Project prj) { - super.setProject(prj); - antSettings.setProject(prj); - } - - public void setRealm(String realm) { - antSettings.setRealm(realm); - } - - public void setUrl(String confUrl) throws MalformedURLException { - antSettings.setUrl(confUrl); - } - - public void setUsername(String userName) { - antSettings.setUsername(userName); - } - -} +/* + * 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.net.MalformedURLException; +import java.util.Properties; + +import org.apache.ivy.ant.IvyAntSettings.Credentials; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Property; + +/** + * Configure Ivy with an ivysettings.xml file + * + * @deprecated Use the IvyAntSettings instead. + */ +public class IvyConfigure extends IvyTask { + + private IvyAntSettings antSettings = new IvyAntSettings(); + + public void doExecute() throws BuildException { + ensureMessageInitialised(); + log("ivy:configure is deprecated, please use the data type ivy:settings instead", + Project.MSG_WARN); + // ivyConfigure used to export properties in the ant script. + // ivy:settings doesn't. + try { + loadDefaultProperties(); + } catch (Exception ex) { + throw new BuildException("impossible to load ivy default properties file: " + ex, ex); + } + antSettings.registerAsDefault(); + } + + private void loadDefaultProperties() { + Property prop = new Property() { + public void execute() throws BuildException { + Properties props = antSettings.getDefaultProperties(); + addProperties(props); + } + }; + prop.setProject(getProject()); + prop.execute(); + } + + public void addConfiguredCredentials(Credentials c) { + antSettings.addConfiguredCredentials(c); + } + + public void setFile(File file) { + antSettings.setFile(file); + } + + public void setHost(String host) { + antSettings.setHost(host); + } + + public void setPasswd(String passwd) { + antSettings.setPasswd(passwd); + } + + public void setProject(Project prj) { + super.setProject(prj); + antSettings.setProject(prj); + } + + public void setRealm(String realm) { + antSettings.setRealm(realm); + } + + public void setUrl(String confUrl) throws MalformedURLException { + antSettings.setUrl(confUrl); + } + + public void setUsername(String userName) { + antSettings.setUsername(userName); + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyConvertPom.java b/src/java/org/apache/ivy/ant/IvyConvertPom.java index 28736397..d30b5d50 100644 --- a/src/java/org/apache/ivy/ant/IvyConvertPom.java +++ b/src/java/org/apache/ivy/ant/IvyConvertPom.java @@ -1,78 +1,78 @@ -/* - * 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.net.MalformedURLException; -import java.text.ParseException; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser; -import org.apache.ivy.plugins.repository.url.URLResource; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -/** - * Convert a pom to an ivy file - */ -public class IvyConvertPom extends IvyTask { - private File _pomFile = null; - - private File _ivyFile = null; - - public File getPomFile() { - return _pomFile; - } - - public void setPomFile(File file) { - _pomFile = file; - } - - public File getIvyFile() { - return _ivyFile; - } - - public void setIvyFile(File ivyFile) { - _ivyFile = ivyFile; - } - - public void doExecute() throws BuildException { - try { - if (_pomFile == null) { - throw new BuildException("source pom file is required for convertpom task"); - } - if (_ivyFile == null) { - throw new BuildException("destination ivy file is required for convertpom task"); - } - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), _pomFile.toURL(), false); - PomModuleDescriptorParser.getInstance().toIvyFile(_pomFile.toURL().openStream(), - new URLResource(_pomFile.toURL()), getIvyFile(), md); - } catch (MalformedURLException e) { - throw new BuildException("unable to convert given pom file to url: " + _pomFile + ": " - + e, e); - } catch (ParseException e) { - log(e.getMessage(), Project.MSG_ERR); - throw new BuildException("syntax errors in pom file " + _pomFile + ": " + e, e); - } catch (Exception e) { - throw new BuildException("impossible convert given pom file to ivy file: " + e - + " from=" + _pomFile + " to=" + _ivyFile, e); - } - } -} +/* + * 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.net.MalformedURLException; +import java.text.ParseException; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser; +import org.apache.ivy.plugins.repository.url.URLResource; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; + +/** + * Convert a pom to an ivy file + */ +public class IvyConvertPom extends IvyTask { + private File _pomFile = null; + + private File _ivyFile = null; + + public File getPomFile() { + return _pomFile; + } + + public void setPomFile(File file) { + _pomFile = file; + } + + public File getIvyFile() { + return _ivyFile; + } + + public void setIvyFile(File ivyFile) { + _ivyFile = ivyFile; + } + + public void doExecute() throws BuildException { + try { + if (_pomFile == null) { + throw new BuildException("source pom file is required for convertpom task"); + } + if (_ivyFile == null) { + throw new BuildException("destination ivy file is required for convertpom task"); + } + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), _pomFile.toURL(), false); + PomModuleDescriptorParser.getInstance().toIvyFile(_pomFile.toURL().openStream(), + new URLResource(_pomFile.toURL()), getIvyFile(), md); + } catch (MalformedURLException e) { + throw new BuildException("unable to convert given pom file to url: " + _pomFile + ": " + + e, e); + } catch (ParseException e) { + log(e.getMessage(), Project.MSG_ERR); + throw new BuildException("syntax errors in pom file " + _pomFile + ": " + e, e); + } catch (Exception e) { + throw new BuildException("impossible convert given pom file to ivy file: " + e + + " from=" + _pomFile + " to=" + _ivyFile, e); + } + } +} diff --git a/src/java/org/apache/ivy/ant/IvyDeliver.java b/src/java/org/apache/ivy/ant/IvyDeliver.java index 3929be09..19e875ba 100644 --- a/src/java/org/apache/ivy/ant/IvyDeliver.java +++ b/src/java/org/apache/ivy/ant/IvyDeliver.java @@ -1,422 +1,422 @@ -/* - * 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.util.Date; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.deliver.DefaultPublishingDRResolver; -import org.apache.ivy.core.deliver.DeliverOptions; -import org.apache.ivy.core.deliver.PublishingDependencyRevisionResolver; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.module.status.StatusManager; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.MessageImpl; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.CallTarget; -import org.apache.tools.ant.taskdefs.Echo; -import org.apache.tools.ant.taskdefs.Input; -import org.apache.tools.ant.taskdefs.Property; - -/** - * Trigger the delivery of a module, which may consist in a recursive delivery of dependencies and - * on the replacement in the ivy file of dynamic revisions (like latest.integration) by static ones. - */ -public class IvyDeliver extends IvyTask { - private final class DeliverDRResolver extends DefaultPublishingDRResolver { - public String resolve(ModuleDescriptor published, String publishedStatus, - ModuleRevisionId depMrid, String depStatus) { - if (StatusManager.getCurrent().isIntegration(publishedStatus)) { - // published status is integration one, nothing to ask - return super.resolve(published, publishedStatus, depMrid, depStatus); - } - - // we are publishing a delivery (a non integration module) - - if (!StatusManager.getCurrent().isIntegration(depStatus)) { - // dependency is already a delivery, nothing to ask - return super.resolve(published, publishedStatus, depMrid, depStatus); - } - - // the dependency is not a delivery - - String statusProperty = depMrid.getName() + "." + depMrid.getRevision() + ".status"; - String versionProperty = depMrid.getName() + "." + depMrid.getRevision() + ".version"; - String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision() - + ".delivered"; - - String version = getProject().getProperty(versionProperty); - String status = getProject().getProperty(statusProperty); - String delivered = getProject().getProperty(deliveredProperty); - Message.debug("found version = " + version + " status=" + status + " delivered=" - + delivered); - if (version != null && status != null) { - if ("true".equals(delivered)) { - // delivery has already been done : just return the value - return version; - } else { - deliverDependency(depMrid, version, status, depStatus); - loadDeliveryList(); - return version; - } - } - - /** - * By setting these properties: recursive.delivery.status and - * recursive.delivery.version, then if the specific status/version is not found, then we - * will use the status/version set in these global properties. This will apply to all - * artifacts in the system. This patch is meant to be used for recursive deliveries so - * that all deliveries will use the global status/version unless a more specific one is - * set. - */ - String globalStatusProperty = "recursive.delivery.status"; - String globalVersionProperty = "recursive.delivery.version"; - version = getProject().getProperty(globalVersionProperty); - status = getProject().getProperty(globalStatusProperty); - if (version != null && status != null) { - // found global delivery properties - delivered = getProject().getProperty( - "recursive." + depMrid.getName() + ".delivered"); - Message.debug("found global version = " + version + " and global status=" + status - + " - delivered = " + delivered); - if ("true".equals(delivered)) { - // delivery has already been done : just return the value - return version; - } else { - getProject().setProperty(statusProperty, status); - deliverDependency(depMrid, version, status, depStatus); - loadDeliveryList(); - return version; - } - } - - // we must ask the user what version and status he want to have - // for the dependency - Input input = (Input) getProject().createTask("input"); - input.setOwningTarget(getOwningTarget()); - input.init(); - - // ask status - input.setMessage(depMrid.getName() + " " + depMrid.getRevision() - + ": please enter a status: "); - input.setValidargs(StatusManager.getCurrent().getDeliveryStatusListString()); - input.setAddproperty(statusProperty); - input.perform(); - status = getProject().getProperty(statusProperty); - appendDeliveryList(statusProperty + " = " + status); - - // ask version - input.setMessage(depMrid.getName() + " " + depMrid.getRevision() - + ": please enter a version: "); - input.setValidargs(null); - input.setAddproperty(versionProperty); - input.perform(); - - version = getProject().getProperty(versionProperty); - appendDeliveryList(versionProperty + " = " + version); - deliverDependency(depMrid, version, status, depStatus); - - loadDeliveryList(); - - return version; - } - - public void deliverDependency(ModuleRevisionId depMrid, String version, String status, - String depStatus) { - // call deliver target if any - if (_deliverTarget != null && _deliverTarget.trim().length() > 0) { - - CallTarget ct = (CallTarget) getProject().createTask("antcall"); - ct.setOwningTarget(getOwningTarget()); - ct.init(); - ct.setTarget(_deliverTarget); - ct.setInheritAll(true); - ct.setInheritRefs(true); - Property param = ct.createParam(); - param.setName("dependency.name"); - param.setValue(depMrid.getName()); - param = ct.createParam(); - param.setName("dependency.published.status"); - param.setValue(status); - param = ct.createParam(); - param.setName("dependency.published.version"); - param.setValue(version); - param = ct.createParam(); - param.setName("dependency.version"); - param.setValue(depMrid.getRevision()); - param = ct.createParam(); - param.setName("dependency.status"); - param.setValue(depStatus == null ? "null" : depStatus); - - MessageImpl impl = IvyContext.getContext().getMessageImpl(); - try { - IvyContext.getContext().setMessageImpl(null); - ct.perform(); - } finally { - IvyContext.getContext().setMessageImpl(impl); - } - - String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision() - + ".delivered"; - getProject().setProperty(deliveredProperty, "true"); - appendDeliveryList(deliveredProperty + " = true"); - - getProject().setProperty("recursive." + depMrid.getName() + ".delivered", "true"); - appendDeliveryList("recursive." + depMrid.getName() + ".delivered" + " = true"); - } - } - - } - - private String _organisation; - - private String _module; - - private String _revision; - - private String _pubRevision; - - private File _cache; - - private String _deliverpattern; - - private String _status; - - private String _pubdate; - - private String _deliverTarget; - - private File _deliveryList; - - private boolean _replacedynamicrev = true; - - private String _resolveId; - - private String _conf; - - public File getCache() { - return _cache; - } - - public void setCache(File cache) { - _cache = cache; - } - - public String getDeliverpattern() { - return _deliverpattern; - } - - public void setDeliverpattern(String destivypattern) { - _deliverpattern = destivypattern; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getPubdate() { - return _pubdate; - } - - public void setPubdate(String pubdate) { - _pubdate = pubdate; - } - - public String getPubrevision() { - return _pubRevision; - } - - public void setPubrevision(String pubRevision) { - _pubRevision = pubRevision; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getStatus() { - return _status; - } - - public void setStatus(String status) { - _status = status; - } - - public void setDelivertarget(String deliverTarget) { - _deliverTarget = deliverTarget; - } - - public void setDeliveryList(File deliveryList) { - _deliveryList = deliveryList; - } - - public boolean isReplacedynamicrev() { - return _replacedynamicrev; - } - - public void setReplacedynamicrev(boolean replacedynamicrev) { - _replacedynamicrev = replacedynamicrev; - } - - public String getResolveId() { - return _resolveId; - } - - public void setResolveId(String resolveId) { - _resolveId = resolveId; - } - - public String getConf() { - return _conf; - } - - public void setConf(String confs) { - _conf = confs; - } - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - - _organisation = getProperty(_organisation, settings, "ivy.organisation", _resolveId); - _module = getProperty(_module, settings, "ivy.module", _resolveId); - _revision = getProperty(_revision, settings, "ivy.revision", _resolveId); - _pubRevision = getProperty(_pubRevision, settings, "ivy.deliver.revision"); - if (_cache == null) { - _cache = settings.getDefaultCache(); - } - _deliverpattern = getProperty(_deliverpattern, settings, "ivy.deliver.ivy.pattern"); - _status = getProperty(_status, settings, "ivy.status"); - if (_deliveryList == null) { - String deliveryListPath = getProperty(settings, "ivy.delivery.list.file"); - if (deliveryListPath == null) { - _deliveryList = new File(System.getProperty("java.io.tmpdir") - + "/delivery.properties"); - } else { - _deliveryList = getProject().resolveFile(settings.substitute(deliveryListPath)); - } - } - if (_resolveId == null) { - if (_organisation == null) { - throw new BuildException( - "no organisation provided for ivy deliver task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); - } - if (_module == null) { - throw new BuildException( - "no module name provided for ivy deliver task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); - } - } - if (_revision == null) { - _revision = Ivy.getWorkingRevision(); - } - Date pubdate = getPubDate(_pubdate, new Date()); - if (_pubRevision == null) { - if (_revision.startsWith("working@")) { - _pubRevision = Ivy.DATE_FORMAT.format(pubdate); - } else { - _pubRevision = _revision; - } - } - if (_deliverpattern == null) { - throw new BuildException( - "deliver ivy pattern is missing: either provide it as parameters or through ivy.deliver.ivy.pattern properties"); - } - if (_status == null) { - throw new BuildException( - "no status provided: either provide it as parameter or through the ivy.status.default property"); - } - - ModuleRevisionId mrid = null; - if (_resolveId == null) { - mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); - } - boolean isLeading = false; - try { - if (!_deliveryList.exists()) { - isLeading = true; - } - - loadDeliveryList(); - - PublishingDependencyRevisionResolver drResolver; - if (_deliverTarget != null && _deliverTarget.trim().length() > 0) { - drResolver = new DeliverDRResolver(); - } else { - drResolver = new DefaultPublishingDRResolver(); - } - - DeliverOptions options = new DeliverOptions(_status, pubdate, CacheManager.getInstance( - settings, _cache), drResolver, doValidate(settings), _replacedynamicrev, - splitConfs(_conf)).setResolveId(_resolveId); - if (mrid == null) { - ivy.deliver(_pubRevision, _deliverpattern, options); - } else { - ivy.deliver(mrid, _pubRevision, _deliverpattern, options); - } - } catch (Exception e) { - throw new BuildException("impossible to deliver " + mrid == null ? _resolveId : mrid - + ": " + e, e); - } finally { - if (isLeading) { - if (_deliveryList.exists()) { - _deliveryList.delete(); - } - } - } - } - - private void loadDeliveryList() { - Property property = (Property) getProject().createTask("property"); - property.setOwningTarget(getOwningTarget()); - property.init(); - property.setFile(_deliveryList); - property.perform(); - } - - private void appendDeliveryList(String msg) { - Echo echo = (Echo) getProject().createTask("echo"); - echo.setOwningTarget(getOwningTarget()); - echo.init(); - echo.setFile(_deliveryList); - echo.setMessage(msg + "\n"); - echo.setAppend(true); - echo.perform(); - } - -} +/* + * 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.util.Date; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.deliver.DefaultPublishingDRResolver; +import org.apache.ivy.core.deliver.DeliverOptions; +import org.apache.ivy.core.deliver.PublishingDependencyRevisionResolver; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.module.status.StatusManager; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.MessageImpl; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.CallTarget; +import org.apache.tools.ant.taskdefs.Echo; +import org.apache.tools.ant.taskdefs.Input; +import org.apache.tools.ant.taskdefs.Property; + +/** + * Trigger the delivery of a module, which may consist in a recursive delivery of dependencies and + * on the replacement in the ivy file of dynamic revisions (like latest.integration) by static ones. + */ +public class IvyDeliver extends IvyTask { + private final class DeliverDRResolver extends DefaultPublishingDRResolver { + public String resolve(ModuleDescriptor published, String publishedStatus, + ModuleRevisionId depMrid, String depStatus) { + if (StatusManager.getCurrent().isIntegration(publishedStatus)) { + // published status is integration one, nothing to ask + return super.resolve(published, publishedStatus, depMrid, depStatus); + } + + // we are publishing a delivery (a non integration module) + + if (!StatusManager.getCurrent().isIntegration(depStatus)) { + // dependency is already a delivery, nothing to ask + return super.resolve(published, publishedStatus, depMrid, depStatus); + } + + // the dependency is not a delivery + + String statusProperty = depMrid.getName() + "." + depMrid.getRevision() + ".status"; + String versionProperty = depMrid.getName() + "." + depMrid.getRevision() + ".version"; + String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision() + + ".delivered"; + + String version = getProject().getProperty(versionProperty); + String status = getProject().getProperty(statusProperty); + String delivered = getProject().getProperty(deliveredProperty); + Message.debug("found version = " + version + " status=" + status + " delivered=" + + delivered); + if (version != null && status != null) { + if ("true".equals(delivered)) { + // delivery has already been done : just return the value + return version; + } else { + deliverDependency(depMrid, version, status, depStatus); + loadDeliveryList(); + return version; + } + } + + /** + * By setting these properties: recursive.delivery.status and + * recursive.delivery.version, then if the specific status/version is not found, then we + * will use the status/version set in these global properties. This will apply to all + * artifacts in the system. This patch is meant to be used for recursive deliveries so + * that all deliveries will use the global status/version unless a more specific one is + * set. + */ + String globalStatusProperty = "recursive.delivery.status"; + String globalVersionProperty = "recursive.delivery.version"; + version = getProject().getProperty(globalVersionProperty); + status = getProject().getProperty(globalStatusProperty); + if (version != null && status != null) { + // found global delivery properties + delivered = getProject().getProperty( + "recursive." + depMrid.getName() + ".delivered"); + Message.debug("found global version = " + version + " and global status=" + status + + " - delivered = " + delivered); + if ("true".equals(delivered)) { + // delivery has already been done : just return the value + return version; + } else { + getProject().setProperty(statusProperty, status); + deliverDependency(depMrid, version, status, depStatus); + loadDeliveryList(); + return version; + } + } + + // we must ask the user what version and status he want to have + // for the dependency + Input input = (Input) getProject().createTask("input"); + input.setOwningTarget(getOwningTarget()); + input.init(); + + // ask status + input.setMessage(depMrid.getName() + " " + depMrid.getRevision() + + ": please enter a status: "); + input.setValidargs(StatusManager.getCurrent().getDeliveryStatusListString()); + input.setAddproperty(statusProperty); + input.perform(); + status = getProject().getProperty(statusProperty); + appendDeliveryList(statusProperty + " = " + status); + + // ask version + input.setMessage(depMrid.getName() + " " + depMrid.getRevision() + + ": please enter a version: "); + input.setValidargs(null); + input.setAddproperty(versionProperty); + input.perform(); + + version = getProject().getProperty(versionProperty); + appendDeliveryList(versionProperty + " = " + version); + deliverDependency(depMrid, version, status, depStatus); + + loadDeliveryList(); + + return version; + } + + public void deliverDependency(ModuleRevisionId depMrid, String version, String status, + String depStatus) { + // call deliver target if any + if (_deliverTarget != null && _deliverTarget.trim().length() > 0) { + + CallTarget ct = (CallTarget) getProject().createTask("antcall"); + ct.setOwningTarget(getOwningTarget()); + ct.init(); + ct.setTarget(_deliverTarget); + ct.setInheritAll(true); + ct.setInheritRefs(true); + Property param = ct.createParam(); + param.setName("dependency.name"); + param.setValue(depMrid.getName()); + param = ct.createParam(); + param.setName("dependency.published.status"); + param.setValue(status); + param = ct.createParam(); + param.setName("dependency.published.version"); + param.setValue(version); + param = ct.createParam(); + param.setName("dependency.version"); + param.setValue(depMrid.getRevision()); + param = ct.createParam(); + param.setName("dependency.status"); + param.setValue(depStatus == null ? "null" : depStatus); + + MessageImpl impl = IvyContext.getContext().getMessageImpl(); + try { + IvyContext.getContext().setMessageImpl(null); + ct.perform(); + } finally { + IvyContext.getContext().setMessageImpl(impl); + } + + String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision() + + ".delivered"; + getProject().setProperty(deliveredProperty, "true"); + appendDeliveryList(deliveredProperty + " = true"); + + getProject().setProperty("recursive." + depMrid.getName() + ".delivered", "true"); + appendDeliveryList("recursive." + depMrid.getName() + ".delivered" + " = true"); + } + } + + } + + private String _organisation; + + private String _module; + + private String _revision; + + private String _pubRevision; + + private File _cache; + + private String _deliverpattern; + + private String _status; + + private String _pubdate; + + private String _deliverTarget; + + private File _deliveryList; + + private boolean _replacedynamicrev = true; + + private String _resolveId; + + private String _conf; + + public File getCache() { + return _cache; + } + + public void setCache(File cache) { + _cache = cache; + } + + public String getDeliverpattern() { + return _deliverpattern; + } + + public void setDeliverpattern(String destivypattern) { + _deliverpattern = destivypattern; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getPubdate() { + return _pubdate; + } + + public void setPubdate(String pubdate) { + _pubdate = pubdate; + } + + public String getPubrevision() { + return _pubRevision; + } + + public void setPubrevision(String pubRevision) { + _pubRevision = pubRevision; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getStatus() { + return _status; + } + + public void setStatus(String status) { + _status = status; + } + + public void setDelivertarget(String deliverTarget) { + _deliverTarget = deliverTarget; + } + + public void setDeliveryList(File deliveryList) { + _deliveryList = deliveryList; + } + + public boolean isReplacedynamicrev() { + return _replacedynamicrev; + } + + public void setReplacedynamicrev(boolean replacedynamicrev) { + _replacedynamicrev = replacedynamicrev; + } + + public String getResolveId() { + return _resolveId; + } + + public void setResolveId(String resolveId) { + _resolveId = resolveId; + } + + public String getConf() { + return _conf; + } + + public void setConf(String confs) { + _conf = confs; + } + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + + _organisation = getProperty(_organisation, settings, "ivy.organisation", _resolveId); + _module = getProperty(_module, settings, "ivy.module", _resolveId); + _revision = getProperty(_revision, settings, "ivy.revision", _resolveId); + _pubRevision = getProperty(_pubRevision, settings, "ivy.deliver.revision"); + if (_cache == null) { + _cache = settings.getDefaultCache(); + } + _deliverpattern = getProperty(_deliverpattern, settings, "ivy.deliver.ivy.pattern"); + _status = getProperty(_status, settings, "ivy.status"); + if (_deliveryList == null) { + String deliveryListPath = getProperty(settings, "ivy.delivery.list.file"); + if (deliveryListPath == null) { + _deliveryList = new File(System.getProperty("java.io.tmpdir") + + "/delivery.properties"); + } else { + _deliveryList = getProject().resolveFile(settings.substitute(deliveryListPath)); + } + } + if (_resolveId == null) { + if (_organisation == null) { + throw new BuildException( + "no organisation provided for ivy deliver task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); + } + if (_module == null) { + throw new BuildException( + "no module name provided for ivy deliver task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); + } + } + if (_revision == null) { + _revision = Ivy.getWorkingRevision(); + } + Date pubdate = getPubDate(_pubdate, new Date()); + if (_pubRevision == null) { + if (_revision.startsWith("working@")) { + _pubRevision = Ivy.DATE_FORMAT.format(pubdate); + } else { + _pubRevision = _revision; + } + } + if (_deliverpattern == null) { + throw new BuildException( + "deliver ivy pattern is missing: either provide it as parameters or through ivy.deliver.ivy.pattern properties"); + } + if (_status == null) { + throw new BuildException( + "no status provided: either provide it as parameter or through the ivy.status.default property"); + } + + ModuleRevisionId mrid = null; + if (_resolveId == null) { + mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); + } + boolean isLeading = false; + try { + if (!_deliveryList.exists()) { + isLeading = true; + } + + loadDeliveryList(); + + PublishingDependencyRevisionResolver drResolver; + if (_deliverTarget != null && _deliverTarget.trim().length() > 0) { + drResolver = new DeliverDRResolver(); + } else { + drResolver = new DefaultPublishingDRResolver(); + } + + DeliverOptions options = new DeliverOptions(_status, pubdate, CacheManager.getInstance( + settings, _cache), drResolver, doValidate(settings), _replacedynamicrev, + splitConfs(_conf)).setResolveId(_resolveId); + if (mrid == null) { + ivy.deliver(_pubRevision, _deliverpattern, options); + } else { + ivy.deliver(mrid, _pubRevision, _deliverpattern, options); + } + } catch (Exception e) { + throw new BuildException("impossible to deliver " + mrid == null ? _resolveId : mrid + + ": " + e, e); + } finally { + if (isLeading) { + if (_deliveryList.exists()) { + _deliveryList.delete(); + } + } + } + } + + private void loadDeliveryList() { + Property property = (Property) getProject().createTask("property"); + property.setOwningTarget(getOwningTarget()); + property.init(); + property.setFile(_deliveryList); + property.perform(); + } + + private void appendDeliveryList(String msg) { + Echo echo = (Echo) getProject().createTask("echo"); + echo.setOwningTarget(getOwningTarget()); + echo.init(); + echo.setFile(_deliveryList); + echo.setMessage(msg + "\n"); + echo.setAppend(true); + echo.perform(); + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyExtractFromSources.java b/src/java/org/apache/ivy/ant/IvyExtractFromSources.java index 67d2b440..2434fe34 100644 --- a/src/java/org/apache/ivy/ant/IvyExtractFromSources.java +++ b/src/java/org/apache/ivy/ant/IvyExtractFromSources.java @@ -1,216 +1,216 @@ -/* - * 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.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.filters.LineContainsRegExp; -import org.apache.tools.ant.filters.TokenFilter; -import org.apache.tools.ant.taskdefs.Concat; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.FilterChain; -import org.apache.tools.ant.types.RegularExpression; - -/** - * Extracts imports from a set of java sources and generate corresponding ivy file - */ -public class IvyExtractFromSources extends IvyTask { - public static class Ignore { - String _package; - - public String getPackage() { - return _package; - } - - public void setPackage(String package1) { - _package = package1; - } - } - - private String _organisation; - - private String _module; - - private String _revision; - - private String _status; - - private List _ignoredPackaged = new ArrayList(); // List (String package) - - private Map _mapping = new HashMap(); // Map (String package -> ModuleRevisionId) - - private Concat _concat = new Concat(); - - private File _to; - - public void addConfiguredIgnore(Ignore ignore) { - _ignoredPackaged.add(ignore.getPackage()); - } - - public File getTo() { - return _to; - } - - public void setTo(File to) { - _to = to; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getStatus() { - return _status; - } - - public void setStatus(String status) { - _status = status; - } - - public void addConfiguredMapping(PackageMapping mapping) { - _mapping.put(mapping.getPackage(), mapping.getModuleRevisionId()); - } - - public void addFileSet(FileSet fileSet) { - _concat.addFileset(fileSet); - } - - public void doExecute() throws BuildException { - configureConcat(); - Writer out = new StringWriter(); - _concat.setWriter(out); - _concat.execute(); - Set importsSet = new HashSet(Arrays.asList(out.toString().split("\n"))); - Set dependencies = new HashSet(); - for (Iterator iter = importsSet.iterator(); iter.hasNext();) { - String pack = ((String) iter.next()).trim(); - ModuleRevisionId mrid = getMapping(pack); - if (mrid != null) { - dependencies.add(mrid); - } - } - try { - PrintWriter writer = new PrintWriter(new FileOutputStream(_to)); - writer.println(""); - writer.println("\t"); - if (!dependencies.isEmpty()) { - writer.println("\t"); - for (Iterator iter = dependencies.iterator(); iter.hasNext();) { - ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); - writer.println("\t\t"); - } - writer.println("\t"); - } - writer.println(""); - writer.close(); - log(dependencies.size() + " dependencies put in " + _to); - } catch (FileNotFoundException e) { - throw new BuildException("impossible to create file " + _to + ": " + e, e); - } - } - - /** - * @param pack - * @return - */ - private ModuleRevisionId getMapping(String pack) { - String askedPack = pack; - ModuleRevisionId ret = null; - while (ret == null && pack.length() > 0) { - if (_ignoredPackaged.contains(pack)) { - return null; - } - ret = (ModuleRevisionId) _mapping.get(pack); - int lastDotIndex = pack.lastIndexOf('.'); - if (lastDotIndex != -1) { - pack = pack.substring(0, lastDotIndex); - } else { - break; - } - } - if (ret == null) { - log("no mapping found for " + askedPack, Project.MSG_VERBOSE); - } - return ret; - } - - private void configureConcat() { - _concat.setProject(getProject()); - _concat.setTaskName(getTaskName()); - FilterChain filterChain = new FilterChain(); - LineContainsRegExp lcre = new LineContainsRegExp(); - RegularExpression regexp = new RegularExpression(); - regexp.setPattern("^import .+;"); - lcre.addConfiguredRegexp(regexp); - filterChain.add(lcre); - TokenFilter tf = new TokenFilter(); - TokenFilter.ReplaceRegex rre = new TokenFilter.ReplaceRegex(); - rre.setPattern("import (.+);.*"); - rre.setReplace("\\1"); - tf.add(rre); - filterChain.add(tf); - _concat.addFilterChain(filterChain); - } -} +/* + * 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.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.filters.LineContainsRegExp; +import org.apache.tools.ant.filters.TokenFilter; +import org.apache.tools.ant.taskdefs.Concat; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.FilterChain; +import org.apache.tools.ant.types.RegularExpression; + +/** + * Extracts imports from a set of java sources and generate corresponding ivy file + */ +public class IvyExtractFromSources extends IvyTask { + public static class Ignore { + String _package; + + public String getPackage() { + return _package; + } + + public void setPackage(String package1) { + _package = package1; + } + } + + private String _organisation; + + private String _module; + + private String _revision; + + private String _status; + + private List _ignoredPackaged = new ArrayList(); // List (String package) + + private Map _mapping = new HashMap(); // Map (String package -> ModuleRevisionId) + + private Concat _concat = new Concat(); + + private File _to; + + public void addConfiguredIgnore(Ignore ignore) { + _ignoredPackaged.add(ignore.getPackage()); + } + + public File getTo() { + return _to; + } + + public void setTo(File to) { + _to = to; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getStatus() { + return _status; + } + + public void setStatus(String status) { + _status = status; + } + + public void addConfiguredMapping(PackageMapping mapping) { + _mapping.put(mapping.getPackage(), mapping.getModuleRevisionId()); + } + + public void addFileSet(FileSet fileSet) { + _concat.addFileset(fileSet); + } + + public void doExecute() throws BuildException { + configureConcat(); + Writer out = new StringWriter(); + _concat.setWriter(out); + _concat.execute(); + Set importsSet = new HashSet(Arrays.asList(out.toString().split("\n"))); + Set dependencies = new HashSet(); + for (Iterator iter = importsSet.iterator(); iter.hasNext();) { + String pack = ((String) iter.next()).trim(); + ModuleRevisionId mrid = getMapping(pack); + if (mrid != null) { + dependencies.add(mrid); + } + } + try { + PrintWriter writer = new PrintWriter(new FileOutputStream(_to)); + writer.println(""); + writer.println("\t"); + if (!dependencies.isEmpty()) { + writer.println("\t"); + for (Iterator iter = dependencies.iterator(); iter.hasNext();) { + ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); + writer.println("\t\t"); + } + writer.println("\t"); + } + writer.println(""); + writer.close(); + log(dependencies.size() + " dependencies put in " + _to); + } catch (FileNotFoundException e) { + throw new BuildException("impossible to create file " + _to + ": " + e, e); + } + } + + /** + * @param pack + * @return + */ + private ModuleRevisionId getMapping(String pack) { + String askedPack = pack; + ModuleRevisionId ret = null; + while (ret == null && pack.length() > 0) { + if (_ignoredPackaged.contains(pack)) { + return null; + } + ret = (ModuleRevisionId) _mapping.get(pack); + int lastDotIndex = pack.lastIndexOf('.'); + if (lastDotIndex != -1) { + pack = pack.substring(0, lastDotIndex); + } else { + break; + } + } + if (ret == null) { + log("no mapping found for " + askedPack, Project.MSG_VERBOSE); + } + return ret; + } + + private void configureConcat() { + _concat.setProject(getProject()); + _concat.setTaskName(getTaskName()); + FilterChain filterChain = new FilterChain(); + LineContainsRegExp lcre = new LineContainsRegExp(); + RegularExpression regexp = new RegularExpression(); + regexp.setPattern("^import .+;"); + lcre.addConfiguredRegexp(regexp); + filterChain.add(lcre); + TokenFilter tf = new TokenFilter(); + TokenFilter.ReplaceRegex rre = new TokenFilter.ReplaceRegex(); + rre.setPattern("import (.+);.*"); + rre.setReplace("\\1"); + tf.add(rre); + filterChain.add(tf); + _concat.addFilterChain(filterChain); + } +} diff --git a/src/java/org/apache/ivy/ant/IvyFindRevision.java b/src/java/org/apache/ivy/ant/IvyFindRevision.java index 329da07f..77ff4981 100644 --- a/src/java/org/apache/ivy/ant/IvyFindRevision.java +++ b/src/java/org/apache/ivy/ant/IvyFindRevision.java @@ -1,104 +1,104 @@ -/* - * 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 org.apache.ivy.Ivy; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.tools.ant.BuildException; - -/** - * Look for the latest module in the repository matching the given criteria, and sets a set of - * properties according to what was found. - */ -public class IvyFindRevision extends IvyTask { - private String _organisation; - - private String _module; - - private String _branch; - - private String _revision; - - private String _property = "ivy.revision"; - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getBranch() { - return _branch; - } - - public void setBranch(String branch) { - _branch = branch; - } - - public String getProperty() { - return _property; - } - - public void setProperty(String prefix) { - _property = prefix; - } - - public void doExecute() throws BuildException { - if (_organisation == null) { - throw new BuildException("no organisation provided for ivy findmodules"); - } - if (_module == null) { - throw new BuildException("no module name provided for ivy findmodules"); - } - if (_revision == null) { - throw new BuildException("no revision provided for ivy findmodules"); - } - - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - if (_branch == null) { - settings.getDefaultBranch(new ModuleId(_organisation, _module)); - } - ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(_organisation, - _module, _branch, _revision)); - if (rmr != null) { - getProject().setProperty(_property, rmr.getId().getRevision()); - } - } -} +/* + * 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 org.apache.ivy.Ivy; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.tools.ant.BuildException; + +/** + * Look for the latest module in the repository matching the given criteria, and sets a set of + * properties according to what was found. + */ +public class IvyFindRevision extends IvyTask { + private String _organisation; + + private String _module; + + private String _branch; + + private String _revision; + + private String _property = "ivy.revision"; + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getBranch() { + return _branch; + } + + public void setBranch(String branch) { + _branch = branch; + } + + public String getProperty() { + return _property; + } + + public void setProperty(String prefix) { + _property = prefix; + } + + public void doExecute() throws BuildException { + if (_organisation == null) { + throw new BuildException("no organisation provided for ivy findmodules"); + } + if (_module == null) { + throw new BuildException("no module name provided for ivy findmodules"); + } + if (_revision == null) { + throw new BuildException("no revision provided for ivy findmodules"); + } + + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + if (_branch == null) { + settings.getDefaultBranch(new ModuleId(_organisation, _module)); + } + ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(_organisation, + _module, _branch, _revision)); + if (rmr != null) { + getProject().setProperty(_property, rmr.getId().getRevision()); + } + } +} diff --git a/src/java/org/apache/ivy/ant/IvyInfo.java b/src/java/org/apache/ivy/ant/IvyInfo.java index 2b22a932..19db706d 100644 --- a/src/java/org/apache/ivy/ant/IvyInfo.java +++ b/src/java/org/apache/ivy/ant/IvyInfo.java @@ -1,86 +1,86 @@ -/* - * 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.net.MalformedURLException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.descriptor.Configuration.Visibility; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -/** - * Parses information about an ivy file and make them available in ant. - */ -public class IvyInfo extends IvyTask { - private File _file = null; - - public File getFile() { - return _file; - } - - public void setFile(File file) { - _file = file; - } - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - if (_file == null) { - _file = getProject().resolveFile(getProperty(settings, "ivy.dep.file")); - } - - try { - ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor( - settings, _file.toURL(), doValidate(settings)); - getProject() - .setProperty("ivy.organisation", md.getModuleRevisionId().getOrganisation()); - getProject().setProperty("ivy.module", md.getModuleRevisionId().getName()); - getProject().setProperty("ivy.revision", md.getModuleRevisionId().getRevision()); - getProject().setProperty("ivy.configurations", mergeConfs(md.getConfigurationsNames())); - - // store the public configurations in a separate property - Configuration[] configs = md.getConfigurations(); - List publicConfigsList = new ArrayList(); - for (int i = 0; i < configs.length; i++) { - if (Visibility.PUBLIC.equals(configs[i].getVisibility())) { - publicConfigsList.add(configs[i].getName()); - } - } - String[] publicConfigs = (String[]) publicConfigsList - .toArray(new String[publicConfigsList.size()]); - getProject().setProperty("ivy.public.configurations", mergeConfs(publicConfigs)); - } catch (MalformedURLException e) { - throw new BuildException( - "unable to convert given ivy file to url: " + _file + ": " + e, e); - } catch (ParseException e) { - log(e.getMessage(), Project.MSG_ERR); - throw new BuildException("syntax errors in ivy file: " + e, e); - } catch (Exception e) { - throw new BuildException("impossible to resolve dependencies: " + e, e); - } - } -} +/* + * 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.net.MalformedURLException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.descriptor.Configuration.Visibility; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; + +/** + * Parses information about an ivy file and make them available in ant. + */ +public class IvyInfo extends IvyTask { + private File _file = null; + + public File getFile() { + return _file; + } + + public void setFile(File file) { + _file = file; + } + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + if (_file == null) { + _file = getProject().resolveFile(getProperty(settings, "ivy.dep.file")); + } + + try { + ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor( + settings, _file.toURL(), doValidate(settings)); + getProject() + .setProperty("ivy.organisation", md.getModuleRevisionId().getOrganisation()); + getProject().setProperty("ivy.module", md.getModuleRevisionId().getName()); + getProject().setProperty("ivy.revision", md.getModuleRevisionId().getRevision()); + getProject().setProperty("ivy.configurations", mergeConfs(md.getConfigurationsNames())); + + // store the public configurations in a separate property + Configuration[] configs = md.getConfigurations(); + List publicConfigsList = new ArrayList(); + for (int i = 0; i < configs.length; i++) { + if (Visibility.PUBLIC.equals(configs[i].getVisibility())) { + publicConfigsList.add(configs[i].getName()); + } + } + String[] publicConfigs = (String[]) publicConfigsList + .toArray(new String[publicConfigsList.size()]); + getProject().setProperty("ivy.public.configurations", mergeConfs(publicConfigs)); + } catch (MalformedURLException e) { + throw new BuildException( + "unable to convert given ivy file to url: " + _file + ": " + e, e); + } catch (ParseException e) { + log(e.getMessage(), Project.MSG_ERR); + throw new BuildException("syntax errors in ivy file: " + e, e); + } catch (Exception e) { + throw new BuildException("impossible to resolve dependencies: " + e, e); + } + } +} diff --git a/src/java/org/apache/ivy/ant/IvyInstall.java b/src/java/org/apache/ivy/ant/IvyInstall.java index 3be5201e..ba6f685e 100644 --- a/src/java/org/apache/ivy/ant/IvyInstall.java +++ b/src/java/org/apache/ivy/ant/IvyInstall.java @@ -1,188 +1,188 @@ -/* - * 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 org.apache.ivy.Ivy; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.util.filter.FilterHelper; -import org.apache.tools.ant.BuildException; - -/** - * Allow to install a module or a set of module from repository to another one. - */ -public class IvyInstall extends IvyTask { - private String _organisation; - - private String _module; - - private String _revision; - - private File _cache; - - private boolean _overwrite = false; - - private String _from; - - private String _to; - - private boolean _transitive; - - private String _type; - - private String _matcher = PatternMatcher.EXACT; - - private boolean _haltOnFailure = true; - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - if (_cache == null) { - _cache = settings.getDefaultCache(); - } - if (_organisation == null) { - throw new BuildException( - "no organisation provided for ivy publish task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); - } - if (_module == null && PatternMatcher.EXACT.equals(_matcher)) { - throw new BuildException( - "no module name provided for ivy publish task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); - } else if (_module == null && !PatternMatcher.EXACT.equals(_matcher)) { - _module = PatternMatcher.ANY_EXPRESSION; - } - if (_revision == null && PatternMatcher.EXACT.equals(_matcher)) { - throw new BuildException( - "no module revision provided for ivy publish task: It can either be set explicitely via the attribute 'revision' or via 'ivy.revision' property or a prior call to "); - } else if (_revision == null && !PatternMatcher.EXACT.equals(_matcher)) { - _revision = PatternMatcher.ANY_EXPRESSION; - } - if (_from == null) { - throw new BuildException( - "no from resolver name: please provide it through parameter 'from'"); - } - if (_to == null) { - throw new BuildException( - "no to resolver name: please provide it through parameter 'to'"); - } - ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); - ResolveReport report; - try { - report = ivy.install(mrid, _from, _to, _transitive, doValidate(settings), _overwrite, - FilterHelper.getArtifactTypeFilter(_type), _cache, _matcher); - } catch (Exception e) { - throw new BuildException("impossible to install " + mrid + ": " + e, e); - } - - if (report.hasError() && isHaltonfailure()) { - throw new BuildException( - "Problem happened while installing modules - see output for details"); - } - } - - public boolean isHaltonfailure() { - return _haltOnFailure; - } - - public void setHaltonfailure(boolean haltOnFailure) { - _haltOnFailure = haltOnFailure; - } - - public File getCache() { - return _cache; - } - - public void setCache(File cache) { - _cache = cache; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public boolean isOverwrite() { - return _overwrite; - } - - public void setOverwrite(boolean overwrite) { - _overwrite = overwrite; - } - - public String getFrom() { - return _from; - } - - public void setFrom(String from) { - _from = from; - } - - public String getTo() { - return _to; - } - - public void setTo(String to) { - _to = to; - } - - public boolean isTransitive() { - return _transitive; - } - - public void setTransitive(boolean transitive) { - _transitive = transitive; - } - - public String getType() { - return _type; - } - - public void setType(String type) { - _type = type; - } - - public String getMatcher() { - return _matcher; - } - - public void setMatcher(String matcher) { - _matcher = matcher; - } -} +/* + * 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 org.apache.ivy.Ivy; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.util.filter.FilterHelper; +import org.apache.tools.ant.BuildException; + +/** + * Allow to install a module or a set of module from repository to another one. + */ +public class IvyInstall extends IvyTask { + private String _organisation; + + private String _module; + + private String _revision; + + private File _cache; + + private boolean _overwrite = false; + + private String _from; + + private String _to; + + private boolean _transitive; + + private String _type; + + private String _matcher = PatternMatcher.EXACT; + + private boolean _haltOnFailure = true; + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + if (_cache == null) { + _cache = settings.getDefaultCache(); + } + if (_organisation == null) { + throw new BuildException( + "no organisation provided for ivy publish task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); + } + if (_module == null && PatternMatcher.EXACT.equals(_matcher)) { + throw new BuildException( + "no module name provided for ivy publish task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); + } else if (_module == null && !PatternMatcher.EXACT.equals(_matcher)) { + _module = PatternMatcher.ANY_EXPRESSION; + } + if (_revision == null && PatternMatcher.EXACT.equals(_matcher)) { + throw new BuildException( + "no module revision provided for ivy publish task: It can either be set explicitely via the attribute 'revision' or via 'ivy.revision' property or a prior call to "); + } else if (_revision == null && !PatternMatcher.EXACT.equals(_matcher)) { + _revision = PatternMatcher.ANY_EXPRESSION; + } + if (_from == null) { + throw new BuildException( + "no from resolver name: please provide it through parameter 'from'"); + } + if (_to == null) { + throw new BuildException( + "no to resolver name: please provide it through parameter 'to'"); + } + ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); + ResolveReport report; + try { + report = ivy.install(mrid, _from, _to, _transitive, doValidate(settings), _overwrite, + FilterHelper.getArtifactTypeFilter(_type), _cache, _matcher); + } catch (Exception e) { + throw new BuildException("impossible to install " + mrid + ": " + e, e); + } + + if (report.hasError() && isHaltonfailure()) { + throw new BuildException( + "Problem happened while installing modules - see output for details"); + } + } + + public boolean isHaltonfailure() { + return _haltOnFailure; + } + + public void setHaltonfailure(boolean haltOnFailure) { + _haltOnFailure = haltOnFailure; + } + + public File getCache() { + return _cache; + } + + public void setCache(File cache) { + _cache = cache; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public boolean isOverwrite() { + return _overwrite; + } + + public void setOverwrite(boolean overwrite) { + _overwrite = overwrite; + } + + public String getFrom() { + return _from; + } + + public void setFrom(String from) { + _from = from; + } + + public String getTo() { + return _to; + } + + public void setTo(String to) { + _to = to; + } + + public boolean isTransitive() { + return _transitive; + } + + public void setTransitive(boolean transitive) { + _transitive = transitive; + } + + public String getType() { + return _type; + } + + public void setType(String type) { + _type = type; + } + + public String getMatcher() { + return _matcher; + } + + public void setMatcher(String matcher) { + _matcher = matcher; + } +} diff --git a/src/java/org/apache/ivy/ant/IvyListModules.java b/src/java/org/apache/ivy/ant/IvyListModules.java index 7696df02..9d4fc502 100644 --- a/src/java/org/apache/ivy/ant/IvyListModules.java +++ b/src/java/org/apache/ivy/ant/IvyListModules.java @@ -1,128 +1,128 @@ -/* - * 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 org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.tools.ant.BuildException; - -/** - * Look for modules in the repository matching the given criteria, and sets a set of properties - * according to what was found. - */ -public class IvyListModules extends IvyTask { - private String _organisation; - - private String _module; - - private String _branch = PatternMatcher.ANY_EXPRESSION; - - private String _revision; - - private String _matcher = PatternMatcher.EXACT_OR_REGEXP; - - private String _property; - - private String _value; - - public String getMatcher() { - return _matcher; - } - - public void setMatcher(String matcher) { - _matcher = matcher; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getProperty() { - return _property; - } - - public void setProperty(String name) { - _property = name; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getValue() { - return _value; - } - - public void setValue(String value) { - _value = value; - } - - public String getBranch() { - return _branch; - } - - public void setBranch(String branch) { - _branch = branch; - } - - public void doExecute() throws BuildException { - if (_organisation == null) { - throw new BuildException("no organisation provided for ivy findmodules"); - } - if (_module == null) { - throw new BuildException("no module name provided for ivy findmodules"); - } - if (_revision == null) { - throw new BuildException("no revision provided for ivy findmodules"); - } - if (_property == null) { - throw new BuildException("no property provided for ivy findmodules"); - } - if (_value == null) { - throw new BuildException("no value provided for ivy findmodules"); - } - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - ModuleRevisionId[] mrids = ivy.listModules(ModuleRevisionId.newInstance(_organisation, - _module, _branch, _revision), settings.getMatcher(_matcher)); - for (int i = 0; i < mrids.length; i++) { - String name = IvyPatternHelper.substitute(settings.substitute(_property), mrids[i]); - String value = IvyPatternHelper.substitute(settings.substitute(_value), mrids[i]); - getProject().setProperty(name, value); - } - } -} +/* + * 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 org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.tools.ant.BuildException; + +/** + * Look for modules in the repository matching the given criteria, and sets a set of properties + * according to what was found. + */ +public class IvyListModules extends IvyTask { + private String _organisation; + + private String _module; + + private String _branch = PatternMatcher.ANY_EXPRESSION; + + private String _revision; + + private String _matcher = PatternMatcher.EXACT_OR_REGEXP; + + private String _property; + + private String _value; + + public String getMatcher() { + return _matcher; + } + + public void setMatcher(String matcher) { + _matcher = matcher; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getProperty() { + return _property; + } + + public void setProperty(String name) { + _property = name; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getValue() { + return _value; + } + + public void setValue(String value) { + _value = value; + } + + public String getBranch() { + return _branch; + } + + public void setBranch(String branch) { + _branch = branch; + } + + public void doExecute() throws BuildException { + if (_organisation == null) { + throw new BuildException("no organisation provided for ivy findmodules"); + } + if (_module == null) { + throw new BuildException("no module name provided for ivy findmodules"); + } + if (_revision == null) { + throw new BuildException("no revision provided for ivy findmodules"); + } + if (_property == null) { + throw new BuildException("no property provided for ivy findmodules"); + } + if (_value == null) { + throw new BuildException("no value provided for ivy findmodules"); + } + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + ModuleRevisionId[] mrids = ivy.listModules(ModuleRevisionId.newInstance(_organisation, + _module, _branch, _revision), settings.getMatcher(_matcher)); + for (int i = 0; i < mrids.length; i++) { + String name = IvyPatternHelper.substitute(settings.substitute(_property), mrids[i]); + String value = IvyPatternHelper.substitute(settings.substitute(_value), mrids[i]); + getProject().setProperty(name, value); + } + } +} diff --git a/src/java/org/apache/ivy/ant/IvyPostResolveTask.java b/src/java/org/apache/ivy/ant/IvyPostResolveTask.java index 4f01d39e..04eb3422 100644 --- a/src/java/org/apache/ivy/ant/IvyPostResolveTask.java +++ b/src/java/org/apache/ivy/ant/IvyPostResolveTask.java @@ -1,371 +1,371 @@ -/* - * 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.util.Arrays; -import java.util.HashSet; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.StringUtils; -import org.apache.ivy.util.filter.Filter; -import org.apache.ivy.util.filter.FilterHelper; -import org.apache.tools.ant.BuildException; - -/** - * Base class for tasks needing to be performed after a resolve. - */ -public abstract class IvyPostResolveTask extends IvyTask { - private String _conf; - - private boolean _haltOnFailure = true; - - private boolean _transitive = true; - - private boolean _inline = false; - - private File _cache; - - private String _organisation; - - private String _module; - - private String _revision = "latest.integration"; - - private String _resolveId; - - private String _type; - - private File _file; - - private Filter _artifactFilter = null; - - private boolean useOrigin = false; - - private Boolean keep = null; - - public boolean isUseOrigin() { - return useOrigin; - } - - public void setUseOrigin(boolean useOrigin) { - this.useOrigin = useOrigin; - } - - protected void prepareAndCheck() { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - - boolean orgAndModSetManually = (_organisation != null) && (_module != null); - - _organisation = getProperty(_organisation, settings, "ivy.organisation"); - _module = getProperty(_module, settings, "ivy.module"); - - if (_cache == null) { - _cache = settings.getDefaultCache(); - } - - if (_file == null) { - String fileName = getProperty(settings, "ivy.resolved.file", _resolveId); - if (fileName != null) { - _file = new File(fileName); - } - } - - if (isInline()) { - _conf = _conf == null ? "*" : _conf; - if (_organisation == null) { - throw new BuildException( - "no organisation provided for ivy cache task in inline mode: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property"); - } - if (_module == null) { - throw new BuildException( - "no module name provided for ivy cache task in inline mode: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property"); - } - String[] toResolve = getConfsToResolve(getOrganisation(), getModule() + "-caller", - _conf, true); - if (toResolve.length > 0) { - Message.verbose("using inline mode to resolve " + getOrganisation() + " " - + getModule() + " " + getRevision() + " (" - + StringUtils.join(toResolve, ", ") + ")"); - IvyResolve resolve = createResolve(isHaltonfailure(), isUseOrigin()); - resolve.setOrganisation(getOrganisation()); - resolve.setModule(getModule()); - resolve.setRevision(getRevision()); - resolve.setInline(true); - resolve.setConf(_conf); - resolve.setCache(_cache); - resolve.setResolveId(_resolveId); - resolve.execute(); - } else { - Message.verbose("inline resolve already done for " + getOrganisation() + " " - + getModule() + " " + getRevision() + " (" + _conf + ")"); - } - if ("*".equals(_conf)) { - _conf = StringUtils.join(getResolvedConfigurations(getOrganisation(), getModule() - + "-caller", true), ", "); - } - } else { - Message.debug("using standard ensure resolved"); - - // if the organization and module has been manually specified, we'll reuse the resolved - // data from another build (there is no way to know which configurations were resolved - // there (TODO: maybe we can check which reports exist and extract the configurations - // from these report names?) - if (!orgAndModSetManually) { - ensureResolved(isHaltonfailure(), isUseOrigin(), isTransitive(), getOrganisation(), - getModule(), getProperty(_conf, settings, "ivy.resolved.configurations"), - _resolveId, _cache); - } - - _conf = getProperty(_conf, settings, "ivy.resolved.configurations"); - if ("*".equals(_conf)) { - _conf = getProperty(settings, "ivy.resolved.configurations"); - if (_conf == null) { - throw new BuildException( - "bad conf provided for ivy cache task: * can only be used with a prior call to "); - } - } - } - _organisation = getProperty(_organisation, settings, "ivy.organisation"); - _module = getProperty(_module, settings, "ivy.module"); - if (_organisation == null) { - throw new BuildException( - "no organisation provided for ivy cache task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); - } - if (_module == null) { - throw new BuildException( - "no module name provided for ivy cache task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); - } - if (_conf == null) { - throw new BuildException( - "no conf provided for ivy cache task: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to "); - } - - _artifactFilter = FilterHelper.getArtifactTypeFilter(_type); - } - - protected void ensureResolved(boolean haltOnFailure, boolean useOrigin, boolean transitive, - String org, String module, String conf, String resolveId, File cache) { - ensureMessageInitialised(); - - String[] confs = null; - if (resolveId != null) { - confs = getConfsToResolve(resolveId, conf); - } else { - confs = getConfsToResolve(org, module, conf, false); - } - - if (confs.length > 0) { - IvyResolve resolve = createResolve(haltOnFailure, useOrigin); - resolve.setFile(_file); - resolve.setCache(cache); - resolve.setTransitive(transitive); - resolve.setConf(StringUtils.join(confs, ", ")); - resolve.setResolveId(resolveId); - resolve.execute(); - } - } - - protected String[] getConfsToResolve(String org, String module, String conf, boolean strict) { - ModuleDescriptor reference = (ModuleDescriptor) getResolvedDescriptor(org, module, strict); - String[] rconfs = getResolvedConfigurations(org, module, strict); - return getConfsToResolve(reference, conf, rconfs); - } - - protected String[] getConfsToResolve(String resolveId, String conf) { - ModuleDescriptor reference = (ModuleDescriptor) getResolvedDescriptor(resolveId, false); - if (reference == null) { - // assume the module has been resolved outside this build, resolve the required - // configurations again - // TODO: find a way to discover which confs were resolved by that previous resolve - if (conf == null) { - return new String[] {"*"}; - } else { - return splitConfs(conf); - } - } - String[] rconfs = (String[]) getProject().getReference( - "ivy.resolved.configurations.ref." + resolveId); - return getConfsToResolve(reference, conf, rconfs); - } - - private String[] getConfsToResolve(ModuleDescriptor reference, String conf, String[] rconfs) { - Message.debug("calculating configurations to resolve"); - - if (reference == null) { - Message.debug("module not yet resolved, all confs still need to be resolved"); - if (conf == null) { - return new String[] {"*"}; - } else { - return splitConfs(conf); - } - } else if (conf != null) { - String[] confs; - if ("*".equals(conf)) { - confs = reference.getConfigurationsNames(); - } else { - confs = splitConfs(conf); - } - HashSet rconfsSet = new HashSet(Arrays.asList(rconfs)); - HashSet confsSet = new HashSet(Arrays.asList(confs)); - Message.debug("resolved configurations: " + rconfsSet); - Message.debug("asked configurations: " + confsSet); - confsSet.removeAll(rconfsSet); - Message.debug("to resolve configurations: " + confsSet); - return (String[]) confsSet.toArray(new String[confsSet.size()]); - } else { - Message.debug("module already resolved, no configuration to resolve"); - return new String[0]; - } - - } - - protected IvyResolve createResolve(boolean haltOnFailure, boolean useOrigin) { - Message.verbose("no resolved descriptor found: launching default resolve"); - IvyResolve resolve = new IvyResolve(); - resolve.setProject(getProject()); - resolve.setHaltonfailure(haltOnFailure); - resolve.setUseOrigin(useOrigin); - resolve.setValidate(isValidate()); - resolve.setKeep(isKeep()); - return resolve; - } - - protected ModuleRevisionId getResolvedMrid() { - return new ModuleRevisionId(getResolvedModuleId(), getRevision() == null ? Ivy - .getWorkingRevision() : getRevision()); - } - - protected ModuleId getResolvedModuleId() { - return isInline() ? new ModuleId(getOrganisation(), getModule() + "-caller") - : new ModuleId(getOrganisation(), getModule()); - } - - protected ResolveReport getResolvedReport() { - return getResolvedReport(getOrganisation(), isInline() ? getModule() + "-caller" - : getModule(), _resolveId); - } - - public String getType() { - return _type; - } - - public void setType(String type) { - _type = type; - } - - public String getConf() { - return _conf; - } - - public void setConf(String conf) { - _conf = conf; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public boolean isHaltonfailure() { - return _haltOnFailure; - } - - public void setHaltonfailure(boolean haltOnFailure) { - _haltOnFailure = haltOnFailure; - } - - public File getCache() { - return _cache; - } - - public void setCache(File cache) { - _cache = cache; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String rev) { - _revision = rev; - } - - public Filter getArtifactFilter() { - return _artifactFilter; - } - - public boolean isTransitive() { - return _transitive; - } - - public void setTransitive(boolean transitive) { - _transitive = transitive; - } - - public boolean isInline() { - return _inline; - } - - public void setInline(boolean inline) { - _inline = inline; - } - - public void setResolveId(String resolveId) { - _resolveId = resolveId; - } - - public String getResolveId() { - return _resolveId; - } - - public void setFile(File file) { - _file = file; - } - - public File getFile() { - return _file; - } - - public void setKeep(boolean keep) { - this.keep = Boolean.valueOf(keep); - } - - public boolean isKeep() { - return this.keep == null ? !isInline() : this.keep.booleanValue(); - } - -} +/* + * 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.util.Arrays; +import java.util.HashSet; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.StringUtils; +import org.apache.ivy.util.filter.Filter; +import org.apache.ivy.util.filter.FilterHelper; +import org.apache.tools.ant.BuildException; + +/** + * Base class for tasks needing to be performed after a resolve. + */ +public abstract class IvyPostResolveTask extends IvyTask { + private String _conf; + + private boolean _haltOnFailure = true; + + private boolean _transitive = true; + + private boolean _inline = false; + + private File _cache; + + private String _organisation; + + private String _module; + + private String _revision = "latest.integration"; + + private String _resolveId; + + private String _type; + + private File _file; + + private Filter _artifactFilter = null; + + private boolean useOrigin = false; + + private Boolean keep = null; + + public boolean isUseOrigin() { + return useOrigin; + } + + public void setUseOrigin(boolean useOrigin) { + this.useOrigin = useOrigin; + } + + protected void prepareAndCheck() { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + + boolean orgAndModSetManually = (_organisation != null) && (_module != null); + + _organisation = getProperty(_organisation, settings, "ivy.organisation"); + _module = getProperty(_module, settings, "ivy.module"); + + if (_cache == null) { + _cache = settings.getDefaultCache(); + } + + if (_file == null) { + String fileName = getProperty(settings, "ivy.resolved.file", _resolveId); + if (fileName != null) { + _file = new File(fileName); + } + } + + if (isInline()) { + _conf = _conf == null ? "*" : _conf; + if (_organisation == null) { + throw new BuildException( + "no organisation provided for ivy cache task in inline mode: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property"); + } + if (_module == null) { + throw new BuildException( + "no module name provided for ivy cache task in inline mode: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property"); + } + String[] toResolve = getConfsToResolve(getOrganisation(), getModule() + "-caller", + _conf, true); + if (toResolve.length > 0) { + Message.verbose("using inline mode to resolve " + getOrganisation() + " " + + getModule() + " " + getRevision() + " (" + + StringUtils.join(toResolve, ", ") + ")"); + IvyResolve resolve = createResolve(isHaltonfailure(), isUseOrigin()); + resolve.setOrganisation(getOrganisation()); + resolve.setModule(getModule()); + resolve.setRevision(getRevision()); + resolve.setInline(true); + resolve.setConf(_conf); + resolve.setCache(_cache); + resolve.setResolveId(_resolveId); + resolve.execute(); + } else { + Message.verbose("inline resolve already done for " + getOrganisation() + " " + + getModule() + " " + getRevision() + " (" + _conf + ")"); + } + if ("*".equals(_conf)) { + _conf = StringUtils.join(getResolvedConfigurations(getOrganisation(), getModule() + + "-caller", true), ", "); + } + } else { + Message.debug("using standard ensure resolved"); + + // if the organization and module has been manually specified, we'll reuse the resolved + // data from another build (there is no way to know which configurations were resolved + // there (TODO: maybe we can check which reports exist and extract the configurations + // from these report names?) + if (!orgAndModSetManually) { + ensureResolved(isHaltonfailure(), isUseOrigin(), isTransitive(), getOrganisation(), + getModule(), getProperty(_conf, settings, "ivy.resolved.configurations"), + _resolveId, _cache); + } + + _conf = getProperty(_conf, settings, "ivy.resolved.configurations"); + if ("*".equals(_conf)) { + _conf = getProperty(settings, "ivy.resolved.configurations"); + if (_conf == null) { + throw new BuildException( + "bad conf provided for ivy cache task: * can only be used with a prior call to "); + } + } + } + _organisation = getProperty(_organisation, settings, "ivy.organisation"); + _module = getProperty(_module, settings, "ivy.module"); + if (_organisation == null) { + throw new BuildException( + "no organisation provided for ivy cache task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); + } + if (_module == null) { + throw new BuildException( + "no module name provided for ivy cache task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); + } + if (_conf == null) { + throw new BuildException( + "no conf provided for ivy cache task: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to "); + } + + _artifactFilter = FilterHelper.getArtifactTypeFilter(_type); + } + + protected void ensureResolved(boolean haltOnFailure, boolean useOrigin, boolean transitive, + String org, String module, String conf, String resolveId, File cache) { + ensureMessageInitialised(); + + String[] confs = null; + if (resolveId != null) { + confs = getConfsToResolve(resolveId, conf); + } else { + confs = getConfsToResolve(org, module, conf, false); + } + + if (confs.length > 0) { + IvyResolve resolve = createResolve(haltOnFailure, useOrigin); + resolve.setFile(_file); + resolve.setCache(cache); + resolve.setTransitive(transitive); + resolve.setConf(StringUtils.join(confs, ", ")); + resolve.setResolveId(resolveId); + resolve.execute(); + } + } + + protected String[] getConfsToResolve(String org, String module, String conf, boolean strict) { + ModuleDescriptor reference = (ModuleDescriptor) getResolvedDescriptor(org, module, strict); + String[] rconfs = getResolvedConfigurations(org, module, strict); + return getConfsToResolve(reference, conf, rconfs); + } + + protected String[] getConfsToResolve(String resolveId, String conf) { + ModuleDescriptor reference = (ModuleDescriptor) getResolvedDescriptor(resolveId, false); + if (reference == null) { + // assume the module has been resolved outside this build, resolve the required + // configurations again + // TODO: find a way to discover which confs were resolved by that previous resolve + if (conf == null) { + return new String[] {"*"}; + } else { + return splitConfs(conf); + } + } + String[] rconfs = (String[]) getProject().getReference( + "ivy.resolved.configurations.ref." + resolveId); + return getConfsToResolve(reference, conf, rconfs); + } + + private String[] getConfsToResolve(ModuleDescriptor reference, String conf, String[] rconfs) { + Message.debug("calculating configurations to resolve"); + + if (reference == null) { + Message.debug("module not yet resolved, all confs still need to be resolved"); + if (conf == null) { + return new String[] {"*"}; + } else { + return splitConfs(conf); + } + } else if (conf != null) { + String[] confs; + if ("*".equals(conf)) { + confs = reference.getConfigurationsNames(); + } else { + confs = splitConfs(conf); + } + HashSet rconfsSet = new HashSet(Arrays.asList(rconfs)); + HashSet confsSet = new HashSet(Arrays.asList(confs)); + Message.debug("resolved configurations: " + rconfsSet); + Message.debug("asked configurations: " + confsSet); + confsSet.removeAll(rconfsSet); + Message.debug("to resolve configurations: " + confsSet); + return (String[]) confsSet.toArray(new String[confsSet.size()]); + } else { + Message.debug("module already resolved, no configuration to resolve"); + return new String[0]; + } + + } + + protected IvyResolve createResolve(boolean haltOnFailure, boolean useOrigin) { + Message.verbose("no resolved descriptor found: launching default resolve"); + IvyResolve resolve = new IvyResolve(); + resolve.setProject(getProject()); + resolve.setHaltonfailure(haltOnFailure); + resolve.setUseOrigin(useOrigin); + resolve.setValidate(isValidate()); + resolve.setKeep(isKeep()); + return resolve; + } + + protected ModuleRevisionId getResolvedMrid() { + return new ModuleRevisionId(getResolvedModuleId(), getRevision() == null ? Ivy + .getWorkingRevision() : getRevision()); + } + + protected ModuleId getResolvedModuleId() { + return isInline() ? new ModuleId(getOrganisation(), getModule() + "-caller") + : new ModuleId(getOrganisation(), getModule()); + } + + protected ResolveReport getResolvedReport() { + return getResolvedReport(getOrganisation(), isInline() ? getModule() + "-caller" + : getModule(), _resolveId); + } + + public String getType() { + return _type; + } + + public void setType(String type) { + _type = type; + } + + public String getConf() { + return _conf; + } + + public void setConf(String conf) { + _conf = conf; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public boolean isHaltonfailure() { + return _haltOnFailure; + } + + public void setHaltonfailure(boolean haltOnFailure) { + _haltOnFailure = haltOnFailure; + } + + public File getCache() { + return _cache; + } + + public void setCache(File cache) { + _cache = cache; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String rev) { + _revision = rev; + } + + public Filter getArtifactFilter() { + return _artifactFilter; + } + + public boolean isTransitive() { + return _transitive; + } + + public void setTransitive(boolean transitive) { + _transitive = transitive; + } + + public boolean isInline() { + return _inline; + } + + public void setInline(boolean inline) { + _inline = inline; + } + + public void setResolveId(String resolveId) { + _resolveId = resolveId; + } + + public String getResolveId() { + return _resolveId; + } + + public void setFile(File file) { + _file = file; + } + + public File getFile() { + return _file; + } + + public void setKeep(boolean keep) { + this.keep = Boolean.valueOf(keep); + } + + public boolean isKeep() { + return this.keep == null ? !isInline() : this.keep.booleanValue(); + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyPublish.java b/src/java/org/apache/ivy/ant/IvyPublish.java index 69f6fbd8..3c189f31 100644 --- a/src/java/org/apache/ivy/ant/IvyPublish.java +++ b/src/java/org/apache/ivy/ant/IvyPublish.java @@ -1,457 +1,457 @@ -/* - * 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.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.id.ArtifactRevisionId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.publish.PublishOptions; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.util.Message; -import org.apache.tools.ant.BuildException; - -/** - * This task allow to publish a module revision to an Ivy repository. - */ -public class IvyPublish extends IvyTask { - private String _organisation; - - private String _module; - - private String _revision; - - private String _pubRevision; - - private File _cache; - - private String _srcivypattern; - - private String _status; - - private String _conf = null; - - private String _pubdate; - - private String _deliverTarget; - - private String _publishResolverName = null; - - private List _artifactspattern = new ArrayList(); - - private File _deliveryList; - - private boolean _publishivy = true; - - private boolean _warnonmissing = true; - - private boolean _haltonmissing = true; - - private boolean _overwrite = false; - - private boolean _update = false; - - private boolean _replacedynamicrev = true; - - private boolean _forcedeliver; - - private Collection _artifacts = new ArrayList(); - - public File getCache() { - return _cache; - } - - public void setCache(File cache) { - _cache = cache; - } - - public String getSrcivypattern() { - return _srcivypattern; - } - - public void setSrcivypattern(String destivypattern) { - _srcivypattern = destivypattern; - } - - /** - * @deprecated use getSrcivypattern instead - * @return - */ - public String getDeliverivypattern() { - return _srcivypattern; - } - - /** - * @deprecated use setSrcivypattern instead - * @return - */ - public void setDeliverivypattern(String destivypattern) { - _srcivypattern = destivypattern; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getPubdate() { - return _pubdate; - } - - public void setPubdate(String pubdate) { - _pubdate = pubdate; - } - - public String getPubrevision() { - return _pubRevision; - } - - public void setPubrevision(String pubRevision) { - _pubRevision = pubRevision; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getStatus() { - return _status; - } - - public void setStatus(String status) { - _status = status; - } - - public void setConf(String conf) { - _conf = conf; - } - - public void setDelivertarget(String deliverTarget) { - _deliverTarget = deliverTarget; - } - - public void setDeliveryList(File deliveryList) { - _deliveryList = deliveryList; - } - - public String getResolver() { - return _publishResolverName; - } - - public void setResolver(String publishResolverName) { - _publishResolverName = publishResolverName; - } - - public String getArtifactspattern() { - return (String) (_artifactspattern.isEmpty() ? null : _artifactspattern.get(0)); - } - - public void setArtifactspattern(String artifactsPattern) { - _artifactspattern.clear(); - _artifactspattern.add(artifactsPattern); - } - - public void addArtifactspattern(String artifactsPattern) { - _artifactspattern.add(artifactsPattern); - } - - public void addConfiguredArtifacts(ArtifactsPattern p) { - _artifactspattern.add(p.getPattern()); - } - - public boolean isReplacedynamicrev() { - return _replacedynamicrev; - } - - public void setReplacedynamicrev(boolean replacedynamicrev) { - _replacedynamicrev = replacedynamicrev; - } - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - - _organisation = getProperty(_organisation, settings, "ivy.organisation"); - _module = getProperty(_module, settings, "ivy.module"); - _revision = getProperty(_revision, settings, "ivy.revision"); - _pubRevision = getProperty(_pubRevision, settings, "ivy.deliver.revision"); - if (_cache == null) { - _cache = settings.getDefaultCache(); - } - if (_artifactspattern.isEmpty()) { - String p = getProperty(null, settings, "ivy.publish.src.artifacts.pattern"); - if (p != null) { - _artifactspattern.add(p); - } - } - if (_srcivypattern == null) { - _srcivypattern = getArtifactspattern(); - } - _status = getProperty(_status, settings, "ivy.status"); - if (_organisation == null) { - throw new BuildException( - "no organisation provided for ivy publish task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); - } - if (_module == null) { - throw new BuildException( - "no module name provided for ivy publish task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); - } - if (_revision == null) { - throw new BuildException( - "no module revision provided for ivy publish task: It can either be set explicitely via the attribute 'revision' or via 'ivy.revision' property or a prior call to "); - } - if (_artifactspattern.isEmpty()) { - throw new BuildException( - "no artifacts pattern: either provide it through parameter or through ivy.publish.src.artifacts.pattern property"); - } - if (_publishResolverName == null) { - throw new BuildException( - "no publish deliver name: please provide it through parameter 'resolver'"); - } - if ("working".equals(_revision)) { - _revision = Ivy.getWorkingRevision(); - } - Date pubdate = getPubDate(_pubdate, new Date()); - if (_pubRevision == null) { - if (_revision.startsWith("working@")) { - _pubRevision = Ivy.DATE_FORMAT.format(pubdate); - } else { - _pubRevision = _revision; - } - } - if (_status == null) { - throw new BuildException( - "no status provided: either provide it as parameter or through the ivy.status.default property"); - } - ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); - try { - File ivyFile = new File(IvyPatternHelper.substitute(_srcivypattern, _organisation, - _module, _pubRevision, "ivy", "ivy", "xml")); - if (_publishivy && (!ivyFile.exists() || _forcedeliver)) { - IvyDeliver deliver = new IvyDeliver(); - deliver.setSettingsRef(getSettingsRef()); - deliver.setProject(getProject()); - deliver.setCache(getCache()); - deliver.setDeliverpattern(getSrcivypattern()); - deliver.setDelivertarget(_deliverTarget); - deliver.setDeliveryList(_deliveryList); - deliver.setModule(getModule()); - deliver.setOrganisation(getOrganisation()); - deliver.setPubdate(Ivy.DATE_FORMAT.format(pubdate)); - deliver.setPubrevision(getPubrevision()); - deliver.setRevision(getRevision()); - deliver.setStatus(getStatus()); - deliver.setValidate(doValidate(settings)); - deliver.setReplacedynamicrev(isReplacedynamicrev()); - deliver.setConf(_conf); - - deliver.execute(); - } - - Collection missing = ivy.publish(mrid, _artifactspattern, _publishResolverName, - new PublishOptions().setPubrevision(getPubrevision()).setCache( - CacheManager.getInstance(settings, _cache)).setSrcIvyPattern( - _publishivy ? _srcivypattern : null).setStatus(getStatus()).setPubdate(pubdate) - .setExtraArtifacts( - (Artifact[]) _artifacts.toArray(new Artifact[_artifacts.size()])) - .setValidate(doValidate(settings)).setOverwrite(_overwrite).setUpdate( - _update).setConfs(splitConfs(_conf))); - if (_warnonmissing) { - for (Iterator iter = missing.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - Message.warn("missing artifact: " + artifact); - } - } - if (_haltonmissing && !missing.isEmpty()) { - throw new BuildException("missing published artifacts for " + mrid + ": " + missing); - } - - } catch (Exception e) { - throw new BuildException("impossible to publish artifacts for " + mrid + ": " + e, e); - } - } - - public PublishArtifact createArtifact() { - PublishArtifact art = new PublishArtifact(); - _artifacts.add(art); - return art; - } - - public boolean isPublishivy() { - return _publishivy; - } - - public void setPublishivy(boolean publishivy) { - _publishivy = publishivy; - } - - public boolean isWarnonmissing() { - return _warnonmissing; - } - - public void setWarnonmissing(boolean warnonmissing) { - _warnonmissing = warnonmissing; - } - - public boolean isHaltonmissing() { - return _haltonmissing; - } - - public void setHaltonmissing(boolean haltonmissing) { - _haltonmissing = haltonmissing; - } - - public boolean isOverwrite() { - return _overwrite; - } - - public void setOverwrite(boolean overwrite) { - _overwrite = overwrite; - } - - public void setForcedeliver(boolean b) { - _forcedeliver = b; - } - - public boolean isForcedeliver() { - return _forcedeliver; - } - - public boolean isUpdate() { - return _update; - } - - public void setUpdate(boolean update) { - _update = update; - } - - public class PublishArtifact implements Artifact { - private String _ext; - - private String _name; - - private String _type; - - public String[] getConfigurations() { - return null; - } - - public String getExt() { - return _ext == null ? _type : _ext; - } - - public ArtifactRevisionId getId() { - return null; - } - - public ModuleRevisionId getModuleRevisionId() { - return null; - } - - public String getName() { - return _name; - } - - public Date getPublicationDate() { - return null; - } - - public String getType() { - return _type; - } - - public URL getUrl() { - return null; - } - - public void setExt(String ext) { - _ext = ext; - } - - public void setName(String name) { - _name = name; - } - - public void setType(String type) { - _type = type; - } - - public String getAttribute(String attName) { - return null; - } - - public Map getAttributes() { - return new HashMap(); - } - - public String getExtraAttribute(String attName) { - return null; - } - - public Map getExtraAttributes() { - return new HashMap(); - } - - public String getStandardAttribute(String attName) { - return null; - } - - public Map getStandardAttributes() { - return new HashMap(); - } - } - - public static class ArtifactsPattern { - private String _pattern; - - public String getPattern() { - return _pattern; - } - - public void setPattern(String pattern) { - _pattern = pattern; - } - } -} +/* + * 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.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.id.ArtifactRevisionId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.publish.PublishOptions; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.util.Message; +import org.apache.tools.ant.BuildException; + +/** + * This task allow to publish a module revision to an Ivy repository. + */ +public class IvyPublish extends IvyTask { + private String _organisation; + + private String _module; + + private String _revision; + + private String _pubRevision; + + private File _cache; + + private String _srcivypattern; + + private String _status; + + private String _conf = null; + + private String _pubdate; + + private String _deliverTarget; + + private String _publishResolverName = null; + + private List _artifactspattern = new ArrayList(); + + private File _deliveryList; + + private boolean _publishivy = true; + + private boolean _warnonmissing = true; + + private boolean _haltonmissing = true; + + private boolean _overwrite = false; + + private boolean _update = false; + + private boolean _replacedynamicrev = true; + + private boolean _forcedeliver; + + private Collection _artifacts = new ArrayList(); + + public File getCache() { + return _cache; + } + + public void setCache(File cache) { + _cache = cache; + } + + public String getSrcivypattern() { + return _srcivypattern; + } + + public void setSrcivypattern(String destivypattern) { + _srcivypattern = destivypattern; + } + + /** + * @deprecated use getSrcivypattern instead + * @return + */ + public String getDeliverivypattern() { + return _srcivypattern; + } + + /** + * @deprecated use setSrcivypattern instead + * @return + */ + public void setDeliverivypattern(String destivypattern) { + _srcivypattern = destivypattern; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getPubdate() { + return _pubdate; + } + + public void setPubdate(String pubdate) { + _pubdate = pubdate; + } + + public String getPubrevision() { + return _pubRevision; + } + + public void setPubrevision(String pubRevision) { + _pubRevision = pubRevision; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getStatus() { + return _status; + } + + public void setStatus(String status) { + _status = status; + } + + public void setConf(String conf) { + _conf = conf; + } + + public void setDelivertarget(String deliverTarget) { + _deliverTarget = deliverTarget; + } + + public void setDeliveryList(File deliveryList) { + _deliveryList = deliveryList; + } + + public String getResolver() { + return _publishResolverName; + } + + public void setResolver(String publishResolverName) { + _publishResolverName = publishResolverName; + } + + public String getArtifactspattern() { + return (String) (_artifactspattern.isEmpty() ? null : _artifactspattern.get(0)); + } + + public void setArtifactspattern(String artifactsPattern) { + _artifactspattern.clear(); + _artifactspattern.add(artifactsPattern); + } + + public void addArtifactspattern(String artifactsPattern) { + _artifactspattern.add(artifactsPattern); + } + + public void addConfiguredArtifacts(ArtifactsPattern p) { + _artifactspattern.add(p.getPattern()); + } + + public boolean isReplacedynamicrev() { + return _replacedynamicrev; + } + + public void setReplacedynamicrev(boolean replacedynamicrev) { + _replacedynamicrev = replacedynamicrev; + } + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + + _organisation = getProperty(_organisation, settings, "ivy.organisation"); + _module = getProperty(_module, settings, "ivy.module"); + _revision = getProperty(_revision, settings, "ivy.revision"); + _pubRevision = getProperty(_pubRevision, settings, "ivy.deliver.revision"); + if (_cache == null) { + _cache = settings.getDefaultCache(); + } + if (_artifactspattern.isEmpty()) { + String p = getProperty(null, settings, "ivy.publish.src.artifacts.pattern"); + if (p != null) { + _artifactspattern.add(p); + } + } + if (_srcivypattern == null) { + _srcivypattern = getArtifactspattern(); + } + _status = getProperty(_status, settings, "ivy.status"); + if (_organisation == null) { + throw new BuildException( + "no organisation provided for ivy publish task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); + } + if (_module == null) { + throw new BuildException( + "no module name provided for ivy publish task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); + } + if (_revision == null) { + throw new BuildException( + "no module revision provided for ivy publish task: It can either be set explicitely via the attribute 'revision' or via 'ivy.revision' property or a prior call to "); + } + if (_artifactspattern.isEmpty()) { + throw new BuildException( + "no artifacts pattern: either provide it through parameter or through ivy.publish.src.artifacts.pattern property"); + } + if (_publishResolverName == null) { + throw new BuildException( + "no publish deliver name: please provide it through parameter 'resolver'"); + } + if ("working".equals(_revision)) { + _revision = Ivy.getWorkingRevision(); + } + Date pubdate = getPubDate(_pubdate, new Date()); + if (_pubRevision == null) { + if (_revision.startsWith("working@")) { + _pubRevision = Ivy.DATE_FORMAT.format(pubdate); + } else { + _pubRevision = _revision; + } + } + if (_status == null) { + throw new BuildException( + "no status provided: either provide it as parameter or through the ivy.status.default property"); + } + ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); + try { + File ivyFile = new File(IvyPatternHelper.substitute(_srcivypattern, _organisation, + _module, _pubRevision, "ivy", "ivy", "xml")); + if (_publishivy && (!ivyFile.exists() || _forcedeliver)) { + IvyDeliver deliver = new IvyDeliver(); + deliver.setSettingsRef(getSettingsRef()); + deliver.setProject(getProject()); + deliver.setCache(getCache()); + deliver.setDeliverpattern(getSrcivypattern()); + deliver.setDelivertarget(_deliverTarget); + deliver.setDeliveryList(_deliveryList); + deliver.setModule(getModule()); + deliver.setOrganisation(getOrganisation()); + deliver.setPubdate(Ivy.DATE_FORMAT.format(pubdate)); + deliver.setPubrevision(getPubrevision()); + deliver.setRevision(getRevision()); + deliver.setStatus(getStatus()); + deliver.setValidate(doValidate(settings)); + deliver.setReplacedynamicrev(isReplacedynamicrev()); + deliver.setConf(_conf); + + deliver.execute(); + } + + Collection missing = ivy.publish(mrid, _artifactspattern, _publishResolverName, + new PublishOptions().setPubrevision(getPubrevision()).setCache( + CacheManager.getInstance(settings, _cache)).setSrcIvyPattern( + _publishivy ? _srcivypattern : null).setStatus(getStatus()).setPubdate(pubdate) + .setExtraArtifacts( + (Artifact[]) _artifacts.toArray(new Artifact[_artifacts.size()])) + .setValidate(doValidate(settings)).setOverwrite(_overwrite).setUpdate( + _update).setConfs(splitConfs(_conf))); + if (_warnonmissing) { + for (Iterator iter = missing.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + Message.warn("missing artifact: " + artifact); + } + } + if (_haltonmissing && !missing.isEmpty()) { + throw new BuildException("missing published artifacts for " + mrid + ": " + missing); + } + + } catch (Exception e) { + throw new BuildException("impossible to publish artifacts for " + mrid + ": " + e, e); + } + } + + public PublishArtifact createArtifact() { + PublishArtifact art = new PublishArtifact(); + _artifacts.add(art); + return art; + } + + public boolean isPublishivy() { + return _publishivy; + } + + public void setPublishivy(boolean publishivy) { + _publishivy = publishivy; + } + + public boolean isWarnonmissing() { + return _warnonmissing; + } + + public void setWarnonmissing(boolean warnonmissing) { + _warnonmissing = warnonmissing; + } + + public boolean isHaltonmissing() { + return _haltonmissing; + } + + public void setHaltonmissing(boolean haltonmissing) { + _haltonmissing = haltonmissing; + } + + public boolean isOverwrite() { + return _overwrite; + } + + public void setOverwrite(boolean overwrite) { + _overwrite = overwrite; + } + + public void setForcedeliver(boolean b) { + _forcedeliver = b; + } + + public boolean isForcedeliver() { + return _forcedeliver; + } + + public boolean isUpdate() { + return _update; + } + + public void setUpdate(boolean update) { + _update = update; + } + + public class PublishArtifact implements Artifact { + private String _ext; + + private String _name; + + private String _type; + + public String[] getConfigurations() { + return null; + } + + public String getExt() { + return _ext == null ? _type : _ext; + } + + public ArtifactRevisionId getId() { + return null; + } + + public ModuleRevisionId getModuleRevisionId() { + return null; + } + + public String getName() { + return _name; + } + + public Date getPublicationDate() { + return null; + } + + public String getType() { + return _type; + } + + public URL getUrl() { + return null; + } + + public void setExt(String ext) { + _ext = ext; + } + + public void setName(String name) { + _name = name; + } + + public void setType(String type) { + _type = type; + } + + public String getAttribute(String attName) { + return null; + } + + public Map getAttributes() { + return new HashMap(); + } + + public String getExtraAttribute(String attName) { + return null; + } + + public Map getExtraAttributes() { + return new HashMap(); + } + + public String getStandardAttribute(String attName) { + return null; + } + + public Map getStandardAttributes() { + return new HashMap(); + } + } + + public static class ArtifactsPattern { + private String _pattern; + + public String getPattern() { + return _pattern; + } + + public void setPattern(String pattern) { + _pattern = pattern; + } + } +} diff --git a/src/java/org/apache/ivy/ant/IvyReport.java b/src/java/org/apache/ivy/ant/IvyReport.java index ab2d1333..91954d81 100644 --- a/src/java/org/apache/ivy/ant/IvyReport.java +++ b/src/java/org/apache/ivy/ant/IvyReport.java @@ -1,357 +1,357 @@ -/* - * 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.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.report.XmlReportOutputter; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.XSLTProcess; -import org.apache.tools.ant.types.Mapper; -import org.apache.tools.ant.util.FileNameMapper; -import org.apache.tools.ant.util.GlobPatternMapper; - -/** - * This ant task let users generates reports (html, xml, graphml, ...) from the last resolve done. - */ -public class IvyReport extends IvyTask { - private File _todir; - - private String _organisation; - - private String _module; - - private String _conf; - - private File _cache; - - private boolean _graph = true; - - private boolean _dot = false; - - private boolean _xml = false; - - private boolean _xsl = true; - - private String _xslFile; - - private String _outputpattern; - - private String _xslext = "html"; - - private List _params = new ArrayList(); - - private String _resolveId; - - public File getTodir() { - return _todir; - } - - public void setTodir(File todir) { - _todir = todir; - } - - public File getCache() { - return _cache; - } - - public void setCache(File cache) { - _cache = cache; - } - - public String getConf() { - return _conf; - } - - public void setConf(String conf) { - _conf = conf; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public boolean isGraph() { - return _graph; - } - - public void setGraph(boolean graph) { - _graph = graph; - } - - public String getXslfile() { - return _xslFile; - } - - public void setXslfile(String xslFile) { - _xslFile = xslFile; - } - - public String getOutputpattern() { - return _outputpattern; - } - - public void setOutputpattern(String outputpattern) { - _outputpattern = outputpattern; - } - - public String getResolveId() { - return _resolveId; - } - - public void setResolveId(String resolveId) { - _resolveId = resolveId; - } - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - - _organisation = getProperty(_organisation, settings, "ivy.organisation", _resolveId); - _module = getProperty(_module, settings, "ivy.module", _resolveId); - if (_cache == null) { - _cache = settings.getDefaultCache(); - } - _conf = getProperty(_conf, settings, "ivy.resolved.configurations", _resolveId); - if ("*".equals(_conf)) { - _conf = getProperty(settings, "ivy.resolved.configurations", _resolveId); - } - if (_conf == null) { - throw new BuildException( - "no conf provided for ivy report task: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to "); - } - if (_todir == null) { - String t = getProperty(settings, "ivy.report.todir"); - if (t != null) { - _todir = new File(t); - } - } - _outputpattern = getProperty(_outputpattern, settings, "ivy.report.output.pattern"); - if (_todir != null && _todir.exists()) { - _todir.mkdirs(); - } - if (_outputpattern == null) { - _outputpattern = "[organisation]-[module]-[conf].[ext]"; - } - - if (_todir != null && _todir.exists() && !_todir.isDirectory()) { - throw new BuildException("destination directory should be a directory !"); - } - if (_organisation == null) { - throw new BuildException( - "no organisation provided for ivy report task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); - } - if (_module == null) { - throw new BuildException( - "no module name provided for ivy report task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); - } - if (_resolveId == null) { - _resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(_organisation, _module)); - } - - try { - String[] confs = splitConfs(_conf); - if (_xsl) { - genreport(_cache, _organisation, _module, confs); - } - if (_xml) { - genxml(_cache, _organisation, _module, confs); - } - if (_graph) { - genStyled(_cache, _organisation, _module, confs, getStylePath(_cache, - "ivy-report-graph.xsl"), "graphml"); - } - if (_dot) { - genStyled(_cache, _organisation, _module, confs, getStylePath(_cache, - "ivy-report-dot.xsl"), "dot"); - } - } catch (IOException e) { - throw new BuildException("impossible to generate report: " + e, e); - } - } - - private void genxml(File cache, String organisation, String module, String[] confs) - throws IOException { - CacheManager cacheMgr = getIvyInstance().getCacheManager(_cache); - for (int i = 0; i < confs.length; i++) { - File xml = cacheMgr.getConfigurationResolveReportInCache(_resolveId, confs[i]); - - File out; - if (_todir != null) { - out = new File(_todir, IvyPatternHelper.substitute(_outputpattern, organisation, - module, "", "", "", "xml", confs[i])); - } else { - out = new File(IvyPatternHelper.substitute(_outputpattern, organisation, module, - "", "", "", "xml", confs[i])); - } - - FileUtil.copy(xml, out, null); - } - } - - private void genreport(File cache, String organisation, String module, String[] confs) - throws IOException { - genStyled(cache, organisation, module, confs, getReportStylePath(cache), _xslext); - - // copy the css if required - if (_todir != null && _xslFile == null) { - File css = new File(_todir, "ivy-report.css"); - if (!css.exists()) { - Message.debug("copying report css to " + _todir); - FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.css"), css, - null); - } - FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.css"), new File( - cache, "ivy-report.css"), null); - } - } - - private String getReportStylePath(File cache) throws IOException { - if (_xslFile != null) { - return _xslFile; - } - // style should be a file (and not an url) - // so we have to copy it from classpath to cache - File style = new File(cache, "ivy-report.xsl"); - FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.xsl"), style, null); - return style.getAbsolutePath(); - } - - private void genStyled(File cache, String organisation, String module, String[] confs, - String style, String ext) throws IOException { - // process the report with xslt to generate dot file - File out; - if (_todir != null) { - out = _todir; - } else { - out = new File("."); - } - - XSLTProcess xslt = new XSLTProcess(); - xslt.setTaskName(getTaskName()); - xslt.setProject(getProject()); - xslt.init(); - - xslt.setDestdir(out); - xslt.setBasedir(cache); - - Mapper mapper = new Mapper(getProject()); - xslt.addMapper(mapper); - - CacheManager cacheMgr = getIvyInstance().getCacheManager(cache); - for (int i = 0; i < confs.length; i++) { - File reportFile = cacheMgr.getConfigurationResolveReportInCache(_resolveId, confs[i]); - xslt.setIncludes(reportFile.getName()); - - FileNameMapper reportMapper = new GlobPatternMapper(); - reportMapper.setFrom(reportFile.getName()); - reportMapper.setTo(IvyPatternHelper.substitute(_outputpattern, organisation, module, - "", "", "", ext, confs[i])); - mapper.add(reportMapper); - } - xslt.setStyle(style); - - XSLTProcess.Param param = xslt.createParam(); - param.setName("confs"); - param.setExpression(_conf); - param = xslt.createParam(); - param.setName("extension"); - param.setExpression(_xslext); - - // add the provided XSLT parameters - for (Iterator it = _params.iterator(); it.hasNext();) { - param = (XSLTProcess.Param) it.next(); - XSLTProcess.Param realParam = xslt.createParam(); - realParam.setName(param.getName()); - realParam.setExpression(param.getExpression()); - } - - xslt.execute(); - } - - private String getStylePath(File cache, String styleResourceName) throws IOException { - // style should be a file (and not an url) - // so we have to copy it from classpath to cache - File style = new File(cache, styleResourceName); - FileUtil.copy(XmlReportOutputter.class.getResourceAsStream(styleResourceName), style, null); - return style.getAbsolutePath(); - } - - public boolean isXml() { - return _xml; - } - - public void setXml(boolean xml) { - _xml = xml; - } - - public boolean isXsl() { - return _xsl; - } - - public void setXsl(boolean xsl) { - _xsl = xsl; - } - - public String getXslext() { - return _xslext; - } - - public void setXslext(String xslext) { - _xslext = xslext; - } - - public XSLTProcess.Param createParam() { - XSLTProcess.Param result = new XSLTProcess.Param(); - _params.add(result); - return result; - } - - public boolean isDot() { - return _dot; - } - - public void setDot(boolean dot) { - _dot = dot; - } - -} +/* + * 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.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.report.XmlReportOutputter; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.XSLTProcess; +import org.apache.tools.ant.types.Mapper; +import org.apache.tools.ant.util.FileNameMapper; +import org.apache.tools.ant.util.GlobPatternMapper; + +/** + * This ant task let users generates reports (html, xml, graphml, ...) from the last resolve done. + */ +public class IvyReport extends IvyTask { + private File _todir; + + private String _organisation; + + private String _module; + + private String _conf; + + private File _cache; + + private boolean _graph = true; + + private boolean _dot = false; + + private boolean _xml = false; + + private boolean _xsl = true; + + private String _xslFile; + + private String _outputpattern; + + private String _xslext = "html"; + + private List _params = new ArrayList(); + + private String _resolveId; + + public File getTodir() { + return _todir; + } + + public void setTodir(File todir) { + _todir = todir; + } + + public File getCache() { + return _cache; + } + + public void setCache(File cache) { + _cache = cache; + } + + public String getConf() { + return _conf; + } + + public void setConf(String conf) { + _conf = conf; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public boolean isGraph() { + return _graph; + } + + public void setGraph(boolean graph) { + _graph = graph; + } + + public String getXslfile() { + return _xslFile; + } + + public void setXslfile(String xslFile) { + _xslFile = xslFile; + } + + public String getOutputpattern() { + return _outputpattern; + } + + public void setOutputpattern(String outputpattern) { + _outputpattern = outputpattern; + } + + public String getResolveId() { + return _resolveId; + } + + public void setResolveId(String resolveId) { + _resolveId = resolveId; + } + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + + _organisation = getProperty(_organisation, settings, "ivy.organisation", _resolveId); + _module = getProperty(_module, settings, "ivy.module", _resolveId); + if (_cache == null) { + _cache = settings.getDefaultCache(); + } + _conf = getProperty(_conf, settings, "ivy.resolved.configurations", _resolveId); + if ("*".equals(_conf)) { + _conf = getProperty(settings, "ivy.resolved.configurations", _resolveId); + } + if (_conf == null) { + throw new BuildException( + "no conf provided for ivy report task: It can either be set explicitely via the attribute 'conf' or via 'ivy.resolved.configurations' property or a prior call to "); + } + if (_todir == null) { + String t = getProperty(settings, "ivy.report.todir"); + if (t != null) { + _todir = new File(t); + } + } + _outputpattern = getProperty(_outputpattern, settings, "ivy.report.output.pattern"); + if (_todir != null && _todir.exists()) { + _todir.mkdirs(); + } + if (_outputpattern == null) { + _outputpattern = "[organisation]-[module]-[conf].[ext]"; + } + + if (_todir != null && _todir.exists() && !_todir.isDirectory()) { + throw new BuildException("destination directory should be a directory !"); + } + if (_organisation == null) { + throw new BuildException( + "no organisation provided for ivy report task: It can either be set explicitely via the attribute 'organisation' or via 'ivy.organisation' property or a prior call to "); + } + if (_module == null) { + throw new BuildException( + "no module name provided for ivy report task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); + } + if (_resolveId == null) { + _resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(_organisation, _module)); + } + + try { + String[] confs = splitConfs(_conf); + if (_xsl) { + genreport(_cache, _organisation, _module, confs); + } + if (_xml) { + genxml(_cache, _organisation, _module, confs); + } + if (_graph) { + genStyled(_cache, _organisation, _module, confs, getStylePath(_cache, + "ivy-report-graph.xsl"), "graphml"); + } + if (_dot) { + genStyled(_cache, _organisation, _module, confs, getStylePath(_cache, + "ivy-report-dot.xsl"), "dot"); + } + } catch (IOException e) { + throw new BuildException("impossible to generate report: " + e, e); + } + } + + private void genxml(File cache, String organisation, String module, String[] confs) + throws IOException { + CacheManager cacheMgr = getIvyInstance().getCacheManager(_cache); + for (int i = 0; i < confs.length; i++) { + File xml = cacheMgr.getConfigurationResolveReportInCache(_resolveId, confs[i]); + + File out; + if (_todir != null) { + out = new File(_todir, IvyPatternHelper.substitute(_outputpattern, organisation, + module, "", "", "", "xml", confs[i])); + } else { + out = new File(IvyPatternHelper.substitute(_outputpattern, organisation, module, + "", "", "", "xml", confs[i])); + } + + FileUtil.copy(xml, out, null); + } + } + + private void genreport(File cache, String organisation, String module, String[] confs) + throws IOException { + genStyled(cache, organisation, module, confs, getReportStylePath(cache), _xslext); + + // copy the css if required + if (_todir != null && _xslFile == null) { + File css = new File(_todir, "ivy-report.css"); + if (!css.exists()) { + Message.debug("copying report css to " + _todir); + FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.css"), css, + null); + } + FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.css"), new File( + cache, "ivy-report.css"), null); + } + } + + private String getReportStylePath(File cache) throws IOException { + if (_xslFile != null) { + return _xslFile; + } + // style should be a file (and not an url) + // so we have to copy it from classpath to cache + File style = new File(cache, "ivy-report.xsl"); + FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.xsl"), style, null); + return style.getAbsolutePath(); + } + + private void genStyled(File cache, String organisation, String module, String[] confs, + String style, String ext) throws IOException { + // process the report with xslt to generate dot file + File out; + if (_todir != null) { + out = _todir; + } else { + out = new File("."); + } + + XSLTProcess xslt = new XSLTProcess(); + xslt.setTaskName(getTaskName()); + xslt.setProject(getProject()); + xslt.init(); + + xslt.setDestdir(out); + xslt.setBasedir(cache); + + Mapper mapper = new Mapper(getProject()); + xslt.addMapper(mapper); + + CacheManager cacheMgr = getIvyInstance().getCacheManager(cache); + for (int i = 0; i < confs.length; i++) { + File reportFile = cacheMgr.getConfigurationResolveReportInCache(_resolveId, confs[i]); + xslt.setIncludes(reportFile.getName()); + + FileNameMapper reportMapper = new GlobPatternMapper(); + reportMapper.setFrom(reportFile.getName()); + reportMapper.setTo(IvyPatternHelper.substitute(_outputpattern, organisation, module, + "", "", "", ext, confs[i])); + mapper.add(reportMapper); + } + xslt.setStyle(style); + + XSLTProcess.Param param = xslt.createParam(); + param.setName("confs"); + param.setExpression(_conf); + param = xslt.createParam(); + param.setName("extension"); + param.setExpression(_xslext); + + // add the provided XSLT parameters + for (Iterator it = _params.iterator(); it.hasNext();) { + param = (XSLTProcess.Param) it.next(); + XSLTProcess.Param realParam = xslt.createParam(); + realParam.setName(param.getName()); + realParam.setExpression(param.getExpression()); + } + + xslt.execute(); + } + + private String getStylePath(File cache, String styleResourceName) throws IOException { + // style should be a file (and not an url) + // so we have to copy it from classpath to cache + File style = new File(cache, styleResourceName); + FileUtil.copy(XmlReportOutputter.class.getResourceAsStream(styleResourceName), style, null); + return style.getAbsolutePath(); + } + + public boolean isXml() { + return _xml; + } + + public void setXml(boolean xml) { + _xml = xml; + } + + public boolean isXsl() { + return _xsl; + } + + public void setXsl(boolean xsl) { + _xsl = xsl; + } + + public String getXslext() { + return _xslext; + } + + public void setXslext(String xslext) { + _xslext = xslext; + } + + public XSLTProcess.Param createParam() { + XSLTProcess.Param result = new XSLTProcess.Param(); + _params.add(result); + return result; + } + + public boolean isDot() { + return _dot; + } + + public void setDot(boolean dot) { + _dot = dot; + } + +} diff --git a/src/java/org/apache/ivy/ant/IvyRepositoryReport.java b/src/java/org/apache/ivy/ant/IvyRepositoryReport.java index c49ced9d..533ecbae 100644 --- a/src/java/org/apache/ivy/ant/IvyRepositoryReport.java +++ b/src/java/org/apache/ivy/ant/IvyRepositoryReport.java @@ -1,322 +1,322 @@ -/* - * 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.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.report.XmlReportOutputter; -import org.apache.ivy.util.FileUtil; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.XSLTProcess; - -/** - * Generates a report of dependencies of a set of modules in the repository. The set of modules is - * specified using organisation/module and matcher. - */ -public class IvyRepositoryReport extends IvyTask { - private String _organisation = "*"; - - private String _module; - - private String _branch; - - private String _revision = "latest.integration"; - - private File _cache; - - private String _matcher = PatternMatcher.EXACT_OR_REGEXP; - - private File _todir = new File("."); - - private boolean _graph = false; - - private boolean _dot = false; - - private boolean _xml = true; - - private boolean _xsl = false; - - private String _xslFile; - - private String _outputname = "ivy-repository-report"; - - private String _xslext = "html"; - - private List _params = new ArrayList(); - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - if (_cache == null) { - _cache = settings.getDefaultCache(); - } - if (_xsl && _xslFile == null) { - throw new BuildException("xsl file is mandatory when using xsl generation"); - } - if (_module == null && PatternMatcher.EXACT.equals(_matcher)) { - throw new BuildException( - "no module name provided for ivy repository graph task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); - } else if (_module == null && !PatternMatcher.EXACT.equals(_matcher)) { - _module = PatternMatcher.ANY_EXPRESSION; - } - ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); - - try { - ModuleId[] mids = ivy.listModules(new ModuleId(_organisation, _module), settings - .getMatcher(_matcher)); - ModuleRevisionId[] mrids = new ModuleRevisionId[mids.length]; - for (int i = 0; i < mrids.length; i++) { - if (_branch != null) { - mrids[i] = new ModuleRevisionId(mids[i], _branch, _revision); - } else { - mrids[i] = new ModuleRevisionId(mids[i], _revision); - } - } - DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(mrids, true, - false); - String resolveId = ResolveOptions.getDefaultResolveId(md); - ResolveReport report = ivy.resolve(md, new ResolveOptions().setResolveId(resolveId) - .setCache(CacheManager.getInstance(settings, _cache)).setValidate( - doValidate(settings))); - - CacheManager cacheMgr = getIvyInstance().getCacheManager(_cache); - new XmlReportOutputter().output(report, _cache); - if (_graph) { - gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md - .getModuleRevisionId().getName()); - } - if (_dot) { - gendot(cacheMgr, md.getModuleRevisionId().getOrganisation(), md - .getModuleRevisionId().getName()); - } - if (_xml) { - - FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"), - new File(_todir, _outputname + ".xml"), null); - } - if (_xsl) { - genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md - .getModuleRevisionId().getName()); - } - } catch (Exception e) { - throw new BuildException("impossible to generate graph for " + mrid + ": " + e, e); - } - } - - private void genreport(CacheManager cache, String organisation, String module) - throws IOException { - // first process the report with xslt - XSLTProcess xslt = new XSLTProcess(); - xslt.setTaskName(getTaskName()); - xslt.setProject(getProject()); - xslt.init(); - - String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module)); - xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default")); - xslt.setOut(new File(_todir, _outputname + "." + _xslext)); - - xslt.setStyle(_xslFile); - - XSLTProcess.Param param = xslt.createParam(); - param.setName("extension"); - param.setExpression(_xslext); - - // add the provided XSLT parameters - for (Iterator it = _params.iterator(); it.hasNext();) { - param = (XSLTProcess.Param) it.next(); - XSLTProcess.Param realParam = xslt.createParam(); - realParam.setName(param.getName()); - realParam.setExpression(param.getExpression()); - } - - xslt.execute(); - } - - private void gengraph(CacheManager cache, String organisation, String module) - throws IOException { - gen(cache, organisation, module, getGraphStylePath(cache.getCache()), "graphml"); - } - - private String getGraphStylePath(File cache) throws IOException { - // style should be a file (and not an url) - // so we have to copy it from classpath to cache - File style = new File(cache, "ivy-report-graph-all.xsl"); - FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report-graph-all.xsl"), - style, null); - return style.getAbsolutePath(); - } - - private void gendot(CacheManager cache, String organisation, String module) throws IOException { - gen(cache, organisation, module, getDotStylePath(cache.getCache()), "dot"); - } - - private String getDotStylePath(File cache) throws IOException { - // style should be a file (and not an url) - // so we have to copy it from classpath to cache - File style = new File(cache, "ivy-report-dot-all.xsl"); - FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report-dot-all.xsl"), - style, null); - return style.getAbsolutePath(); - } - - private void gen(CacheManager cache, String organisation, String module, String style, - String ext) throws IOException { - XSLTProcess xslt = new XSLTProcess(); - xslt.setTaskName(getTaskName()); - xslt.setProject(getProject()); - xslt.init(); - - String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module)); - xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default")); - xslt.setOut(new File(_todir, _outputname + "." + ext)); - xslt.setBasedir(cache.getCache()); - xslt.setStyle(style); - xslt.execute(); - } - - public File getTodir() { - return _todir; - } - - public void setTodir(File todir) { - _todir = todir; - } - - public boolean isGraph() { - return _graph; - } - - public void setGraph(boolean graph) { - _graph = graph; - } - - public String getXslfile() { - return _xslFile; - } - - public void setXslfile(String xslFile) { - _xslFile = xslFile; - } - - public boolean isXml() { - return _xml; - } - - public void setXml(boolean xml) { - _xml = xml; - } - - public boolean isXsl() { - return _xsl; - } - - public void setXsl(boolean xsl) { - _xsl = xsl; - } - - public String getXslext() { - return _xslext; - } - - public void setXslext(String xslext) { - _xslext = xslext; - } - - public XSLTProcess.Param createParam() { - XSLTProcess.Param result = new XSLTProcess.Param(); - _params.add(result); - return result; - } - - public String getOutputname() { - return _outputname; - } - - public void setOutputname(String outputpattern) { - _outputname = outputpattern; - } - - public File getCache() { - return _cache; - } - - public void setCache(File cache) { - _cache = cache; - } - - public String getMatcher() { - return _matcher; - } - - public void setMatcher(String matcher) { - _matcher = matcher; - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getBranch() { - return _branch; - } - - public void setBranch(String branch) { - _branch = branch; - } - - public boolean isDot() { - return _dot; - } - - public void setDot(boolean dot) { - _dot = dot; - } -} +/* + * 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.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.report.XmlReportOutputter; +import org.apache.ivy.util.FileUtil; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.XSLTProcess; + +/** + * Generates a report of dependencies of a set of modules in the repository. The set of modules is + * specified using organisation/module and matcher. + */ +public class IvyRepositoryReport extends IvyTask { + private String _organisation = "*"; + + private String _module; + + private String _branch; + + private String _revision = "latest.integration"; + + private File _cache; + + private String _matcher = PatternMatcher.EXACT_OR_REGEXP; + + private File _todir = new File("."); + + private boolean _graph = false; + + private boolean _dot = false; + + private boolean _xml = true; + + private boolean _xsl = false; + + private String _xslFile; + + private String _outputname = "ivy-repository-report"; + + private String _xslext = "html"; + + private List _params = new ArrayList(); + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + if (_cache == null) { + _cache = settings.getDefaultCache(); + } + if (_xsl && _xslFile == null) { + throw new BuildException("xsl file is mandatory when using xsl generation"); + } + if (_module == null && PatternMatcher.EXACT.equals(_matcher)) { + throw new BuildException( + "no module name provided for ivy repository graph task: It can either be set explicitely via the attribute 'module' or via 'ivy.module' property or a prior call to "); + } else if (_module == null && !PatternMatcher.EXACT.equals(_matcher)) { + _module = PatternMatcher.ANY_EXPRESSION; + } + ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); + + try { + ModuleId[] mids = ivy.listModules(new ModuleId(_organisation, _module), settings + .getMatcher(_matcher)); + ModuleRevisionId[] mrids = new ModuleRevisionId[mids.length]; + for (int i = 0; i < mrids.length; i++) { + if (_branch != null) { + mrids[i] = new ModuleRevisionId(mids[i], _branch, _revision); + } else { + mrids[i] = new ModuleRevisionId(mids[i], _revision); + } + } + DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(mrids, true, + false); + String resolveId = ResolveOptions.getDefaultResolveId(md); + ResolveReport report = ivy.resolve(md, new ResolveOptions().setResolveId(resolveId) + .setCache(CacheManager.getInstance(settings, _cache)).setValidate( + doValidate(settings))); + + CacheManager cacheMgr = getIvyInstance().getCacheManager(_cache); + new XmlReportOutputter().output(report, _cache); + if (_graph) { + gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md + .getModuleRevisionId().getName()); + } + if (_dot) { + gendot(cacheMgr, md.getModuleRevisionId().getOrganisation(), md + .getModuleRevisionId().getName()); + } + if (_xml) { + + FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"), + new File(_todir, _outputname + ".xml"), null); + } + if (_xsl) { + genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md + .getModuleRevisionId().getName()); + } + } catch (Exception e) { + throw new BuildException("impossible to generate graph for " + mrid + ": " + e, e); + } + } + + private void genreport(CacheManager cache, String organisation, String module) + throws IOException { + // first process the report with xslt + XSLTProcess xslt = new XSLTProcess(); + xslt.setTaskName(getTaskName()); + xslt.setProject(getProject()); + xslt.init(); + + String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module)); + xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default")); + xslt.setOut(new File(_todir, _outputname + "." + _xslext)); + + xslt.setStyle(_xslFile); + + XSLTProcess.Param param = xslt.createParam(); + param.setName("extension"); + param.setExpression(_xslext); + + // add the provided XSLT parameters + for (Iterator it = _params.iterator(); it.hasNext();) { + param = (XSLTProcess.Param) it.next(); + XSLTProcess.Param realParam = xslt.createParam(); + realParam.setName(param.getName()); + realParam.setExpression(param.getExpression()); + } + + xslt.execute(); + } + + private void gengraph(CacheManager cache, String organisation, String module) + throws IOException { + gen(cache, organisation, module, getGraphStylePath(cache.getCache()), "graphml"); + } + + private String getGraphStylePath(File cache) throws IOException { + // style should be a file (and not an url) + // so we have to copy it from classpath to cache + File style = new File(cache, "ivy-report-graph-all.xsl"); + FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report-graph-all.xsl"), + style, null); + return style.getAbsolutePath(); + } + + private void gendot(CacheManager cache, String organisation, String module) throws IOException { + gen(cache, organisation, module, getDotStylePath(cache.getCache()), "dot"); + } + + private String getDotStylePath(File cache) throws IOException { + // style should be a file (and not an url) + // so we have to copy it from classpath to cache + File style = new File(cache, "ivy-report-dot-all.xsl"); + FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report-dot-all.xsl"), + style, null); + return style.getAbsolutePath(); + } + + private void gen(CacheManager cache, String organisation, String module, String style, + String ext) throws IOException { + XSLTProcess xslt = new XSLTProcess(); + xslt.setTaskName(getTaskName()); + xslt.setProject(getProject()); + xslt.init(); + + String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module)); + xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default")); + xslt.setOut(new File(_todir, _outputname + "." + ext)); + xslt.setBasedir(cache.getCache()); + xslt.setStyle(style); + xslt.execute(); + } + + public File getTodir() { + return _todir; + } + + public void setTodir(File todir) { + _todir = todir; + } + + public boolean isGraph() { + return _graph; + } + + public void setGraph(boolean graph) { + _graph = graph; + } + + public String getXslfile() { + return _xslFile; + } + + public void setXslfile(String xslFile) { + _xslFile = xslFile; + } + + public boolean isXml() { + return _xml; + } + + public void setXml(boolean xml) { + _xml = xml; + } + + public boolean isXsl() { + return _xsl; + } + + public void setXsl(boolean xsl) { + _xsl = xsl; + } + + public String getXslext() { + return _xslext; + } + + public void setXslext(String xslext) { + _xslext = xslext; + } + + public XSLTProcess.Param createParam() { + XSLTProcess.Param result = new XSLTProcess.Param(); + _params.add(result); + return result; + } + + public String getOutputname() { + return _outputname; + } + + public void setOutputname(String outputpattern) { + _outputname = outputpattern; + } + + public File getCache() { + return _cache; + } + + public void setCache(File cache) { + _cache = cache; + } + + public String getMatcher() { + return _matcher; + } + + public void setMatcher(String matcher) { + _matcher = matcher; + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getBranch() { + return _branch; + } + + public void setBranch(String branch) { + _branch = branch; + } + + public boolean isDot() { + return _dot; + } + + public void setDot(boolean dot) { + _dot = dot; + } +} diff --git a/src/java/org/apache/ivy/ant/IvyResolve.java b/src/java/org/apache/ivy/ant/IvyResolve.java index a93e47cc..0446066b 100644 --- a/src/java/org/apache/ivy/ant/IvyResolve.java +++ b/src/java/org/apache/ivy/ant/IvyResolve.java @@ -1,357 +1,357 @@ -/* - * 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.net.MalformedURLException; -import java.text.ParseException; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.filter.FilterHelper; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; - -/** - * This task allow to call the Ivy dependency resolution from ant. - */ -public class IvyResolve extends IvyTask { - private File _file = null; - - private String _conf = null; - - private File _cache = null; - - private String _organisation = null; - - private String _module = null; - - private String _revision = null; - - private String _pubdate = null; - - private boolean _inline = false; - - private boolean _haltOnFailure = true; - - private boolean _useCacheOnly = false; - - private String _type = null; - - private boolean _transitive = true; - - private boolean _changing = false; - - private Boolean _keep = null; - - private String _failureProperty = null; - - private boolean _useOrigin = false; - - private String _resolveId = null; - - public boolean isUseOrigin() { - return _useOrigin; - } - - public void setUseOrigin(boolean useOrigin) { - _useOrigin = useOrigin; - } - - public String getDate() { - return _pubdate; - } - - public void setDate(String pubdate) { - _pubdate = pubdate; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public File getCache() { - return _cache; - } - - public void setCache(File cache) { - _cache = cache; - } - - public String getConf() { - return _conf; - } - - public void setConf(String conf) { - _conf = conf; - } - - public File getFile() { - return _file; - } - - public void setFile(File file) { - _file = file; - } - - public boolean isHaltonfailure() { - return _haltOnFailure; - } - - public void setHaltonfailure(boolean haltOnFailure) { - _haltOnFailure = haltOnFailure; - } - - public void setShowprogress(boolean show) { - Message.setShowProgress(show); - } - - public boolean isUseCacheOnly() { - return _useCacheOnly; - } - - public void setUseCacheOnly(boolean useCacheOnly) { - _useCacheOnly = useCacheOnly; - } - - public String getType() { - return _type; - } - - public void setType(String type) { - _type = type; - } - - /** - * @deprecated Use {@link #setFailureProperty(String)} instead - */ - public void setFailurePropery(String failureProperty) { - log("The 'failurepropery' attribute is deprecated. " - + "Please use the 'failureproperty' attribute instead", Project.MSG_WARN); - setFailureProperty(failureProperty); - } - - public void setFailureProperty(String failureProperty) { - _failureProperty = failureProperty; - } - - public String getFailureProperty() { - return _failureProperty; - } - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - try { - _conf = getProperty(_conf, settings, "ivy.configurations"); - _type = getProperty(_type, settings, "ivy.resolve.default.type.filter"); - if (_cache == null) { - _cache = settings.getDefaultCache(); - } - String[] confs = splitConfs(_conf); - - ResolveReport report; - if (isInline()) { - if (_organisation == null) { - throw new BuildException("'organisation' is required when using inline mode"); - } - if (_module == null) { - throw new BuildException("'module' is required when using inline mode"); - } - if (_file != null) { - throw new BuildException("'file' not allowed when using inline mode"); - } - if (_revision == null) { - _revision = "latest.integration"; - } - report = ivy.resolve(ModuleRevisionId - .newInstance(_organisation, _module, _revision), getResolveOptions(confs, - settings), _changing); - - } else { - if (_organisation != null) { - throw new BuildException( - "'organisation' not allowed when not using 'org' attribute"); - } - if (_module != null) { - throw new BuildException("'module' not allowed when not using 'org' attribute"); - } - if (_file == null) { - _file = getProject().resolveFile(getProperty(settings, "ivy.dep.file")); - } - report = ivy.resolve(_file.toURL(), getResolveOptions(confs, settings)); - } - if (report.hasError()) { - if (_failureProperty != null) { - getProject().setProperty(_failureProperty, "true"); - } - if (isHaltonfailure()) { - throw new BuildException("resolve failed - see output for details"); - } - } - setResolved(report, _resolveId, isKeep()); - - if (isKeep()) { - ModuleDescriptor md = report.getModuleDescriptor(); - // put resolved infos in ant properties and ivy variables - // putting them in ivy variables is important to be able to change from one resolve - // call to the other - getProject().setProperty("ivy.organisation", - md.getModuleRevisionId().getOrganisation()); - settings - .setVariable("ivy.organisation", md.getModuleRevisionId().getOrganisation()); - getProject().setProperty("ivy.module", md.getModuleRevisionId().getName()); - settings.setVariable("ivy.module", md.getModuleRevisionId().getName()); - getProject().setProperty("ivy.revision", - md.getResolvedModuleRevisionId().getRevision()); - settings - .setVariable("ivy.revision", md.getResolvedModuleRevisionId().getRevision()); - boolean hasChanged = report.hasChanged(); - getProject().setProperty("ivy.deps.changed", String.valueOf(hasChanged)); - settings.setVariable("ivy.deps.changed", String.valueOf(hasChanged)); - if (_conf.trim().equals("*")) { - getProject().setProperty("ivy.resolved.configurations", - mergeConfs(md.getConfigurationsNames())); - settings.setVariable("ivy.resolved.configurations", mergeConfs(md - .getConfigurationsNames())); - } else { - getProject().setProperty("ivy.resolved.configurations", _conf); - settings.setVariable("ivy.resolved.configurations", _conf); - } - if (_file != null) { - getProject().setProperty("ivy.resolved.file", _file.getAbsolutePath()); - settings.setVariable("ivy.resolved.file", _file.getAbsolutePath()); - } - if (_resolveId != null) { - getProject().setProperty("ivy.organisation." + _resolveId, - md.getModuleRevisionId().getOrganisation()); - settings.setVariable("ivy.organisation." + _resolveId, md.getModuleRevisionId() - .getOrganisation()); - getProject().setProperty("ivy.module." + _resolveId, - md.getModuleRevisionId().getName()); - settings.setVariable("ivy.module." + _resolveId, md.getModuleRevisionId() - .getName()); - getProject().setProperty("ivy.revision." + _resolveId, - md.getResolvedModuleRevisionId().getRevision()); - settings.setVariable("ivy.revision." + _resolveId, md - .getResolvedModuleRevisionId().getRevision()); - getProject().setProperty("ivy.deps.changed." + _resolveId, - String.valueOf(hasChanged)); - settings.setVariable("ivy.deps.changed." + _resolveId, String - .valueOf(hasChanged)); - if (_conf.trim().equals("*")) { - getProject().setProperty("ivy.resolved.configurations." + _resolveId, - mergeConfs(md.getConfigurationsNames())); - settings.setVariable("ivy.resolved.configurations." + _resolveId, - mergeConfs(md.getConfigurationsNames())); - } else { - getProject() - .setProperty("ivy.resolved.configurations." + _resolveId, _conf); - settings.setVariable("ivy.resolved.configurations." + _resolveId, _conf); - } - getProject().setProperty("ivy.resolved.file." + _resolveId, - _file.getAbsolutePath()); - settings - .setVariable("ivy.resolved.file." + _resolveId, _file.getAbsolutePath()); - } - } - } catch (MalformedURLException e) { - throw new BuildException( - "unable to convert given ivy file to url: " + _file + ": " + e, e); - } catch (ParseException e) { - log(e.getMessage(), Project.MSG_ERR); - throw new BuildException("syntax errors in ivy file: " + e, e); - } catch (Exception e) { - throw new BuildException("impossible to resolve dependencies: " + e, e); - } - } - - private ResolveOptions getResolveOptions(String[] confs, IvySettings settings) { - return new ResolveOptions().setConfs(confs).setValidate(doValidate(settings)) - .setArtifactFilter(FilterHelper.getArtifactTypeFilter(_type)) - .setRevision(_revision).setCache(CacheManager.getInstance(settings, _cache)) - .setDate(getPubDate(_pubdate, null)).setUseCacheOnly(_useCacheOnly).setUseOrigin( - _useOrigin).setTransitive(_transitive).setResolveId(_resolveId); - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public boolean isTransitive() { - return _transitive; - } - - public void setTransitive(boolean transitive) { - _transitive = transitive; - } - - public boolean isChanging() { - return _changing; - } - - public void setChanging(boolean changing) { - _changing = changing; - } - - public boolean isKeep() { - return _keep == null ? _organisation == null : _keep.booleanValue(); - } - - public void setKeep(boolean keep) { - _keep = Boolean.valueOf(keep); - } - - public boolean isInline() { - return _inline; - } - - public void setInline(boolean inline) { - _inline = inline; - } - - public String getResolveId() { - return _resolveId; - } - - public void setResolveId(String resolveId) { - _resolveId = resolveId; - } -} +/* + * 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.net.MalformedURLException; +import java.text.ParseException; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.filter.FilterHelper; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; + +/** + * This task allow to call the Ivy dependency resolution from ant. + */ +public class IvyResolve extends IvyTask { + private File _file = null; + + private String _conf = null; + + private File _cache = null; + + private String _organisation = null; + + private String _module = null; + + private String _revision = null; + + private String _pubdate = null; + + private boolean _inline = false; + + private boolean _haltOnFailure = true; + + private boolean _useCacheOnly = false; + + private String _type = null; + + private boolean _transitive = true; + + private boolean _changing = false; + + private Boolean _keep = null; + + private String _failureProperty = null; + + private boolean _useOrigin = false; + + private String _resolveId = null; + + public boolean isUseOrigin() { + return _useOrigin; + } + + public void setUseOrigin(boolean useOrigin) { + _useOrigin = useOrigin; + } + + public String getDate() { + return _pubdate; + } + + public void setDate(String pubdate) { + _pubdate = pubdate; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public File getCache() { + return _cache; + } + + public void setCache(File cache) { + _cache = cache; + } + + public String getConf() { + return _conf; + } + + public void setConf(String conf) { + _conf = conf; + } + + public File getFile() { + return _file; + } + + public void setFile(File file) { + _file = file; + } + + public boolean isHaltonfailure() { + return _haltOnFailure; + } + + public void setHaltonfailure(boolean haltOnFailure) { + _haltOnFailure = haltOnFailure; + } + + public void setShowprogress(boolean show) { + Message.setShowProgress(show); + } + + public boolean isUseCacheOnly() { + return _useCacheOnly; + } + + public void setUseCacheOnly(boolean useCacheOnly) { + _useCacheOnly = useCacheOnly; + } + + public String getType() { + return _type; + } + + public void setType(String type) { + _type = type; + } + + /** + * @deprecated Use {@link #setFailureProperty(String)} instead + */ + public void setFailurePropery(String failureProperty) { + log("The 'failurepropery' attribute is deprecated. " + + "Please use the 'failureproperty' attribute instead", Project.MSG_WARN); + setFailureProperty(failureProperty); + } + + public void setFailureProperty(String failureProperty) { + _failureProperty = failureProperty; + } + + public String getFailureProperty() { + return _failureProperty; + } + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + try { + _conf = getProperty(_conf, settings, "ivy.configurations"); + _type = getProperty(_type, settings, "ivy.resolve.default.type.filter"); + if (_cache == null) { + _cache = settings.getDefaultCache(); + } + String[] confs = splitConfs(_conf); + + ResolveReport report; + if (isInline()) { + if (_organisation == null) { + throw new BuildException("'organisation' is required when using inline mode"); + } + if (_module == null) { + throw new BuildException("'module' is required when using inline mode"); + } + if (_file != null) { + throw new BuildException("'file' not allowed when using inline mode"); + } + if (_revision == null) { + _revision = "latest.integration"; + } + report = ivy.resolve(ModuleRevisionId + .newInstance(_organisation, _module, _revision), getResolveOptions(confs, + settings), _changing); + + } else { + if (_organisation != null) { + throw new BuildException( + "'organisation' not allowed when not using 'org' attribute"); + } + if (_module != null) { + throw new BuildException("'module' not allowed when not using 'org' attribute"); + } + if (_file == null) { + _file = getProject().resolveFile(getProperty(settings, "ivy.dep.file")); + } + report = ivy.resolve(_file.toURL(), getResolveOptions(confs, settings)); + } + if (report.hasError()) { + if (_failureProperty != null) { + getProject().setProperty(_failureProperty, "true"); + } + if (isHaltonfailure()) { + throw new BuildException("resolve failed - see output for details"); + } + } + setResolved(report, _resolveId, isKeep()); + + if (isKeep()) { + ModuleDescriptor md = report.getModuleDescriptor(); + // put resolved infos in ant properties and ivy variables + // putting them in ivy variables is important to be able to change from one resolve + // call to the other + getProject().setProperty("ivy.organisation", + md.getModuleRevisionId().getOrganisation()); + settings + .setVariable("ivy.organisation", md.getModuleRevisionId().getOrganisation()); + getProject().setProperty("ivy.module", md.getModuleRevisionId().getName()); + settings.setVariable("ivy.module", md.getModuleRevisionId().getName()); + getProject().setProperty("ivy.revision", + md.getResolvedModuleRevisionId().getRevision()); + settings + .setVariable("ivy.revision", md.getResolvedModuleRevisionId().getRevision()); + boolean hasChanged = report.hasChanged(); + getProject().setProperty("ivy.deps.changed", String.valueOf(hasChanged)); + settings.setVariable("ivy.deps.changed", String.valueOf(hasChanged)); + if (_conf.trim().equals("*")) { + getProject().setProperty("ivy.resolved.configurations", + mergeConfs(md.getConfigurationsNames())); + settings.setVariable("ivy.resolved.configurations", mergeConfs(md + .getConfigurationsNames())); + } else { + getProject().setProperty("ivy.resolved.configurations", _conf); + settings.setVariable("ivy.resolved.configurations", _conf); + } + if (_file != null) { + getProject().setProperty("ivy.resolved.file", _file.getAbsolutePath()); + settings.setVariable("ivy.resolved.file", _file.getAbsolutePath()); + } + if (_resolveId != null) { + getProject().setProperty("ivy.organisation." + _resolveId, + md.getModuleRevisionId().getOrganisation()); + settings.setVariable("ivy.organisation." + _resolveId, md.getModuleRevisionId() + .getOrganisation()); + getProject().setProperty("ivy.module." + _resolveId, + md.getModuleRevisionId().getName()); + settings.setVariable("ivy.module." + _resolveId, md.getModuleRevisionId() + .getName()); + getProject().setProperty("ivy.revision." + _resolveId, + md.getResolvedModuleRevisionId().getRevision()); + settings.setVariable("ivy.revision." + _resolveId, md + .getResolvedModuleRevisionId().getRevision()); + getProject().setProperty("ivy.deps.changed." + _resolveId, + String.valueOf(hasChanged)); + settings.setVariable("ivy.deps.changed." + _resolveId, String + .valueOf(hasChanged)); + if (_conf.trim().equals("*")) { + getProject().setProperty("ivy.resolved.configurations." + _resolveId, + mergeConfs(md.getConfigurationsNames())); + settings.setVariable("ivy.resolved.configurations." + _resolveId, + mergeConfs(md.getConfigurationsNames())); + } else { + getProject() + .setProperty("ivy.resolved.configurations." + _resolveId, _conf); + settings.setVariable("ivy.resolved.configurations." + _resolveId, _conf); + } + getProject().setProperty("ivy.resolved.file." + _resolveId, + _file.getAbsolutePath()); + settings + .setVariable("ivy.resolved.file." + _resolveId, _file.getAbsolutePath()); + } + } + } catch (MalformedURLException e) { + throw new BuildException( + "unable to convert given ivy file to url: " + _file + ": " + e, e); + } catch (ParseException e) { + log(e.getMessage(), Project.MSG_ERR); + throw new BuildException("syntax errors in ivy file: " + e, e); + } catch (Exception e) { + throw new BuildException("impossible to resolve dependencies: " + e, e); + } + } + + private ResolveOptions getResolveOptions(String[] confs, IvySettings settings) { + return new ResolveOptions().setConfs(confs).setValidate(doValidate(settings)) + .setArtifactFilter(FilterHelper.getArtifactTypeFilter(_type)) + .setRevision(_revision).setCache(CacheManager.getInstance(settings, _cache)) + .setDate(getPubDate(_pubdate, null)).setUseCacheOnly(_useCacheOnly).setUseOrigin( + _useOrigin).setTransitive(_transitive).setResolveId(_resolveId); + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public boolean isTransitive() { + return _transitive; + } + + public void setTransitive(boolean transitive) { + _transitive = transitive; + } + + public boolean isChanging() { + return _changing; + } + + public void setChanging(boolean changing) { + _changing = changing; + } + + public boolean isKeep() { + return _keep == null ? _organisation == null : _keep.booleanValue(); + } + + public void setKeep(boolean keep) { + _keep = Boolean.valueOf(keep); + } + + public boolean isInline() { + return _inline; + } + + public void setInline(boolean inline) { + _inline = inline; + } + + public String getResolveId() { + return _resolveId; + } + + public void setResolveId(String resolveId) { + _resolveId = resolveId; + } +} diff --git a/src/java/org/apache/ivy/ant/IvyRetrieve.java b/src/java/org/apache/ivy/ant/IvyRetrieve.java index fecd82c2..b759be9b 100644 --- a/src/java/org/apache/ivy/ant/IvyRetrieve.java +++ b/src/java/org/apache/ivy/ant/IvyRetrieve.java @@ -1,88 +1,88 @@ -/* - * 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 org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.retrieve.RetrieveOptions; -import org.apache.ivy.util.filter.Filter; -import org.apache.tools.ant.BuildException; - -/** - * This task allow to retrieve dependencies from the cache to a local directory like a lib dir. - */ -public class IvyRetrieve extends IvyPostResolveTask { - private String _pattern; - - private String _ivypattern = null; - - private boolean _sync = false; - - private boolean _symlink = false; - - public String getPattern() { - return _pattern; - } - - public void setPattern(String pattern) { - _pattern = pattern; - } - - public void doExecute() throws BuildException { - prepareAndCheck(); - - _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern"); - try { - Filter artifactFilter = getArtifactFilter(); - int targetsCopied = getIvyInstance().retrieve( - getResolvedMrid(), - _pattern, - new RetrieveOptions().setConfs(splitConfs(getConf())).setCache( - CacheManager.getInstance(getIvyInstance().getSettings(), getCache())) - .setDestIvyPattern(_ivypattern).setArtifactFilter(artifactFilter).setSync( - _sync).setUseOrigin(isUseOrigin()).setMakeSymlinks(_symlink)); - boolean haveTargetsBeenCopied = targetsCopied > 0; - getProject().setProperty("ivy.nb.targets.copied", String.valueOf(targetsCopied)); - getProject().setProperty("ivy.targets.copied", String.valueOf(haveTargetsBeenCopied)); - } catch (Exception ex) { - throw new BuildException("impossible to ivy retrieve: " + ex, ex); - } - } - - public String getIvypattern() { - return _ivypattern; - } - - public void setIvypattern(String ivypattern) { - _ivypattern = ivypattern; - } - - public boolean isSync() { - return _sync; - } - - public void setSync(boolean sync) { - _sync = sync; - } - - /** - * Option to create symlinks instead of copying. - */ - public void setSymlink(boolean symlink) { - _symlink = symlink; - } -} +/* + * 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 org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.retrieve.RetrieveOptions; +import org.apache.ivy.util.filter.Filter; +import org.apache.tools.ant.BuildException; + +/** + * This task allow to retrieve dependencies from the cache to a local directory like a lib dir. + */ +public class IvyRetrieve extends IvyPostResolveTask { + private String _pattern; + + private String _ivypattern = null; + + private boolean _sync = false; + + private boolean _symlink = false; + + public String getPattern() { + return _pattern; + } + + public void setPattern(String pattern) { + _pattern = pattern; + } + + public void doExecute() throws BuildException { + prepareAndCheck(); + + _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern"); + try { + Filter artifactFilter = getArtifactFilter(); + int targetsCopied = getIvyInstance().retrieve( + getResolvedMrid(), + _pattern, + new RetrieveOptions().setConfs(splitConfs(getConf())).setCache( + CacheManager.getInstance(getIvyInstance().getSettings(), getCache())) + .setDestIvyPattern(_ivypattern).setArtifactFilter(artifactFilter).setSync( + _sync).setUseOrigin(isUseOrigin()).setMakeSymlinks(_symlink)); + boolean haveTargetsBeenCopied = targetsCopied > 0; + getProject().setProperty("ivy.nb.targets.copied", String.valueOf(targetsCopied)); + getProject().setProperty("ivy.targets.copied", String.valueOf(haveTargetsBeenCopied)); + } catch (Exception ex) { + throw new BuildException("impossible to ivy retrieve: " + ex, ex); + } + } + + public String getIvypattern() { + return _ivypattern; + } + + public void setIvypattern(String ivypattern) { + _ivypattern = ivypattern; + } + + public boolean isSync() { + return _sync; + } + + public void setSync(boolean sync) { + _sync = sync; + } + + /** + * Option to create symlinks instead of copying. + */ + public void setSymlink(boolean symlink) { + _symlink = symlink; + } +} diff --git a/src/java/org/apache/ivy/ant/IvyTask.java b/src/java/org/apache/ivy/ant/IvyTask.java index e410c7e6..eb09c824 100644 --- a/src/java/org/apache/ivy/ant/IvyTask.java +++ b/src/java/org/apache/ivy/ant/IvyTask.java @@ -1,292 +1,292 @@ -/* - * 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.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.StringUtils; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Reference; - -/** - * Base class for all ivy ant tasks, deal particularly with ivy instance storage in ant project. - */ -public abstract class IvyTask extends Task { - public static final String ANT_PROJECT_CONTEXT_KEY = "ant-project"; - - private Boolean _validate = null; - - private Reference _antIvyEngineRef = null; - - protected boolean doValidate(IvySettings ivy) { - if (_validate != null) { - return _validate.booleanValue(); - } - return ivy.doValidate(); - } - - public boolean isValidate() { - return _validate == null ? true : _validate.booleanValue(); - } - - public void setValidate(boolean validate) { - _validate = Boolean.valueOf(validate); - } - - public void setSettingsRef(Reference ref) { - _antIvyEngineRef = ref; - } - - public Reference getSettingsRef() { - return _antIvyEngineRef; - } - - protected IvySettings getSettings() { - return getIvyInstance().getSettings(); - } - - protected Ivy getIvyInstance() { - ensureMessageInitialised(); - Object antIvyEngine; - if (_antIvyEngineRef != null) { - antIvyEngine = _antIvyEngineRef.getReferencedObject(); - if (!antIvyEngine.getClass().getName().equals(IvyAntSettings.class.getName())) { - throw new BuildException(_antIvyEngineRef.getRefId() - + " doesn't reference an ivy:settings", getLocation()); - } - if (!(antIvyEngine instanceof IvyAntSettings)) { - throw new BuildException( - _antIvyEngineRef.getRefId() - + " has been defined in a different classloader. Please use the same loader when defining your task, or redeclare your ivy:settings in this classloader", - getLocation()); - } - } else { - antIvyEngine = IvyAntSettings.getDefaultInstance(getProject()); - } - return ((IvyAntSettings) antIvyEngine).getConfiguredIvyInstance(); - } - - /** - * Every task MUST call ensureMessageInitialised when the execution method starts (at least - * before doing any log in order to set the correct task in the log. - */ - protected void ensureMessageInitialised() { - if (!Message.isInitialised()) { - Message.init(new AntMessageImpl(this)); - } - } - - protected void setResolved(ResolveReport report, boolean keep) { - ModuleDescriptor md = report.getModuleDescriptor(); - String[] confs = report.getConfigurations(); - if (keep) { - getProject().addReference("ivy.resolved.report", report); - getProject().addReference("ivy.resolved.configurations.ref", confs); - getProject().addReference("ivy.resolved.descriptor", md); - } - String suffix = md.getModuleRevisionId().getModuleId().getOrganisation() + "." - + md.getModuleRevisionId().getModuleId().getName(); - getProject().addReference("ivy.resolved.report." + suffix, report); - getProject().addReference("ivy.resolved.descriptor." + suffix, md); - getProject().addReference("ivy.resolved.configurations.ref." + suffix, confs); - } - - protected void setResolved(ResolveReport report, String resolveId, boolean keep) { - setResolved(report, keep); - if (resolveId != null) { - ModuleDescriptor md = report.getModuleDescriptor(); - String[] confs = report.getConfigurations(); - getProject().addReference("ivy.resolved.report." + resolveId, report); - getProject().addReference("ivy.resolved.descriptor." + resolveId, md); - getProject().addReference("ivy.resolved.configurations.ref." + resolveId, confs); - } - } - - protected String[] getResolvedConfigurations(String org, String module, boolean strict) { - return (String[]) getReference("ivy.resolved.configurations.ref", org, module, strict); - } - - protected Object getResolvedDescriptor(String resolveId) { - return getResolvedDescriptor(resolveId, true); - } - - protected Object getResolvedDescriptor(String resolveId, boolean strict) { - Object result = getProject().getReference("ivy.resolved.descriptor." + resolveId); - if (strict && (result == null)) { - throw new BuildException("ModuleDescriptor for resolve with id '" + resolveId - + "' not found."); - } - return result; - } - - protected Object getResolvedDescriptor(String org, String module) { - return getResolvedDescriptor(org, module, false); - } - - protected Object getResolvedDescriptor(String org, String module, boolean strict) { - return getReference("ivy.resolved.descriptor", org, module, strict); - } - - private Object getReference(String prefix, String org, String module, boolean strict) { - Object reference = null; - if (org != null && module != null) { - reference = getProject().getReference(prefix + "." + org + "." + module); - } - if (!strict && reference == null) { - reference = getProject().getReference(prefix); - } - return reference; - } - - protected ResolveReport getResolvedReport(String org, String module, String resolveId) { - ResolveReport result = null; - - if (resolveId == null) { - result = (ResolveReport) getReference("ivy.resolved.report", org, module, false); - } else { - result = (ResolveReport) getReference("ivy.resolved.report." + resolveId, null, null, - false); - } - - return result; - } - - protected String[] splitConfs(String conf) { - if (conf == null) { - return null; - } - String[] confs = conf.split(","); - for (int i = 0; i < confs.length; i++) { - confs[i] = confs[i].trim(); - } - return confs; - } - - protected String mergeConfs(String[] conf) { - return StringUtils.join(conf, ", "); - } - - private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); - - protected Date getPubDate(String date, Date def) { - if (date != null) { - if ("now".equalsIgnoreCase(date)) { - return new Date(); - } - try { - return DATE_FORMAT.parse(date); - } catch (Exception ex) { - throw new BuildException( - "publication date provided in bad format. should be yyyyMMddHHmmss and not " - + date); - } - } else { - return def; - } - } - - protected String getProperty(String value, IvySettings ivy, String name) { - if (value == null) { - return getProperty(ivy, name); - } else { - value = ivy.substitute(value); - Message.debug("parameter found as attribute value: " + name + "=" + value); - return value; - } - } - - protected String getProperty(String value, IvySettings ivy, String name, String resolveId) { - if (resolveId == null) { - return getProperty(value, ivy, name); - } else { - return getProperty(value, ivy, name + "." + resolveId); - } - } - - protected String getProperty(IvySettings ivy, String name, String resolveId) { - if (resolveId == null) { - return getProperty(ivy, name); - } else { - return getProperty(ivy, name + "." + resolveId); - } - } - - protected String getProperty(IvySettings ivy, String name) { - String val = ivy.getVariable(name); - if (val == null) { - val = ivy.substitute(getProject().getProperty(name)); - if (val != null) { - Message.debug("parameter found as ant project property: " + name + "=" + val); - } else { - Message.debug("parameter not found: " + name); - } - } else { - val = ivy.substitute(val); - Message.debug("parameter found as ivy variable: " + name + "=" + val); - } - return val; - } - - /** - * Called when task starts its execution. - */ - protected void prepareTask() { - // push current project on the stack in context - IvyContext.getContext().push(ANT_PROJECT_CONTEXT_KEY, getProject()); - } - - /** - * Called when task is about to finish Should clean up all state related information (stacks for - * example) - */ - protected void finalizeTask() { - if (!IvyContext.getContext().pop(ANT_PROJECT_CONTEXT_KEY, getProject())) { - Message.error("ANT project poped from stack not equals current !. Ignoring"); - } - } - - /** - * Ant task execute. Calls prepareTask, doExecute, finalzeTask - */ - public final void execute() throws BuildException { - try { - prepareTask(); - doExecute(); - } finally { - finalizeTask(); - } - } - - /** - * The real logic of task execution after project has been set in the context. MUST be - * implemented by subclasses - * - * @throws BuildException - */ - public abstract void doExecute() throws BuildException; - -} +/* + * 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.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.StringUtils; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Reference; + +/** + * Base class for all ivy ant tasks, deal particularly with ivy instance storage in ant project. + */ +public abstract class IvyTask extends Task { + public static final String ANT_PROJECT_CONTEXT_KEY = "ant-project"; + + private Boolean _validate = null; + + private Reference _antIvyEngineRef = null; + + protected boolean doValidate(IvySettings ivy) { + if (_validate != null) { + return _validate.booleanValue(); + } + return ivy.doValidate(); + } + + public boolean isValidate() { + return _validate == null ? true : _validate.booleanValue(); + } + + public void setValidate(boolean validate) { + _validate = Boolean.valueOf(validate); + } + + public void setSettingsRef(Reference ref) { + _antIvyEngineRef = ref; + } + + public Reference getSettingsRef() { + return _antIvyEngineRef; + } + + protected IvySettings getSettings() { + return getIvyInstance().getSettings(); + } + + protected Ivy getIvyInstance() { + ensureMessageInitialised(); + Object antIvyEngine; + if (_antIvyEngineRef != null) { + antIvyEngine = _antIvyEngineRef.getReferencedObject(); + if (!antIvyEngine.getClass().getName().equals(IvyAntSettings.class.getName())) { + throw new BuildException(_antIvyEngineRef.getRefId() + + " doesn't reference an ivy:settings", getLocation()); + } + if (!(antIvyEngine instanceof IvyAntSettings)) { + throw new BuildException( + _antIvyEngineRef.getRefId() + + " has been defined in a different classloader. Please use the same loader when defining your task, or redeclare your ivy:settings in this classloader", + getLocation()); + } + } else { + antIvyEngine = IvyAntSettings.getDefaultInstance(getProject()); + } + return ((IvyAntSettings) antIvyEngine).getConfiguredIvyInstance(); + } + + /** + * Every task MUST call ensureMessageInitialised when the execution method starts (at least + * before doing any log in order to set the correct task in the log. + */ + protected void ensureMessageInitialised() { + if (!Message.isInitialised()) { + Message.init(new AntMessageImpl(this)); + } + } + + protected void setResolved(ResolveReport report, boolean keep) { + ModuleDescriptor md = report.getModuleDescriptor(); + String[] confs = report.getConfigurations(); + if (keep) { + getProject().addReference("ivy.resolved.report", report); + getProject().addReference("ivy.resolved.configurations.ref", confs); + getProject().addReference("ivy.resolved.descriptor", md); + } + String suffix = md.getModuleRevisionId().getModuleId().getOrganisation() + "." + + md.getModuleRevisionId().getModuleId().getName(); + getProject().addReference("ivy.resolved.report." + suffix, report); + getProject().addReference("ivy.resolved.descriptor." + suffix, md); + getProject().addReference("ivy.resolved.configurations.ref." + suffix, confs); + } + + protected void setResolved(ResolveReport report, String resolveId, boolean keep) { + setResolved(report, keep); + if (resolveId != null) { + ModuleDescriptor md = report.getModuleDescriptor(); + String[] confs = report.getConfigurations(); + getProject().addReference("ivy.resolved.report." + resolveId, report); + getProject().addReference("ivy.resolved.descriptor." + resolveId, md); + getProject().addReference("ivy.resolved.configurations.ref." + resolveId, confs); + } + } + + protected String[] getResolvedConfigurations(String org, String module, boolean strict) { + return (String[]) getReference("ivy.resolved.configurations.ref", org, module, strict); + } + + protected Object getResolvedDescriptor(String resolveId) { + return getResolvedDescriptor(resolveId, true); + } + + protected Object getResolvedDescriptor(String resolveId, boolean strict) { + Object result = getProject().getReference("ivy.resolved.descriptor." + resolveId); + if (strict && (result == null)) { + throw new BuildException("ModuleDescriptor for resolve with id '" + resolveId + + "' not found."); + } + return result; + } + + protected Object getResolvedDescriptor(String org, String module) { + return getResolvedDescriptor(org, module, false); + } + + protected Object getResolvedDescriptor(String org, String module, boolean strict) { + return getReference("ivy.resolved.descriptor", org, module, strict); + } + + private Object getReference(String prefix, String org, String module, boolean strict) { + Object reference = null; + if (org != null && module != null) { + reference = getProject().getReference(prefix + "." + org + "." + module); + } + if (!strict && reference == null) { + reference = getProject().getReference(prefix); + } + return reference; + } + + protected ResolveReport getResolvedReport(String org, String module, String resolveId) { + ResolveReport result = null; + + if (resolveId == null) { + result = (ResolveReport) getReference("ivy.resolved.report", org, module, false); + } else { + result = (ResolveReport) getReference("ivy.resolved.report." + resolveId, null, null, + false); + } + + return result; + } + + protected String[] splitConfs(String conf) { + if (conf == null) { + return null; + } + String[] confs = conf.split(","); + for (int i = 0; i < confs.length; i++) { + confs[i] = confs[i].trim(); + } + return confs; + } + + protected String mergeConfs(String[] conf) { + return StringUtils.join(conf, ", "); + } + + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); + + protected Date getPubDate(String date, Date def) { + if (date != null) { + if ("now".equalsIgnoreCase(date)) { + return new Date(); + } + try { + return DATE_FORMAT.parse(date); + } catch (Exception ex) { + throw new BuildException( + "publication date provided in bad format. should be yyyyMMddHHmmss and not " + + date); + } + } else { + return def; + } + } + + protected String getProperty(String value, IvySettings ivy, String name) { + if (value == null) { + return getProperty(ivy, name); + } else { + value = ivy.substitute(value); + Message.debug("parameter found as attribute value: " + name + "=" + value); + return value; + } + } + + protected String getProperty(String value, IvySettings ivy, String name, String resolveId) { + if (resolveId == null) { + return getProperty(value, ivy, name); + } else { + return getProperty(value, ivy, name + "." + resolveId); + } + } + + protected String getProperty(IvySettings ivy, String name, String resolveId) { + if (resolveId == null) { + return getProperty(ivy, name); + } else { + return getProperty(ivy, name + "." + resolveId); + } + } + + protected String getProperty(IvySettings ivy, String name) { + String val = ivy.getVariable(name); + if (val == null) { + val = ivy.substitute(getProject().getProperty(name)); + if (val != null) { + Message.debug("parameter found as ant project property: " + name + "=" + val); + } else { + Message.debug("parameter not found: " + name); + } + } else { + val = ivy.substitute(val); + Message.debug("parameter found as ivy variable: " + name + "=" + val); + } + return val; + } + + /** + * Called when task starts its execution. + */ + protected void prepareTask() { + // push current project on the stack in context + IvyContext.getContext().push(ANT_PROJECT_CONTEXT_KEY, getProject()); + } + + /** + * Called when task is about to finish Should clean up all state related information (stacks for + * example) + */ + protected void finalizeTask() { + if (!IvyContext.getContext().pop(ANT_PROJECT_CONTEXT_KEY, getProject())) { + Message.error("ANT project poped from stack not equals current !. Ignoring"); + } + } + + /** + * Ant task execute. Calls prepareTask, doExecute, finalzeTask + */ + public final void execute() throws BuildException { + try { + prepareTask(); + doExecute(); + } finally { + finalizeTask(); + } + } + + /** + * The real logic of task execution after project has been set in the context. MUST be + * implemented by subclasses + * + * @throws BuildException + */ + public abstract void doExecute() throws BuildException; + +} diff --git a/src/java/org/apache/ivy/ant/IvyVar.java b/src/java/org/apache/ivy/ant/IvyVar.java index 9bd6d4f8..79534074 100644 --- a/src/java/org/apache/ivy/ant/IvyVar.java +++ b/src/java/org/apache/ivy/ant/IvyVar.java @@ -1,131 +1,131 @@ -/* - * 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.InputStream; -import java.net.URL; -import java.util.Iterator; -import java.util.Properties; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.tools.ant.BuildException; - -/** - * This task let user set ivy variables from ant. - */ -public class IvyVar extends IvyTask { - private String _name; - - private String _value; - - private File _file; - - private String _url; - - private String _prefix; - - public File getFile() { - return _file; - } - - public void setFile(File file) { - _file = file; - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public String getPrefix() { - return _prefix; - } - - public void setPrefix(String prefix) { - _prefix = prefix; - } - - public String getUrl() { - return _url; - } - - public void setUrl(String url) { - _url = url; - } - - public String getValue() { - return _value; - } - - public void setValue(String value) { - _value = value; - } - - public void doExecute() throws BuildException { - Ivy ivy = getIvyInstance(); - IvySettings settings = ivy.getSettings(); - if (getName() != null) { - settings.setVariable(getVarName(getName()), getValue()); - } else { - Properties props = new Properties(); - InputStream is = null; - try { - if (getFile() != null) { - is = new FileInputStream(getFile()); - } else if (getUrl() != null) { - is = new URL(getUrl()).openStream(); - } else { - throw new BuildException("specify either name or file or url to ivy var task"); - } - props.load(is); - } catch (Exception ex) { - throw new BuildException("impossible to load variables from file: " + ex, ex); - } finally { - if (is != null) { - try { - is.close(); - } catch (Exception e) { - } - } - } - for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { - String name = (String) iter.next(); - String value = (String) props.get(name); - settings.setVariable(getVarName(name), value); - } - } - } - - private String getVarName(String name) { - String prefix = getPrefix(); - if (prefix != null) { - if (prefix.endsWith(".")) { - return prefix + name; - } else { - return prefix + "." + name; - } - } - return name; - } -} +/* + * 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.InputStream; +import java.net.URL; +import java.util.Iterator; +import java.util.Properties; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.tools.ant.BuildException; + +/** + * This task let user set ivy variables from ant. + */ +public class IvyVar extends IvyTask { + private String _name; + + private String _value; + + private File _file; + + private String _url; + + private String _prefix; + + public File getFile() { + return _file; + } + + public void setFile(File file) { + _file = file; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public String getPrefix() { + return _prefix; + } + + public void setPrefix(String prefix) { + _prefix = prefix; + } + + public String getUrl() { + return _url; + } + + public void setUrl(String url) { + _url = url; + } + + public String getValue() { + return _value; + } + + public void setValue(String value) { + _value = value; + } + + public void doExecute() throws BuildException { + Ivy ivy = getIvyInstance(); + IvySettings settings = ivy.getSettings(); + if (getName() != null) { + settings.setVariable(getVarName(getName()), getValue()); + } else { + Properties props = new Properties(); + InputStream is = null; + try { + if (getFile() != null) { + is = new FileInputStream(getFile()); + } else if (getUrl() != null) { + is = new URL(getUrl()).openStream(); + } else { + throw new BuildException("specify either name or file or url to ivy var task"); + } + props.load(is); + } catch (Exception ex) { + throw new BuildException("impossible to load variables from file: " + ex, ex); + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception e) { + } + } + } + for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { + String name = (String) iter.next(); + String value = (String) props.get(name); + settings.setVariable(getVarName(name), value); + } + } + } + + private String getVarName(String name) { + String prefix = getPrefix(); + if (prefix != null) { + if (prefix.endsWith(".")) { + return prefix + name; + } else { + return prefix + "." + name; + } + } + return name; + } +} diff --git a/src/java/org/apache/ivy/ant/PackageMapping.java b/src/java/org/apache/ivy/ant/PackageMapping.java index 4414ad2c..7812395b 100644 --- a/src/java/org/apache/ivy/ant/PackageMapping.java +++ b/src/java/org/apache/ivy/ant/PackageMapping.java @@ -1,69 +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.ant; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -/** - * Describes a mapping between a package name and an org name revision uple - */ -public class PackageMapping { - private String _package; - - private String _organisation; - - private String _module; - - private String _revision; - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrganisation() { - return _organisation; - } - - public void setOrganisation(String organisation) { - _organisation = organisation; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - _revision = revision; - } - - public String getPackage() { - return _package; - } - - public void setPackage(String package1) { - _package = package1; - } - - public ModuleRevisionId getModuleRevisionId() { - return ModuleRevisionId.newInstance(_organisation, _module, _revision); - } -} +/* + * 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 org.apache.ivy.core.module.id.ModuleRevisionId; + +/** + * Describes a mapping between a package name and an org name revision uple + */ +public class PackageMapping { + private String _package; + + private String _organisation; + + private String _module; + + private String _revision; + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrganisation() { + return _organisation; + } + + public void setOrganisation(String organisation) { + _organisation = organisation; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + _revision = revision; + } + + public String getPackage() { + return _package; + } + + public void setPackage(String package1) { + _package = package1; + } + + public ModuleRevisionId getModuleRevisionId() { + return ModuleRevisionId.newInstance(_organisation, _module, _revision); + } +} diff --git a/src/java/org/apache/ivy/ant/antlib.xml b/src/java/org/apache/ivy/ant/antlib.xml index 4fc9c4c1..d3ba195d 100644 --- a/src/java/org/apache/ivy/ant/antlib.xml +++ b/src/java/org/apache/ivy/ant/antlib.xml @@ -1,44 +1,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/org/apache/ivy/core/IvyContext.java b/src/java/org/apache/ivy/core/IvyContext.java index 5412b484..e354c7f0 100644 --- a/src/java/org/apache/ivy/core/IvyContext.java +++ b/src/java/org/apache/ivy/core/IvyContext.java @@ -1,296 +1,296 @@ -/* - * 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.core; - -import java.io.File; -import java.lang.ref.WeakReference; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Stack; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.circular.CircularDependencyStrategy; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.MessageImpl; - -/** - * This class represents an execution context of an Ivy action. It contains several getters to - * retrieve information, like the used Ivy instance, the cache location... - * - * @see IvyThread - */ -public class IvyContext { - - private static ThreadLocal current = new ThreadLocal(); - - private Ivy defaultIvy; - - private WeakReference ivy = new WeakReference(null); - - private File cache; - - private MessageImpl messageImpl; - - private Stack resolver = new Stack(); // Stack(DependencyResolver) - - private Map contextMap = new HashMap(); - - private Thread operatingThread; - - public static IvyContext getContext() { - IvyContext cur = (IvyContext) current.get(); - if (cur == null) { - cur = new IvyContext(); - current.set(cur); - } - return cur; - } - - /** - * Changes the context associated with this thread. This is especially useful when launching a - * new thread, to associate it with the same context as the initial one. - * - * @param context - * the new context to use in this thread. - */ - public static void setContext(IvyContext context) { - current.set(context); - } - - /** - * Returns the current ivy instance. When calling any public ivy method on an ivy instance, a - * reference to this instance is put in this context, and thus accessible using this method, - * until no code reference this instance and the garbage collector collects it. Then, or if no - * ivy method has been called, a default ivy instance is returned by this method, so that it - * never returns null. - * - * @return the current ivy instance - */ - public Ivy getIvy() { - Ivy ivy = (Ivy) this.ivy.get(); - return ivy == null ? getDefaultIvy() : ivy; - } - - private Ivy getDefaultIvy() { - if (defaultIvy == null) { - defaultIvy = Ivy.newInstance(); - try { - defaultIvy.configureDefault(); - } catch (Exception e) { - } - } - return defaultIvy; - } - - public void setIvy(Ivy ivy) { - this.ivy = new WeakReference(ivy); - operatingThread = Thread.currentThread(); - } - - public File getCache() { - return cache == null ? getSettings().getDefaultCache() : cache; - } - - public void setCache(File cache) { - this.cache = cache; - } - - public IvySettings getSettings() { - return getIvy().getSettings(); - } - - public CircularDependencyStrategy getCircularDependencyStrategy() { - return getSettings().getCircularDependencyStrategy(); - } - - public Object get(String key) { - WeakReference ref = (WeakReference) contextMap.get(key); - return ref == null ? null : ref.get(); - } - - public void set(String key, Object value) { - contextMap.put(key, new WeakReference(value)); - } - - /** - * Reads the first object from the list saved under given key in the context. If value under key - * represents non List object then a RuntimeException is thrown. - * - * @param key - * context key for the string - * @return top object from the list (index 0) or null if no key or list empty - */ - public Object peek(String key) { - synchronized (contextMap) { - Object o = contextMap.get(key); - if (o == null) - return null; - if (o instanceof List) { - if (((List) o).size() == 0) - return null; - Object ret = ((List) o).get(0); - return ret; - } else { - throw new RuntimeException("Cannot top from non List object " + o); - } - } - } - - /** - * Removes and returns first object from the list saved under given key in the context. If value - * under key represents non List object then a RuntimeException is thrown. - * - * @param key - * context key for the string - * @return top object from the list (index 0) or null if no key or list empty - */ - public Object pop(String key) { - synchronized (contextMap) { - Object o = contextMap.get(key); - if (o == null) - return null; - if (o instanceof List) { - if (((List) o).size() == 0) - return null; - Object ret = ((List) o).remove(0); - return ret; - } else { - throw new RuntimeException("Cannot pop from non List object " + o); - } - } - } - - /** - * Removes and returns first object from the list saved under given key in the context but only - * if it equals the given expectedValue - if not a false value is returned. If value under key - * represents non List object then a RuntimeException is thrown. - * - * @param key - * context key for the string - * @return true if the r - */ - public boolean pop(String key, Object expectedValue) { - synchronized (contextMap) { - Object o = contextMap.get(key); - if (o == null) - return false; - if (o instanceof List) { - if (((List) o).size() == 0) - return false; - Object top = ((List) o).get(0); - if (!top.equals(expectedValue)) - return false; - ((List) o).remove(0); - return true; - } else { - throw new RuntimeException("Cannot pop from non List object " + o); - } - } - } - - /** - * Puts a new object at the start of the list saved under given key in the context. If value - * under key represents non List object then a RuntimeException is thrown. If no list exists - * under given key a new LinkedList is created. This is kept without WeakReference in opposite - * to the put() results. - * - * @param key - * key context key for the string - * @param value - * value to be saved under the key - */ - public void push(String key, Object value) { - synchronized (contextMap) { - if (!contextMap.containsKey(key)) - contextMap.put(key, new LinkedList()); - Object o = contextMap.get(key); - if (o instanceof List) { - ((List) o).add(0, value); - } else { - throw new RuntimeException("Cannot push to non List object " + o); - } - } - } - - public Thread getOperatingThread() { - return operatingThread; - } - - /* - * NB : The messageImpl is only used by Message. It should be better to place it there. - * Alternatively, the Message itself could be placed here, bu this is has a major impact because - * Message is used at a lot of place. - */ - public MessageImpl getMessageImpl() { - return messageImpl; - } - - public void setMessageImpl(MessageImpl impl) { - messageImpl = impl; - } - - public EventManager getEventManager() { - return getIvy().getEventManager(); - } - - public CacheManager getCacheManager() { - return CacheManager.getInstance(getSettings(), getCache()); - } - - public void checkInterrupted() { - getIvy().checkInterrupted(); - } - - public DependencyResolver getResolver() { - return (DependencyResolver) resolver.peek(); - } - - public void pushResolver(DependencyResolver resolver) { - this.resolver.push(resolver); - } - - public void popResolver() { - resolver.pop(); - } - - // should be better to use context to store this kind of information, but not yet ready to do - // so... - // private WeakReference _root = new WeakReference(null); - // private String _rootModuleConf = null; - // public IvyNode getRoot() { - // return (IvyNode) _root.get(); - // } - // - // public void setRoot(IvyNode root) { - // _root = new WeakReference(root); - // } - // - // public String getRootModuleConf() { - // return _rootModuleConf; - // } - // - // public void setRootModuleConf(String rootModuleConf) { - // _rootModuleConf = rootModuleConf; - // } - -} +/* + * 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.core; + +import java.io.File; +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.circular.CircularDependencyStrategy; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.MessageImpl; + +/** + * This class represents an execution context of an Ivy action. It contains several getters to + * retrieve information, like the used Ivy instance, the cache location... + * + * @see IvyThread + */ +public class IvyContext { + + private static ThreadLocal current = new ThreadLocal(); + + private Ivy defaultIvy; + + private WeakReference ivy = new WeakReference(null); + + private File cache; + + private MessageImpl messageImpl; + + private Stack resolver = new Stack(); // Stack(DependencyResolver) + + private Map contextMap = new HashMap(); + + private Thread operatingThread; + + public static IvyContext getContext() { + IvyContext cur = (IvyContext) current.get(); + if (cur == null) { + cur = new IvyContext(); + current.set(cur); + } + return cur; + } + + /** + * Changes the context associated with this thread. This is especially useful when launching a + * new thread, to associate it with the same context as the initial one. + * + * @param context + * the new context to use in this thread. + */ + public static void setContext(IvyContext context) { + current.set(context); + } + + /** + * Returns the current ivy instance. When calling any public ivy method on an ivy instance, a + * reference to this instance is put in this context, and thus accessible using this method, + * until no code reference this instance and the garbage collector collects it. Then, or if no + * ivy method has been called, a default ivy instance is returned by this method, so that it + * never returns null. + * + * @return the current ivy instance + */ + public Ivy getIvy() { + Ivy ivy = (Ivy) this.ivy.get(); + return ivy == null ? getDefaultIvy() : ivy; + } + + private Ivy getDefaultIvy() { + if (defaultIvy == null) { + defaultIvy = Ivy.newInstance(); + try { + defaultIvy.configureDefault(); + } catch (Exception e) { + } + } + return defaultIvy; + } + + public void setIvy(Ivy ivy) { + this.ivy = new WeakReference(ivy); + operatingThread = Thread.currentThread(); + } + + public File getCache() { + return cache == null ? getSettings().getDefaultCache() : cache; + } + + public void setCache(File cache) { + this.cache = cache; + } + + public IvySettings getSettings() { + return getIvy().getSettings(); + } + + public CircularDependencyStrategy getCircularDependencyStrategy() { + return getSettings().getCircularDependencyStrategy(); + } + + public Object get(String key) { + WeakReference ref = (WeakReference) contextMap.get(key); + return ref == null ? null : ref.get(); + } + + public void set(String key, Object value) { + contextMap.put(key, new WeakReference(value)); + } + + /** + * Reads the first object from the list saved under given key in the context. If value under key + * represents non List object then a RuntimeException is thrown. + * + * @param key + * context key for the string + * @return top object from the list (index 0) or null if no key or list empty + */ + public Object peek(String key) { + synchronized (contextMap) { + Object o = contextMap.get(key); + if (o == null) + return null; + if (o instanceof List) { + if (((List) o).size() == 0) + return null; + Object ret = ((List) o).get(0); + return ret; + } else { + throw new RuntimeException("Cannot top from non List object " + o); + } + } + } + + /** + * Removes and returns first object from the list saved under given key in the context. If value + * under key represents non List object then a RuntimeException is thrown. + * + * @param key + * context key for the string + * @return top object from the list (index 0) or null if no key or list empty + */ + public Object pop(String key) { + synchronized (contextMap) { + Object o = contextMap.get(key); + if (o == null) + return null; + if (o instanceof List) { + if (((List) o).size() == 0) + return null; + Object ret = ((List) o).remove(0); + return ret; + } else { + throw new RuntimeException("Cannot pop from non List object " + o); + } + } + } + + /** + * Removes and returns first object from the list saved under given key in the context but only + * if it equals the given expectedValue - if not a false value is returned. If value under key + * represents non List object then a RuntimeException is thrown. + * + * @param key + * context key for the string + * @return true if the r + */ + public boolean pop(String key, Object expectedValue) { + synchronized (contextMap) { + Object o = contextMap.get(key); + if (o == null) + return false; + if (o instanceof List) { + if (((List) o).size() == 0) + return false; + Object top = ((List) o).get(0); + if (!top.equals(expectedValue)) + return false; + ((List) o).remove(0); + return true; + } else { + throw new RuntimeException("Cannot pop from non List object " + o); + } + } + } + + /** + * Puts a new object at the start of the list saved under given key in the context. If value + * under key represents non List object then a RuntimeException is thrown. If no list exists + * under given key a new LinkedList is created. This is kept without WeakReference in opposite + * to the put() results. + * + * @param key + * key context key for the string + * @param value + * value to be saved under the key + */ + public void push(String key, Object value) { + synchronized (contextMap) { + if (!contextMap.containsKey(key)) + contextMap.put(key, new LinkedList()); + Object o = contextMap.get(key); + if (o instanceof List) { + ((List) o).add(0, value); + } else { + throw new RuntimeException("Cannot push to non List object " + o); + } + } + } + + public Thread getOperatingThread() { + return operatingThread; + } + + /* + * NB : The messageImpl is only used by Message. It should be better to place it there. + * Alternatively, the Message itself could be placed here, bu this is has a major impact because + * Message is used at a lot of place. + */ + public MessageImpl getMessageImpl() { + return messageImpl; + } + + public void setMessageImpl(MessageImpl impl) { + messageImpl = impl; + } + + public EventManager getEventManager() { + return getIvy().getEventManager(); + } + + public CacheManager getCacheManager() { + return CacheManager.getInstance(getSettings(), getCache()); + } + + public void checkInterrupted() { + getIvy().checkInterrupted(); + } + + public DependencyResolver getResolver() { + return (DependencyResolver) resolver.peek(); + } + + public void pushResolver(DependencyResolver resolver) { + this.resolver.push(resolver); + } + + public void popResolver() { + resolver.pop(); + } + + // should be better to use context to store this kind of information, but not yet ready to do + // so... + // private WeakReference _root = new WeakReference(null); + // private String _rootModuleConf = null; + // public IvyNode getRoot() { + // return (IvyNode) _root.get(); + // } + // + // public void setRoot(IvyNode root) { + // _root = new WeakReference(root); + // } + // + // public String getRootModuleConf() { + // return _rootModuleConf; + // } + // + // public void setRootModuleConf(String rootModuleConf) { + // _rootModuleConf = rootModuleConf; + // } + +} diff --git a/src/java/org/apache/ivy/core/IvyPatternHelper.java b/src/java/org/apache/ivy/core/IvyPatternHelper.java index c6fe60fb..c5784e73 100644 --- a/src/java/org/apache/ivy/core/IvyPatternHelper.java +++ b/src/java/org/apache/ivy/core/IvyPatternHelper.java @@ -1,455 +1,455 @@ -/* - * 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.core; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.core.cache.ArtifactOrigin; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.util.Message; - -/** - */ -public class IvyPatternHelper { - public static final String CONF_KEY = "conf"; - - public static final String TYPE_KEY = "type"; - - public static final String EXT_KEY = "ext"; - - public static final String ARTIFACT_KEY = "artifact"; - - public static final String BRANCH_KEY = "branch"; - - public static final String REVISION_KEY = "revision"; - - public static final String MODULE_KEY = "module"; - - public static final String ORGANISATION_KEY = "organisation"; - - public static final String ORGANISATION_KEY2 = "organization"; - - public static final String ORIGINAL_ARTIFACTNAME_KEY = "originalname"; - - private static final Pattern PARAM_PATTERN = Pattern.compile("\\@\\{(.*?)\\}"); - - private static final Pattern VAR_PATTERN = Pattern.compile("\\$\\{(.*?)\\}"); - - public static String substitute(String pattern, ModuleRevisionId moduleRevision) { - return substitute(pattern, moduleRevision.getOrganisation(), moduleRevision.getName(), - moduleRevision.getRevision(), "ivy", "ivy", "xml", null, moduleRevision.getAttributes()); - } - - public static String substitute(String pattern, ModuleRevisionId moduleRevision, - String artifact, String type, String ext) { - return substitute(pattern, moduleRevision, new DefaultArtifact(moduleRevision, null, - artifact, type, ext), null); - } - - public static String substitute(String pattern, Artifact artifact) { - return substitute(pattern, artifact, (String) null); - } - - public static String substitute(String pattern, Artifact artifact, ArtifactOrigin origin) { - return substitute(pattern, artifact.getModuleRevisionId(), artifact, null, origin); - } - - public static String substitute(String pattern, Artifact artifact, String conf) { - return substitute(pattern, artifact.getModuleRevisionId(), artifact, conf); - } - - public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact) { - return substitute(pattern, mrid, artifact, null); - } - - public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact, - String conf) { - return substitute(pattern, mrid, artifact, conf, null); - } - - public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact, - String conf, ArtifactOrigin origin) { - Map attributes = new HashMap(); - attributes.putAll(mrid.getAttributes()); - attributes.putAll(artifact.getAttributes()); - return substitute(pattern, mrid.getOrganisation(), mrid.getName(), mrid.getBranch(), mrid - .getRevision(), artifact.getName(), artifact.getType(), artifact.getExt(), conf, - origin, attributes); - } - - public static String substitute(String pattern, String org, String module, String revision, - String artifact, String type, String ext) { - return substitute(pattern, org, module, revision, artifact, type, ext, null); - } - - public static String substitute(String pattern, String org, String module, String revision, - String artifact, String type, String ext, String conf) { - return substitute(pattern, org, module, revision, artifact, type, ext, conf, null); - } - - public static String substitute(String pattern, String org, String module, String revision, - String artifact, String type, String ext, String conf, Map extraAttributes) { - return substitute(pattern, org, module, revision, artifact, type, ext, conf, null, - extraAttributes); - } - - public static String substitute(String pattern, String org, String module, String revision, - String artifact, String type, String ext, String conf, ArtifactOrigin origin, - Map extraAttributes) { - return substitute(pattern, org, module, null, revision, artifact, type, ext, conf, origin, - extraAttributes); - } - - public static String substitute(String pattern, String org, String module, String branch, - String revision, String artifact, String type, String ext, String conf, - ArtifactOrigin origin, Map extraAttributes) { - Map tokens = new HashMap(extraAttributes == null ? Collections.EMPTY_MAP : extraAttributes); - tokens.put(ORGANISATION_KEY, org == null ? "" : org); - tokens.put(ORGANISATION_KEY2, org == null ? "" : org); - tokens.put(MODULE_KEY, module == null ? "" : module); - tokens.put(BRANCH_KEY, branch == null ? "" : branch); - tokens.put(REVISION_KEY, revision == null ? "" : revision); - tokens.put(ARTIFACT_KEY, artifact == null ? module : artifact); - tokens.put(TYPE_KEY, type == null ? "jar" : type); - tokens.put(EXT_KEY, ext == null ? "jar" : ext); - tokens.put(CONF_KEY, conf == null ? "default" : conf); - tokens.put(ORIGINAL_ARTIFACTNAME_KEY, origin == null ? new OriginalArtifactNameValue(org, - module, branch, revision, artifact, type, ext) : new OriginalArtifactNameValue( - origin)); - return substituteTokens(pattern, tokens); - } - - public static String substitute(String pattern, Map variables, Map tokens) { - return substituteTokens(substituteVariables(pattern, variables), tokens); - } - - public static String substituteVariables(String pattern, Map variables) { - return substituteVariables(pattern, variables, new Stack()); - } - - private static String substituteVariables(String pattern, Map variables, Stack substituting) { - // if you supply null, null is what you get - if (pattern == null) { - return null; - } - - Matcher m = VAR_PATTERN.matcher(pattern); - - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String var = m.group(1); - String val = (String) variables.get(var); - if (val != null) { - int index; - if ((index = substituting.indexOf(var)) != -1) { - List cycle = new ArrayList(substituting.subList(index, substituting.size())); - cycle.add(var); - throw new IllegalArgumentException("cyclic variable definition: cycle = " - + cycle); - } - substituting.push(var); - val = substituteVariables(val, variables, substituting); - substituting.pop(); - } else { - val = m.group(); - } - m - .appendReplacement(sb, val.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\$", - "\\\\\\$")); - } - m.appendTail(sb); - - return sb.toString(); - } - - public static String substituteTokens(String pattern, Map tokens) { - StringBuffer buffer = new StringBuffer(); - - char[] chars = pattern.toCharArray(); - - StringBuffer optionalPart = null; - StringBuffer tokenBuffer = null; - boolean insideOptionalPart = false; - boolean insideToken = false; - boolean tokenHadValue = false; - - for (int i = 0; i < chars.length; i++) { - switch (chars[i]) { - case '(': - if (insideOptionalPart) { - throw new IllegalArgumentException( - "invalid start of optional part at position " + i + " in pattern " - + pattern); - } - - optionalPart = new StringBuffer(); - insideOptionalPart = true; - tokenHadValue = false; - break; - - case ')': - if (!insideOptionalPart || insideToken) { - throw new IllegalArgumentException( - "invalid end of optional part at position " + i + " in pattern " - + pattern); - } - - if (tokenHadValue) { - buffer.append(optionalPart.toString()); - } - - insideOptionalPart = false; - break; - - case '[': - if (insideToken) { - throw new IllegalArgumentException("invalid start of token at position " - + i + " in pattern " + pattern); - } - - tokenBuffer = new StringBuffer(); - insideToken = true; - break; - - case ']': - if (!insideToken) { - throw new IllegalArgumentException("invalid end of token at position " + i - + " in pattern " + pattern); - } - - String token = tokenBuffer.toString(); - Object tokenValue = tokens.get(token); - String value = (tokenValue == null) ? null : tokenValue.toString(); - - if (insideOptionalPart) { - tokenHadValue = (value != null) && (value.length() > 0); - optionalPart.append(value); - } else { - if (value == null) { // the token wasn't set, it's kept as is - value = "[" + token + "]"; - } - buffer.append(value); - } - - insideToken = false; - break; - - default: - if (insideToken) { - tokenBuffer.append(chars[i]); - } else if (insideOptionalPart) { - optionalPart.append(chars[i]); - } else { - buffer.append(chars[i]); - } - - break; - } - } - - if (insideToken) { - throw new IllegalArgumentException("last token hasn't been closed in pattern " - + pattern); - } - - if (insideOptionalPart) { - throw new IllegalArgumentException("optional part hasn't been closed in pattern " - + pattern); - } - - return buffer.toString(); - } - - public static String substituteVariable(String pattern, String variable, String value) { - StringBuffer buf = new StringBuffer(pattern); - substituteVariable(buf, variable, value); - return buf.toString(); - } - - public static void substituteVariable(StringBuffer buf, String variable, String value) { - String from = "${" + variable + "}"; - int fromLength = from.length(); - for (int index = buf.indexOf(from); index != -1; index = buf.indexOf(from, index)) { - buf.replace(index, index + fromLength, value); - } - } - - public static String substituteToken(String pattern, String token, String value) { - StringBuffer buf = new StringBuffer(pattern); - substituteToken(buf, token, value); - return buf.toString(); - } - - public static void substituteToken(StringBuffer buf, String token, String value) { - String from = getTokenString(token); - int fromLength = from.length(); - for (int index = buf.indexOf(from); index != -1; index = buf.indexOf(from, index)) { - buf.replace(index, index + fromLength, value); - } - } - - public static String getTokenString(String token) { - return "[" + token + "]"; - } - - public static String substituteParams(String pattern, Map params) { - return substituteParams(pattern, params, new Stack()); - } - - private static String substituteParams(String pattern, Map params, Stack substituting) { - // TODO : refactor this with substituteVariables - // if you supply null, null is what you get - if (pattern == null) { - return null; - } - - Matcher m = PARAM_PATTERN.matcher(pattern); - - StringBuffer sb = new StringBuffer(); - while (m.find()) { - String var = m.group(1); - String val = (String) params.get(var); - if (val != null) { - int index; - if ((index = substituting.indexOf(var)) != -1) { - List cycle = new ArrayList(substituting.subList(index, substituting.size())); - cycle.add(var); - throw new IllegalArgumentException("cyclic param definition: cycle = " + cycle); - } - substituting.push(var); - val = substituteVariables(val, params, substituting); - substituting.pop(); - } else { - val = m.group(); - } - m - .appendReplacement(sb, val.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\@", - "\\\\\\@")); - } - m.appendTail(sb); - - return sb.toString(); - } - - public static void main(String[] args) { - String pattern = "[organisation]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; - System.out.println("pattern= " + pattern); - System.out.println("resolved= " - + substitute(pattern, "apache", "Test", "1.0", "test", "jar", "jar")); - - Map variables = new HashMap(); - variables.put("test", "mytest"); - variables.put("test2", "${test}2"); - pattern = "${test} ${test2} ${nothing}"; - System.out.println("pattern= " + pattern); - System.out.println("resolved= " + substituteVariables(pattern, variables)); - } - - /** - * This class returns the original name of the artifact 'on demand'. This is done to avoid - * having to read the cached datafile containing the original location of the artifact if we - * don't need it. - */ - private static class OriginalArtifactNameValue { - // module properties - private String org; - - private String moduleName; - - private String branch; - - private String revision; - - // artifact properties - private String artifactName; - - private String artifactType; - - private String artifactExt; - - // cached origin; - private ArtifactOrigin origin; - - public OriginalArtifactNameValue(String org, String moduleName, String branch, - String revision, String artifactName, String artifactType, String artifactExt) { - this.org = org; - this.moduleName = moduleName; - this.branch = branch; - this.revision = revision; - this.artifactName = artifactName; - this.artifactType = artifactType; - this.artifactExt = artifactExt; - } - - /** - * @param origin - */ - public OriginalArtifactNameValue(ArtifactOrigin origin) { - this.origin = origin; - } - - // Called by substituteTokens only if the original artifact name is needed - public String toString() { - if (origin == null) { - ModuleRevisionId revId = ModuleRevisionId.newInstance(org, moduleName, branch, - revision); - Artifact artifact = new DefaultArtifact(revId, null, artifactName, artifactType, - artifactExt); - - CacheManager cacheManager = IvyContext.getContext().getCacheManager(); - - origin = cacheManager.getSavedArtifactOrigin(artifact); - - if (origin == null) { - Message.debug("no artifact origin found for " + artifact + " in " - + cacheManager); - return null; - } - } - - // we assume that the original filename is the last part of the original file location - String location = origin.getLocation(); - int lastPathIndex = location.lastIndexOf('/'); - if (lastPathIndex == -1) { - lastPathIndex = location.lastIndexOf('\\'); - } - int lastColonIndex = location.lastIndexOf('.'); - - return location.substring(lastPathIndex + 1, lastColonIndex); - } - } - - public static String getTokenRoot(String pattern) { - int index = pattern.indexOf('['); - if (index == -1) { - return pattern; - } else { - return pattern.substring(0, index); - } - } -} +/* + * 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.core; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.util.Message; + +/** + */ +public class IvyPatternHelper { + public static final String CONF_KEY = "conf"; + + public static final String TYPE_KEY = "type"; + + public static final String EXT_KEY = "ext"; + + public static final String ARTIFACT_KEY = "artifact"; + + public static final String BRANCH_KEY = "branch"; + + public static final String REVISION_KEY = "revision"; + + public static final String MODULE_KEY = "module"; + + public static final String ORGANISATION_KEY = "organisation"; + + public static final String ORGANISATION_KEY2 = "organization"; + + public static final String ORIGINAL_ARTIFACTNAME_KEY = "originalname"; + + private static final Pattern PARAM_PATTERN = Pattern.compile("\\@\\{(.*?)\\}"); + + private static final Pattern VAR_PATTERN = Pattern.compile("\\$\\{(.*?)\\}"); + + public static String substitute(String pattern, ModuleRevisionId moduleRevision) { + return substitute(pattern, moduleRevision.getOrganisation(), moduleRevision.getName(), + moduleRevision.getRevision(), "ivy", "ivy", "xml", null, moduleRevision.getAttributes()); + } + + public static String substitute(String pattern, ModuleRevisionId moduleRevision, + String artifact, String type, String ext) { + return substitute(pattern, moduleRevision, new DefaultArtifact(moduleRevision, null, + artifact, type, ext), null); + } + + public static String substitute(String pattern, Artifact artifact) { + return substitute(pattern, artifact, (String) null); + } + + public static String substitute(String pattern, Artifact artifact, ArtifactOrigin origin) { + return substitute(pattern, artifact.getModuleRevisionId(), artifact, null, origin); + } + + public static String substitute(String pattern, Artifact artifact, String conf) { + return substitute(pattern, artifact.getModuleRevisionId(), artifact, conf); + } + + public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact) { + return substitute(pattern, mrid, artifact, null); + } + + public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact, + String conf) { + return substitute(pattern, mrid, artifact, conf, null); + } + + public static String substitute(String pattern, ModuleRevisionId mrid, Artifact artifact, + String conf, ArtifactOrigin origin) { + Map attributes = new HashMap(); + attributes.putAll(mrid.getAttributes()); + attributes.putAll(artifact.getAttributes()); + return substitute(pattern, mrid.getOrganisation(), mrid.getName(), mrid.getBranch(), mrid + .getRevision(), artifact.getName(), artifact.getType(), artifact.getExt(), conf, + origin, attributes); + } + + public static String substitute(String pattern, String org, String module, String revision, + String artifact, String type, String ext) { + return substitute(pattern, org, module, revision, artifact, type, ext, null); + } + + public static String substitute(String pattern, String org, String module, String revision, + String artifact, String type, String ext, String conf) { + return substitute(pattern, org, module, revision, artifact, type, ext, conf, null); + } + + public static String substitute(String pattern, String org, String module, String revision, + String artifact, String type, String ext, String conf, Map extraAttributes) { + return substitute(pattern, org, module, revision, artifact, type, ext, conf, null, + extraAttributes); + } + + public static String substitute(String pattern, String org, String module, String revision, + String artifact, String type, String ext, String conf, ArtifactOrigin origin, + Map extraAttributes) { + return substitute(pattern, org, module, null, revision, artifact, type, ext, conf, origin, + extraAttributes); + } + + public static String substitute(String pattern, String org, String module, String branch, + String revision, String artifact, String type, String ext, String conf, + ArtifactOrigin origin, Map extraAttributes) { + Map tokens = new HashMap(extraAttributes == null ? Collections.EMPTY_MAP : extraAttributes); + tokens.put(ORGANISATION_KEY, org == null ? "" : org); + tokens.put(ORGANISATION_KEY2, org == null ? "" : org); + tokens.put(MODULE_KEY, module == null ? "" : module); + tokens.put(BRANCH_KEY, branch == null ? "" : branch); + tokens.put(REVISION_KEY, revision == null ? "" : revision); + tokens.put(ARTIFACT_KEY, artifact == null ? module : artifact); + tokens.put(TYPE_KEY, type == null ? "jar" : type); + tokens.put(EXT_KEY, ext == null ? "jar" : ext); + tokens.put(CONF_KEY, conf == null ? "default" : conf); + tokens.put(ORIGINAL_ARTIFACTNAME_KEY, origin == null ? new OriginalArtifactNameValue(org, + module, branch, revision, artifact, type, ext) : new OriginalArtifactNameValue( + origin)); + return substituteTokens(pattern, tokens); + } + + public static String substitute(String pattern, Map variables, Map tokens) { + return substituteTokens(substituteVariables(pattern, variables), tokens); + } + + public static String substituteVariables(String pattern, Map variables) { + return substituteVariables(pattern, variables, new Stack()); + } + + private static String substituteVariables(String pattern, Map variables, Stack substituting) { + // if you supply null, null is what you get + if (pattern == null) { + return null; + } + + Matcher m = VAR_PATTERN.matcher(pattern); + + StringBuffer sb = new StringBuffer(); + while (m.find()) { + String var = m.group(1); + String val = (String) variables.get(var); + if (val != null) { + int index; + if ((index = substituting.indexOf(var)) != -1) { + List cycle = new ArrayList(substituting.subList(index, substituting.size())); + cycle.add(var); + throw new IllegalArgumentException("cyclic variable definition: cycle = " + + cycle); + } + substituting.push(var); + val = substituteVariables(val, variables, substituting); + substituting.pop(); + } else { + val = m.group(); + } + m + .appendReplacement(sb, val.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\$", + "\\\\\\$")); + } + m.appendTail(sb); + + return sb.toString(); + } + + public static String substituteTokens(String pattern, Map tokens) { + StringBuffer buffer = new StringBuffer(); + + char[] chars = pattern.toCharArray(); + + StringBuffer optionalPart = null; + StringBuffer tokenBuffer = null; + boolean insideOptionalPart = false; + boolean insideToken = false; + boolean tokenHadValue = false; + + for (int i = 0; i < chars.length; i++) { + switch (chars[i]) { + case '(': + if (insideOptionalPart) { + throw new IllegalArgumentException( + "invalid start of optional part at position " + i + " in pattern " + + pattern); + } + + optionalPart = new StringBuffer(); + insideOptionalPart = true; + tokenHadValue = false; + break; + + case ')': + if (!insideOptionalPart || insideToken) { + throw new IllegalArgumentException( + "invalid end of optional part at position " + i + " in pattern " + + pattern); + } + + if (tokenHadValue) { + buffer.append(optionalPart.toString()); + } + + insideOptionalPart = false; + break; + + case '[': + if (insideToken) { + throw new IllegalArgumentException("invalid start of token at position " + + i + " in pattern " + pattern); + } + + tokenBuffer = new StringBuffer(); + insideToken = true; + break; + + case ']': + if (!insideToken) { + throw new IllegalArgumentException("invalid end of token at position " + i + + " in pattern " + pattern); + } + + String token = tokenBuffer.toString(); + Object tokenValue = tokens.get(token); + String value = (tokenValue == null) ? null : tokenValue.toString(); + + if (insideOptionalPart) { + tokenHadValue = (value != null) && (value.length() > 0); + optionalPart.append(value); + } else { + if (value == null) { // the token wasn't set, it's kept as is + value = "[" + token + "]"; + } + buffer.append(value); + } + + insideToken = false; + break; + + default: + if (insideToken) { + tokenBuffer.append(chars[i]); + } else if (insideOptionalPart) { + optionalPart.append(chars[i]); + } else { + buffer.append(chars[i]); + } + + break; + } + } + + if (insideToken) { + throw new IllegalArgumentException("last token hasn't been closed in pattern " + + pattern); + } + + if (insideOptionalPart) { + throw new IllegalArgumentException("optional part hasn't been closed in pattern " + + pattern); + } + + return buffer.toString(); + } + + public static String substituteVariable(String pattern, String variable, String value) { + StringBuffer buf = new StringBuffer(pattern); + substituteVariable(buf, variable, value); + return buf.toString(); + } + + public static void substituteVariable(StringBuffer buf, String variable, String value) { + String from = "${" + variable + "}"; + int fromLength = from.length(); + for (int index = buf.indexOf(from); index != -1; index = buf.indexOf(from, index)) { + buf.replace(index, index + fromLength, value); + } + } + + public static String substituteToken(String pattern, String token, String value) { + StringBuffer buf = new StringBuffer(pattern); + substituteToken(buf, token, value); + return buf.toString(); + } + + public static void substituteToken(StringBuffer buf, String token, String value) { + String from = getTokenString(token); + int fromLength = from.length(); + for (int index = buf.indexOf(from); index != -1; index = buf.indexOf(from, index)) { + buf.replace(index, index + fromLength, value); + } + } + + public static String getTokenString(String token) { + return "[" + token + "]"; + } + + public static String substituteParams(String pattern, Map params) { + return substituteParams(pattern, params, new Stack()); + } + + private static String substituteParams(String pattern, Map params, Stack substituting) { + // TODO : refactor this with substituteVariables + // if you supply null, null is what you get + if (pattern == null) { + return null; + } + + Matcher m = PARAM_PATTERN.matcher(pattern); + + StringBuffer sb = new StringBuffer(); + while (m.find()) { + String var = m.group(1); + String val = (String) params.get(var); + if (val != null) { + int index; + if ((index = substituting.indexOf(var)) != -1) { + List cycle = new ArrayList(substituting.subList(index, substituting.size())); + cycle.add(var); + throw new IllegalArgumentException("cyclic param definition: cycle = " + cycle); + } + substituting.push(var); + val = substituteVariables(val, params, substituting); + substituting.pop(); + } else { + val = m.group(); + } + m + .appendReplacement(sb, val.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\@", + "\\\\\\@")); + } + m.appendTail(sb); + + return sb.toString(); + } + + public static void main(String[] args) { + String pattern = "[organisation]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; + System.out.println("pattern= " + pattern); + System.out.println("resolved= " + + substitute(pattern, "apache", "Test", "1.0", "test", "jar", "jar")); + + Map variables = new HashMap(); + variables.put("test", "mytest"); + variables.put("test2", "${test}2"); + pattern = "${test} ${test2} ${nothing}"; + System.out.println("pattern= " + pattern); + System.out.println("resolved= " + substituteVariables(pattern, variables)); + } + + /** + * This class returns the original name of the artifact 'on demand'. This is done to avoid + * having to read the cached datafile containing the original location of the artifact if we + * don't need it. + */ + private static class OriginalArtifactNameValue { + // module properties + private String org; + + private String moduleName; + + private String branch; + + private String revision; + + // artifact properties + private String artifactName; + + private String artifactType; + + private String artifactExt; + + // cached origin; + private ArtifactOrigin origin; + + public OriginalArtifactNameValue(String org, String moduleName, String branch, + String revision, String artifactName, String artifactType, String artifactExt) { + this.org = org; + this.moduleName = moduleName; + this.branch = branch; + this.revision = revision; + this.artifactName = artifactName; + this.artifactType = artifactType; + this.artifactExt = artifactExt; + } + + /** + * @param origin + */ + public OriginalArtifactNameValue(ArtifactOrigin origin) { + this.origin = origin; + } + + // Called by substituteTokens only if the original artifact name is needed + public String toString() { + if (origin == null) { + ModuleRevisionId revId = ModuleRevisionId.newInstance(org, moduleName, branch, + revision); + Artifact artifact = new DefaultArtifact(revId, null, artifactName, artifactType, + artifactExt); + + CacheManager cacheManager = IvyContext.getContext().getCacheManager(); + + origin = cacheManager.getSavedArtifactOrigin(artifact); + + if (origin == null) { + Message.debug("no artifact origin found for " + artifact + " in " + + cacheManager); + return null; + } + } + + // we assume that the original filename is the last part of the original file location + String location = origin.getLocation(); + int lastPathIndex = location.lastIndexOf('/'); + if (lastPathIndex == -1) { + lastPathIndex = location.lastIndexOf('\\'); + } + int lastColonIndex = location.lastIndexOf('.'); + + return location.substring(lastPathIndex + 1, lastColonIndex); + } + } + + public static String getTokenRoot(String pattern) { + int index = pattern.indexOf('['); + if (index == -1) { + return pattern; + } else { + return pattern.substring(0, index); + } + } +} diff --git a/src/java/org/apache/ivy/core/IvyThread.java b/src/java/org/apache/ivy/core/IvyThread.java index 7541e15a..522c65b1 100644 --- a/src/java/org/apache/ivy/core/IvyThread.java +++ b/src/java/org/apache/ivy/core/IvyThread.java @@ -1,70 +1,70 @@ -/* - * 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.core; - -/** - * A simple thread subclass associated the same IvyContext as the thread in which it is - * instanciated. If you override the run target, then you will have to call initContext() to do the - * association with the original IvyContext. - * - * @see IvyContext - */ -public class IvyThread extends Thread { - private IvyContext context = IvyContext.getContext(); - - public IvyThread() { - super(); - } - - public IvyThread(Runnable target, String name) { - super(target, name); - } - - public IvyThread(Runnable target) { - super(target); - } - - public IvyThread(String name) { - super(name); - } - - public IvyThread(ThreadGroup group, Runnable target, String name, long stackSize) { - super(group, target, name, stackSize); - } - - public IvyThread(ThreadGroup group, Runnable target, String name) { - super(group, target, name); - } - - public IvyThread(ThreadGroup group, Runnable target) { - super(group, target); - } - - public IvyThread(ThreadGroup group, String name) { - super(group, name); - } - - public void run() { - initContext(); - super.run(); - } - - protected void initContext() { - IvyContext.setContext(context); - } -} +/* + * 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.core; + +/** + * A simple thread subclass associated the same IvyContext as the thread in which it is + * instanciated. If you override the run target, then you will have to call initContext() to do the + * association with the original IvyContext. + * + * @see IvyContext + */ +public class IvyThread extends Thread { + private IvyContext context = IvyContext.getContext(); + + public IvyThread() { + super(); + } + + public IvyThread(Runnable target, String name) { + super(target, name); + } + + public IvyThread(Runnable target) { + super(target); + } + + public IvyThread(String name) { + super(name); + } + + public IvyThread(ThreadGroup group, Runnable target, String name, long stackSize) { + super(group, target, name, stackSize); + } + + public IvyThread(ThreadGroup group, Runnable target, String name) { + super(group, target, name); + } + + public IvyThread(ThreadGroup group, Runnable target) { + super(group, target); + } + + public IvyThread(ThreadGroup group, String name) { + super(group, name); + } + + public void run() { + initContext(); + super.run(); + } + + protected void initContext() { + IvyContext.setContext(context); + } +} diff --git a/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java b/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java index b88a7991..2b215858 100644 --- a/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java +++ b/src/java/org/apache/ivy/core/cache/ArtifactOrigin.java @@ -1,89 +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.core.cache; - -/** - * This class contains information about the origin of an artifact. - * - * @see org.apache.ivy.plugins.resolver.BasicResolver - * @see org.apache.ivy.plugins.resolver.util.ResolvedResource - */ -public class ArtifactOrigin { - private boolean isLocal; - - private String location; - - /** - * Create a new instance - * - * @param isLocal - * boolean value indicating if the resource is local (on the - * filesystem). - * @param location - * the location of the resource (normally a url) - */ - public ArtifactOrigin(boolean isLocal, String location) { - this.isLocal = isLocal; - this.location = location; - } - - /** - * Is this resource local to this host, i.e. is it on the file system? - * - * @return boolean value indicating if the resource is local. - */ - public boolean isLocal() { - return isLocal; - } - - /** - * Return the location of the resource (normally a url) - * - * @return the location of the resource - */ - public String getLocation() { - return location; - } - - public String toString() { - return "ArtifactOrigin { isLocal=" + isLocal + ", location=" + location + "}"; - } - - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - - ArtifactOrigin that = (ArtifactOrigin) o; - - if (isLocal != that.isLocal) - return false; - if (!location.equals(that.location)) - return false; - - return true; - } - - public int hashCode() { - int result; - result = (isLocal ? 1 : 0); - result = 31 * result + location.hashCode(); - return result; - } -} +/* + * 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.core.cache; + +/** + * This class contains information about the origin of an artifact. + * + * @see org.apache.ivy.plugins.resolver.BasicResolver + * @see org.apache.ivy.plugins.resolver.util.ResolvedResource + */ +public class ArtifactOrigin { + private boolean isLocal; + + private String location; + + /** + * Create a new instance + * + * @param isLocal + * boolean value indicating if the resource is local (on the + * filesystem). + * @param location + * the location of the resource (normally a url) + */ + public ArtifactOrigin(boolean isLocal, String location) { + this.isLocal = isLocal; + this.location = location; + } + + /** + * Is this resource local to this host, i.e. is it on the file system? + * + * @return boolean value indicating if the resource is local. + */ + public boolean isLocal() { + return isLocal; + } + + /** + * Return the location of the resource (normally a url) + * + * @return the location of the resource + */ + public String getLocation() { + return location; + } + + public String toString() { + return "ArtifactOrigin { isLocal=" + isLocal + ", location=" + location + "}"; + } + + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + ArtifactOrigin that = (ArtifactOrigin) o; + + if (isLocal != that.isLocal) + return false; + if (!location.equals(that.location)) + return false; + + return true; + } + + public int hashCode() { + int result; + result = (isLocal ? 1 : 0); + result = 31 * result + location.hashCode(); + return result; + } +} diff --git a/src/java/org/apache/ivy/core/cache/CacheManager.java b/src/java/org/apache/ivy/core/cache/CacheManager.java index 35166434..26d39e9f 100644 --- a/src/java/org/apache/ivy/core/cache/CacheManager.java +++ b/src/java/org/apache/ivy/core/cache/CacheManager.java @@ -1,307 +1,307 @@ -/* - * 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.core.cache; - -import java.io.File; -import java.io.FilenameFilter; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.DefaultModuleRevision; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.PropertiesFile; - -public class CacheManager { - public static CacheManager getInstance(IvySettings settings, File cache) { - return new CacheManager(settings, cache); - } - - public static CacheManager getInstance(IvySettings settings) { - return getInstance(settings, settings.getDefaultCache()); - } - - private IvySettings settings; - - private File cache; - - public CacheManager(IvySettings settings, File cache) { - this.settings = settings; - this.cache = cache; - } - - public File getResolvedIvyFileInCache(ModuleRevisionId mrid) { - String file = IvyPatternHelper.substitute(settings.getCacheResolvedIvyPattern(), mrid - .getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml"); - return new File(cache, file); - } - - public File getResolvedIvyPropertiesInCache(ModuleRevisionId mrid) { - String file = IvyPatternHelper.substitute(settings.getCacheResolvedIvyPropertiesPattern(), - mrid.getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml"); - return new File(cache, file); - } - - public File getIvyFileInCache(ModuleRevisionId mrid) { - String file = IvyPatternHelper.substitute(settings.getCacheIvyPattern(), DefaultArtifact - .newIvyArtifact(mrid, null)); - return new File(cache, file); - } - - public File getConfigurationResolveReportInCache(String resolveId, String conf) { - return new File(cache, resolveId + "-" + conf + ".xml"); - } - - public File[] getConfigurationResolveReportsInCache(final String resolveId) { - final String prefix = resolveId + "-"; - final String suffix = ".xml"; - return cache.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return (name.startsWith(prefix) && name.endsWith(suffix)); - } - }); - } - - /** - * Returns a File object pointing to where the artifact can be found on the local file system. - * This is usually in the cache, but it can be directly in the repository if it is local and if - * the resolve has been done with useOrigin = true - */ - public File getArchiveFileInCache(Artifact artifact) { - ArtifactOrigin origin = getSavedArtifactOrigin(artifact); - return getArchiveFileInCache(artifact, origin); - } - - /** - * Returns a File object pointing to where the artifact can be found on the local file system. - * This is usually in the cache, but it can be directly in the repository if it is local and if - * the resolve has been done with useOrigin = true - */ - public File getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin) { - File archive = new File(cache, getArchivePathInCache(artifact, origin)); - if (!archive.exists() && origin != null && origin.isLocal()) { - File original = new File(origin.getLocation()); - if (original.exists()) { - return original; - } - } - return archive; - } - - /** - * Returns a File object pointing to where the artifact can be found on the local file system, - * using or not the original location depending on the availability of origin information - * provided as parameter and the setting of useOrigin. If useOrigin is false, this method will - * always return the file in the cache. - */ - public File getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin, boolean useOrigin) { - if (useOrigin && origin != null && origin.isLocal()) { - return new File(origin.getLocation()); - } else { - return new File(cache, getArchivePathInCache(artifact, origin)); - } - } - - public String getArchivePathInCache(Artifact artifact) { - return IvyPatternHelper.substitute(settings.getCacheArtifactPattern(), artifact); - } - - public String getArchivePathInCache(Artifact artifact, ArtifactOrigin origin) { - return IvyPatternHelper.substitute(settings.getCacheArtifactPattern(), artifact, origin); - } - - /** - * Saves the information of which resolver was used to resolve a md, so that this info can be - * retrieve later (even after a jvm restart) by getSavedResolverName(ModuleDescriptor md) - * - * @param md - * the module descriptor resolved - * @param name - * resolver name - */ - public void saveResolver(ModuleDescriptor md, String name) { - PropertiesFile cdf = getCachedDataFile(md); - cdf.setProperty("resolver", name); - cdf.save(); - } - - /** - * Saves the information of which resolver was used to resolve a md, so that this info can be - * retrieve later (even after a jvm restart) by getSavedArtResolverName(ModuleDescriptor md) - * - * @param md - * the module descriptor resolved - * @param name - * artifact resolver name - */ - public void saveArtResolver(ModuleDescriptor md, String name) { - PropertiesFile cdf = getCachedDataFile(md); - cdf.setProperty("artifact.resolver", name); - cdf.save(); - } - - public void saveArtifactOrigin(Artifact artifact, ArtifactOrigin origin) { - PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId()); - cdf.setProperty(getIsLocalKey(artifact), String.valueOf(origin.isLocal())); - cdf.setProperty(getLocationKey(artifact), origin.getLocation()); - cdf.save(); - } - - public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) { - PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId()); - String location = cdf.getProperty(getLocationKey(artifact)); - String local = cdf.getProperty(getIsLocalKey(artifact)); - boolean isLocal = Boolean.valueOf(local).booleanValue(); - - if (location == null) { - // origin has not been specified, return null - return null; - } - - return new ArtifactOrigin(isLocal, location); - } - - public void removeSavedArtifactOrigin(Artifact artifact) { - PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId()); - cdf.remove(getLocationKey(artifact)); - cdf.remove(getIsLocalKey(artifact)); - cdf.save(); - } - - /** - * Creates the unique prefix key that will reference the artifact within the properties. - * - * @param artifact - * the artifact to create the unique key from. Cannot be null. - * @return the unique prefix key as a string. - */ - private String getPrefixKey(Artifact artifact) { - // use the hashcode as a uuid for the artifact (fingers crossed) - int hashCode = artifact.getId().hashCode(); - // use just some visual cue - return "artifact:" + artifact.getName() + "#" + artifact.getType() + "#" - + artifact.getExt() + "#" + hashCode; - } - - /** - * Returns the key used to identify the location of the artifact. - * - * @param artifact - * the artifact to generate the key from. Cannot be null. - * @return the key to be used to reference the artifact location. - */ - private String getLocationKey(Artifact artifact) { - String prefix = getPrefixKey(artifact); - return prefix + ".location"; - } - - /** - * Returns the key used to identify if the artifact is local. - * - * @param artifact - * the artifact to generate the key from. Cannot be null. - * @return the key to be used to reference the artifact location. - */ - private String getIsLocalKey(Artifact artifact) { - String prefix = getPrefixKey(artifact); - return prefix + ".is-local"; - } - - private String getSavedResolverName(ModuleDescriptor md) { - PropertiesFile cdf = getCachedDataFile(md); - return cdf.getProperty("resolver"); - } - - private String getSavedArtResolverName(ModuleDescriptor md) { - PropertiesFile cdf = getCachedDataFile(md); - return cdf.getProperty("artifact.resolver"); - } - - private PropertiesFile getCachedDataFile(ModuleDescriptor md) { - return getCachedDataFile(md.getResolvedModuleRevisionId()); - } - - private PropertiesFile getCachedDataFile(ModuleRevisionId mRevId) { - return new PropertiesFile(new File(cache, IvyPatternHelper.substitute(settings - .getCacheDataFilePattern(), mRevId)), "ivy cached data file for " + mRevId); - } - - public ResolvedModuleRevision findModuleInCache(ModuleRevisionId mrid, boolean validate) { - // first, check if it is in cache - if (!settings.getVersionMatcher().isDynamic(mrid)) { - File ivyFile = getIvyFileInCache(mrid); - if (ivyFile.exists()) { - // found in cache ! - try { - ModuleDescriptor depMD = XmlModuleDescriptorParser.getInstance() - .parseDescriptor(settings, ivyFile.toURL(), validate); - String resolverName = getSavedResolverName(depMD); - String artResolverName = getSavedArtResolverName(depMD); - DependencyResolver resolver = settings.getResolver(resolverName); - if (resolver == null) { - Message.debug("\tresolver not found: " + resolverName - + " => trying to use the one configured for " + mrid); - resolver = settings.getResolver(depMD.getResolvedModuleRevisionId() - .getModuleId()); - if (resolver != null) { - Message.debug("\tconfigured resolver found for " - + depMD.getResolvedModuleRevisionId() + ": " - + resolver.getName() + ": saving this data"); - saveResolver(depMD, resolver.getName()); - } - } - DependencyResolver artResolver = settings.getResolver(artResolverName); - if (artResolver == null) { - artResolver = resolver; - } - if (resolver != null) { - Message.debug("\tfound ivy file in cache for " + mrid + " (resolved by " - + resolver.getName() + "): " + ivyFile); - return new DefaultModuleRevision(resolver, artResolver, depMD, false, - false, ivyFile.toURL()); - } else { - Message.debug("\tresolver not found: " + resolverName - + " => cannot use cached ivy file for " + mrid); - } - } catch (Exception e) { - // will try with resolver - Message.debug("\tproblem while parsing cached ivy file for: " + mrid + ": " - + e.getMessage()); - } - } else { - Message.debug("\tno ivy file in cache for " + mrid + ": tried " + ivyFile); - } - } - return null; - } - - public String toString() { - return "cache: " + String.valueOf(cache); - } - - public File getCache() { - return cache; - } - -} +/* + * 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.core.cache; + +import java.io.File; +import java.io.FilenameFilter; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.DefaultModuleRevision; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.PropertiesFile; + +public class CacheManager { + public static CacheManager getInstance(IvySettings settings, File cache) { + return new CacheManager(settings, cache); + } + + public static CacheManager getInstance(IvySettings settings) { + return getInstance(settings, settings.getDefaultCache()); + } + + private IvySettings settings; + + private File cache; + + public CacheManager(IvySettings settings, File cache) { + this.settings = settings; + this.cache = cache; + } + + public File getResolvedIvyFileInCache(ModuleRevisionId mrid) { + String file = IvyPatternHelper.substitute(settings.getCacheResolvedIvyPattern(), mrid + .getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml"); + return new File(cache, file); + } + + public File getResolvedIvyPropertiesInCache(ModuleRevisionId mrid) { + String file = IvyPatternHelper.substitute(settings.getCacheResolvedIvyPropertiesPattern(), + mrid.getOrganisation(), mrid.getName(), mrid.getRevision(), "ivy", "ivy", "xml"); + return new File(cache, file); + } + + public File getIvyFileInCache(ModuleRevisionId mrid) { + String file = IvyPatternHelper.substitute(settings.getCacheIvyPattern(), DefaultArtifact + .newIvyArtifact(mrid, null)); + return new File(cache, file); + } + + public File getConfigurationResolveReportInCache(String resolveId, String conf) { + return new File(cache, resolveId + "-" + conf + ".xml"); + } + + public File[] getConfigurationResolveReportsInCache(final String resolveId) { + final String prefix = resolveId + "-"; + final String suffix = ".xml"; + return cache.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return (name.startsWith(prefix) && name.endsWith(suffix)); + } + }); + } + + /** + * Returns a File object pointing to where the artifact can be found on the local file system. + * This is usually in the cache, but it can be directly in the repository if it is local and if + * the resolve has been done with useOrigin = true + */ + public File getArchiveFileInCache(Artifact artifact) { + ArtifactOrigin origin = getSavedArtifactOrigin(artifact); + return getArchiveFileInCache(artifact, origin); + } + + /** + * Returns a File object pointing to where the artifact can be found on the local file system. + * This is usually in the cache, but it can be directly in the repository if it is local and if + * the resolve has been done with useOrigin = true + */ + public File getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin) { + File archive = new File(cache, getArchivePathInCache(artifact, origin)); + if (!archive.exists() && origin != null && origin.isLocal()) { + File original = new File(origin.getLocation()); + if (original.exists()) { + return original; + } + } + return archive; + } + + /** + * Returns a File object pointing to where the artifact can be found on the local file system, + * using or not the original location depending on the availability of origin information + * provided as parameter and the setting of useOrigin. If useOrigin is false, this method will + * always return the file in the cache. + */ + public File getArchiveFileInCache(Artifact artifact, ArtifactOrigin origin, boolean useOrigin) { + if (useOrigin && origin != null && origin.isLocal()) { + return new File(origin.getLocation()); + } else { + return new File(cache, getArchivePathInCache(artifact, origin)); + } + } + + public String getArchivePathInCache(Artifact artifact) { + return IvyPatternHelper.substitute(settings.getCacheArtifactPattern(), artifact); + } + + public String getArchivePathInCache(Artifact artifact, ArtifactOrigin origin) { + return IvyPatternHelper.substitute(settings.getCacheArtifactPattern(), artifact, origin); + } + + /** + * Saves the information of which resolver was used to resolve a md, so that this info can be + * retrieve later (even after a jvm restart) by getSavedResolverName(ModuleDescriptor md) + * + * @param md + * the module descriptor resolved + * @param name + * resolver name + */ + public void saveResolver(ModuleDescriptor md, String name) { + PropertiesFile cdf = getCachedDataFile(md); + cdf.setProperty("resolver", name); + cdf.save(); + } + + /** + * Saves the information of which resolver was used to resolve a md, so that this info can be + * retrieve later (even after a jvm restart) by getSavedArtResolverName(ModuleDescriptor md) + * + * @param md + * the module descriptor resolved + * @param name + * artifact resolver name + */ + public void saveArtResolver(ModuleDescriptor md, String name) { + PropertiesFile cdf = getCachedDataFile(md); + cdf.setProperty("artifact.resolver", name); + cdf.save(); + } + + public void saveArtifactOrigin(Artifact artifact, ArtifactOrigin origin) { + PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId()); + cdf.setProperty(getIsLocalKey(artifact), String.valueOf(origin.isLocal())); + cdf.setProperty(getLocationKey(artifact), origin.getLocation()); + cdf.save(); + } + + public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) { + PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId()); + String location = cdf.getProperty(getLocationKey(artifact)); + String local = cdf.getProperty(getIsLocalKey(artifact)); + boolean isLocal = Boolean.valueOf(local).booleanValue(); + + if (location == null) { + // origin has not been specified, return null + return null; + } + + return new ArtifactOrigin(isLocal, location); + } + + public void removeSavedArtifactOrigin(Artifact artifact) { + PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId()); + cdf.remove(getLocationKey(artifact)); + cdf.remove(getIsLocalKey(artifact)); + cdf.save(); + } + + /** + * Creates the unique prefix key that will reference the artifact within the properties. + * + * @param artifact + * the artifact to create the unique key from. Cannot be null. + * @return the unique prefix key as a string. + */ + private String getPrefixKey(Artifact artifact) { + // use the hashcode as a uuid for the artifact (fingers crossed) + int hashCode = artifact.getId().hashCode(); + // use just some visual cue + return "artifact:" + artifact.getName() + "#" + artifact.getType() + "#" + + artifact.getExt() + "#" + hashCode; + } + + /** + * Returns the key used to identify the location of the artifact. + * + * @param artifact + * the artifact to generate the key from. Cannot be null. + * @return the key to be used to reference the artifact location. + */ + private String getLocationKey(Artifact artifact) { + String prefix = getPrefixKey(artifact); + return prefix + ".location"; + } + + /** + * Returns the key used to identify if the artifact is local. + * + * @param artifact + * the artifact to generate the key from. Cannot be null. + * @return the key to be used to reference the artifact location. + */ + private String getIsLocalKey(Artifact artifact) { + String prefix = getPrefixKey(artifact); + return prefix + ".is-local"; + } + + private String getSavedResolverName(ModuleDescriptor md) { + PropertiesFile cdf = getCachedDataFile(md); + return cdf.getProperty("resolver"); + } + + private String getSavedArtResolverName(ModuleDescriptor md) { + PropertiesFile cdf = getCachedDataFile(md); + return cdf.getProperty("artifact.resolver"); + } + + private PropertiesFile getCachedDataFile(ModuleDescriptor md) { + return getCachedDataFile(md.getResolvedModuleRevisionId()); + } + + private PropertiesFile getCachedDataFile(ModuleRevisionId mRevId) { + return new PropertiesFile(new File(cache, IvyPatternHelper.substitute(settings + .getCacheDataFilePattern(), mRevId)), "ivy cached data file for " + mRevId); + } + + public ResolvedModuleRevision findModuleInCache(ModuleRevisionId mrid, boolean validate) { + // first, check if it is in cache + if (!settings.getVersionMatcher().isDynamic(mrid)) { + File ivyFile = getIvyFileInCache(mrid); + if (ivyFile.exists()) { + // found in cache ! + try { + ModuleDescriptor depMD = XmlModuleDescriptorParser.getInstance() + .parseDescriptor(settings, ivyFile.toURL(), validate); + String resolverName = getSavedResolverName(depMD); + String artResolverName = getSavedArtResolverName(depMD); + DependencyResolver resolver = settings.getResolver(resolverName); + if (resolver == null) { + Message.debug("\tresolver not found: " + resolverName + + " => trying to use the one configured for " + mrid); + resolver = settings.getResolver(depMD.getResolvedModuleRevisionId() + .getModuleId()); + if (resolver != null) { + Message.debug("\tconfigured resolver found for " + + depMD.getResolvedModuleRevisionId() + ": " + + resolver.getName() + ": saving this data"); + saveResolver(depMD, resolver.getName()); + } + } + DependencyResolver artResolver = settings.getResolver(artResolverName); + if (artResolver == null) { + artResolver = resolver; + } + if (resolver != null) { + Message.debug("\tfound ivy file in cache for " + mrid + " (resolved by " + + resolver.getName() + "): " + ivyFile); + return new DefaultModuleRevision(resolver, artResolver, depMD, false, + false, ivyFile.toURL()); + } else { + Message.debug("\tresolver not found: " + resolverName + + " => cannot use cached ivy file for " + mrid); + } + } catch (Exception e) { + // will try with resolver + Message.debug("\tproblem while parsing cached ivy file for: " + mrid + ": " + + e.getMessage()); + } + } else { + Message.debug("\tno ivy file in cache for " + mrid + ": tried " + ivyFile); + } + } + return null; + } + + public String toString() { + return "cache: " + String.valueOf(cache); + } + + public File getCache() { + return cache; + } + +} diff --git a/src/java/org/apache/ivy/core/check/CheckEngine.java b/src/java/org/apache/ivy/core/check/CheckEngine.java index 5f6a005f..95734691 100644 --- a/src/java/org/apache/ivy/core/check/CheckEngine.java +++ b/src/java/org/apache/ivy/core/check/CheckEngine.java @@ -1,140 +1,140 @@ -/* - * 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.core.check; - -import java.io.IOException; -import java.net.URL; -import java.text.ParseException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -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.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.Message; - -public class CheckEngine { - private IvySettings settings; - - private ResolveEngine resolveEngine; - - public CheckEngine(IvySettings settings, ResolveEngine resolveEngine) { - this.settings = settings; - this.resolveEngine = resolveEngine; - } - - /** - * Checks the given ivy file using current settings to see if all dependencies are available, - * with good confs. If a resolver name is given, it also checks that the declared publications - * are available in the corresponding resolver. Note that the check is not performed - * recursively, i.e. if a dependency has itself dependencies badly described or not available, - * this check will not discover it. - */ - public boolean check(URL ivyFile, String resolvername) { - try { - boolean result = true; - // parse ivy file - ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor( - settings, ivyFile, settings.doValidate()); - - // check publications if possible - if (resolvername != null) { - DependencyResolver resolver = settings.getResolver(resolvername); - String[] confs = md.getConfigurationsNames(); - Set artifacts = new HashSet(); - for (int i = 0; i < confs.length; i++) { - artifacts.addAll(Arrays.asList(md.getArtifacts(confs[i]))); - } - for (Iterator iter = artifacts.iterator(); iter.hasNext();) { - Artifact art = (Artifact) iter.next(); - if (!resolver.exists(art)) { - Message.info("declared publication not found: " + art); - result = false; - } - } - } - - // check dependencies - DependencyDescriptor[] dds = md.getDependencies(); - ResolveData data = new ResolveData(resolveEngine, new ResolveOptions() - .setCache(CacheManager.getInstance(settings))); - for (int i = 0; i < dds.length; i++) { - // check master confs - String[] masterConfs = dds[i].getModuleConfigurations(); - for (int j = 0; j < masterConfs.length; j++) { - if (!"*".equals(masterConfs[j].trim()) - && md.getConfiguration(masterConfs[j]) == null) { - Message.info("dependency required in non existing conf for " + ivyFile - + " \n\tin " + dds[i].getDependencyRevisionId() + ": " - + masterConfs[j]); - result = false; - } - } - // resolve - DependencyResolver resolver = settings.getResolver(dds[i].getDependencyId()); - ResolvedModuleRevision rmr = resolver.getDependency(dds[i], data); - if (rmr == null) { - Message.info("dependency not found in " + ivyFile + ":\n\t" + dds[i]); - result = false; - } else { - String[] depConfs = dds[i].getDependencyConfigurations(md - .getConfigurationsNames()); - for (int j = 0; j < depConfs.length; j++) { - if (!Arrays.asList(rmr.getDescriptor().getConfigurationsNames()).contains( - depConfs[j])) { - Message.info("dependency configuration is missing for " + ivyFile - + "\n\tin " + dds[i].getDependencyRevisionId() + ": " - + depConfs[j]); - result = false; - } - Artifact[] arts = rmr.getDescriptor().getArtifacts(depConfs[j]); - for (int k = 0; k < arts.length; k++) { - if (!resolver.exists(arts[k])) { - Message.info("dependency artifact is missing for " + ivyFile - + "\n\t in " + dds[i].getDependencyRevisionId() + ": " - + arts[k]); - result = false; - } - } - } - } - } - return result; - } catch (ParseException e) { - Message.info("parse problem on " + ivyFile + ": " + e); - return false; - } catch (IOException e) { - Message.info("io problem on " + ivyFile + ": " + e); - return false; - } catch (Exception e) { - Message.info("problem on " + ivyFile + ": " + e); - return false; - } - } - -} +/* + * 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.core.check; + +import java.io.IOException; +import java.net.URL; +import java.text.ParseException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +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.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.Message; + +public class CheckEngine { + private IvySettings settings; + + private ResolveEngine resolveEngine; + + public CheckEngine(IvySettings settings, ResolveEngine resolveEngine) { + this.settings = settings; + this.resolveEngine = resolveEngine; + } + + /** + * Checks the given ivy file using current settings to see if all dependencies are available, + * with good confs. If a resolver name is given, it also checks that the declared publications + * are available in the corresponding resolver. Note that the check is not performed + * recursively, i.e. if a dependency has itself dependencies badly described or not available, + * this check will not discover it. + */ + public boolean check(URL ivyFile, String resolvername) { + try { + boolean result = true; + // parse ivy file + ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor( + settings, ivyFile, settings.doValidate()); + + // check publications if possible + if (resolvername != null) { + DependencyResolver resolver = settings.getResolver(resolvername); + String[] confs = md.getConfigurationsNames(); + Set artifacts = new HashSet(); + for (int i = 0; i < confs.length; i++) { + artifacts.addAll(Arrays.asList(md.getArtifacts(confs[i]))); + } + for (Iterator iter = artifacts.iterator(); iter.hasNext();) { + Artifact art = (Artifact) iter.next(); + if (!resolver.exists(art)) { + Message.info("declared publication not found: " + art); + result = false; + } + } + } + + // check dependencies + DependencyDescriptor[] dds = md.getDependencies(); + ResolveData data = new ResolveData(resolveEngine, new ResolveOptions() + .setCache(CacheManager.getInstance(settings))); + for (int i = 0; i < dds.length; i++) { + // check master confs + String[] masterConfs = dds[i].getModuleConfigurations(); + for (int j = 0; j < masterConfs.length; j++) { + if (!"*".equals(masterConfs[j].trim()) + && md.getConfiguration(masterConfs[j]) == null) { + Message.info("dependency required in non existing conf for " + ivyFile + + " \n\tin " + dds[i].getDependencyRevisionId() + ": " + + masterConfs[j]); + result = false; + } + } + // resolve + DependencyResolver resolver = settings.getResolver(dds[i].getDependencyId()); + ResolvedModuleRevision rmr = resolver.getDependency(dds[i], data); + if (rmr == null) { + Message.info("dependency not found in " + ivyFile + ":\n\t" + dds[i]); + result = false; + } else { + String[] depConfs = dds[i].getDependencyConfigurations(md + .getConfigurationsNames()); + for (int j = 0; j < depConfs.length; j++) { + if (!Arrays.asList(rmr.getDescriptor().getConfigurationsNames()).contains( + depConfs[j])) { + Message.info("dependency configuration is missing for " + ivyFile + + "\n\tin " + dds[i].getDependencyRevisionId() + ": " + + depConfs[j]); + result = false; + } + Artifact[] arts = rmr.getDescriptor().getArtifacts(depConfs[j]); + for (int k = 0; k < arts.length; k++) { + if (!resolver.exists(arts[k])) { + Message.info("dependency artifact is missing for " + ivyFile + + "\n\t in " + dds[i].getDependencyRevisionId() + ": " + + arts[k]); + result = false; + } + } + } + } + } + return result; + } catch (ParseException e) { + Message.info("parse problem on " + ivyFile + ": " + e); + return false; + } catch (IOException e) { + Message.info("io problem on " + ivyFile + ": " + e); + return false; + } catch (Exception e) { + Message.info("problem on " + ivyFile + ": " + e); + return false; + } + } + +} diff --git a/src/java/org/apache/ivy/core/deliver/DefaultPublishingDRResolver.java b/src/java/org/apache/ivy/core/deliver/DefaultPublishingDRResolver.java index 4dd179d1..50f26e5c 100644 --- a/src/java/org/apache/ivy/core/deliver/DefaultPublishingDRResolver.java +++ b/src/java/org/apache/ivy/core/deliver/DefaultPublishingDRResolver.java @@ -1,28 +1,28 @@ -/* - * 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.core.deliver; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class DefaultPublishingDRResolver implements PublishingDependencyRevisionResolver { - public String resolve(ModuleDescriptor published, String publishedStatus, - ModuleRevisionId depMrid, String status) { - return depMrid.getRevision(); - } -} +/* + * 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.core.deliver; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class DefaultPublishingDRResolver implements PublishingDependencyRevisionResolver { + public String resolve(ModuleDescriptor published, String publishedStatus, + ModuleRevisionId depMrid, String status) { + return depMrid.getRevision(); + } +} diff --git a/src/java/org/apache/ivy/core/deliver/DeliverEngine.java b/src/java/org/apache/ivy/core/deliver/DeliverEngine.java index e311c532..f6cfc4cf 100644 --- a/src/java/org/apache/ivy/core/deliver/DeliverEngine.java +++ b/src/java/org/apache/ivy/core/deliver/DeliverEngine.java @@ -1,189 +1,189 @@ -/* - * 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.core.deliver; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.text.ParseException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater; -import org.apache.ivy.plugins.report.XmlReportParser; -import org.apache.ivy.util.ConfigurationUtils; -import org.apache.ivy.util.Message; -import org.xml.sax.SAXException; - -public class DeliverEngine { - private IvySettings settings; - - public DeliverEngine(IvySettings settings) { - this.settings = settings; - } - - /** - * Delivers a resolved ivy file based upon last resolve call status. If resolve report file - * cannot be found in cache, then it throws an IllegalStateException (maybe resolve has not been - * called before ?). - * - * @param revision - * the revision to which the module should be delivered - * @param destIvyPattern - * the pattern to which the delivered ivy file should be written - * @param options - * the options with which deliver should be done - */ - public void deliver(String revision, String destIvyPattern, DeliverOptions options) - throws IOException, ParseException { - String resolveId = options.getResolveId(); - if (resolveId == null) { - throw new IllegalArgumentException("A resolveId must be specified for delivering."); - } - File[] files = options.getCache().getConfigurationResolveReportsInCache(resolveId); - if (files.length == 0) { - throw new IllegalStateException("No previous resolve found for id '" + resolveId - + "' Please resolve dependencies before delivering."); - } - XmlReportParser parser = new XmlReportParser(); - parser.parse(files[0]); - ModuleRevisionId mrid = parser.getResolvedModule(); - deliver(mrid, revision, destIvyPattern, options); - } - - /** - * Delivers a resolved ivy file based upon last resolve call status. If resolve report file - * cannot be found in cache, then it throws an IllegalStateException (maybe resolve has not been - * called before ?). - * - * @param mrid - * the module revision id of the module to deliver - * @param revision - * the revision to which the module should be delivered - * @param destIvyPattern - * the pattern to which the delivered ivy file should be written - * @param options - * the options with which deliver should be done - */ - public void deliver(ModuleRevisionId mrid, String revision, String destIvyPattern, - DeliverOptions options) throws IOException, ParseException { - Message.info(":: delivering :: " + mrid + " :: " + revision + " :: " + options.getStatus() - + " :: " + options.getPubdate()); - Message.verbose("\toptions = " + options); - long start = System.currentTimeMillis(); - destIvyPattern = settings.substitute(destIvyPattern); - - // 1) find the resolved module descriptor in cache - File ivyFile = options.getCache().getResolvedIvyFileInCache(mrid); - if (!ivyFile.exists()) { - throw new IllegalStateException("ivy file not found in cache for " + mrid - + ": please resolve dependencies before delivering (" + ivyFile + ")"); - } - ModuleDescriptor md = null; - URL ivyFileURL = null; - try { - ivyFileURL = ivyFile.toURL(); - md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, - options.isValidate()); - md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(mrid, revision)); - md.setResolvedPublicationDate(options.getPubdate()); - } catch (MalformedURLException e) { - throw new RuntimeException("malformed url obtained for file " + ivyFile, e); - } catch (ParseException e) { - throw new RuntimeException("bad ivy file in cache for " + mrid - + ": please clean and resolve again", e); - } - - // 2) parse resolvedRevisions From properties file - Map resolvedRevisions = new HashMap(); // Map (ModuleId -> String revision) - Map dependenciesStatus = new HashMap(); // Map (ModuleId -> String status) - File ivyProperties = options.getCache().getResolvedIvyPropertiesInCache(mrid); - if (!ivyProperties.exists()) { - throw new IllegalStateException("ivy properties not found in cache for " + mrid - + ": please resolve dependencies before delivering (" + ivyFile + ")"); - } - Properties props = new Properties(); - FileInputStream in = new FileInputStream(ivyProperties); - props.load(in); - in.close(); - - for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { - String depMridStr = (String) iter.next(); - String[] parts = props.getProperty(depMridStr).split(" "); - ModuleRevisionId decodedMrid = ModuleRevisionId.decode(depMridStr); - if (options.isResolveDynamicRevisions()) { - resolvedRevisions.put(decodedMrid, parts[0]); - } - dependenciesStatus.put(decodedMrid, parts[1]); - } - - // 3) use pdrResolver to resolve dependencies info - Map resolvedDependencies = new HashMap(); // Map (ModuleRevisionId -> String revision) - DependencyDescriptor[] dependencies = md.getDependencies(); - for (int i = 0; i < dependencies.length; i++) { - String rev = (String) resolvedRevisions.get(dependencies[i].getDependencyRevisionId()); - if (rev == null) { - rev = dependencies[i].getDependencyRevisionId().getRevision(); - } - String depStatus = (String) dependenciesStatus.get(dependencies[i] - .getDependencyRevisionId()); - resolvedDependencies.put(dependencies[i].getDependencyRevisionId(), options - .getPdrResolver().resolve( - md, - options.getStatus(), - ModuleRevisionId - .newInstance(dependencies[i].getDependencyRevisionId(), rev), - depStatus)); - } - - // 4) copy the source resolved ivy to the destination specified, - // updating status, revision and dependency revisions obtained by - // PublishingDependencyRevisionResolver - String publishedIvy = IvyPatternHelper.substitute(destIvyPattern, md - .getResolvedModuleRevisionId()); - Message.info("\tdelivering ivy file to " + publishedIvy); - - String[] confs = ConfigurationUtils.replaceWildcards(options.getConfs(), md); - Set confsToRemove = new HashSet(Arrays.asList(md.getConfigurationsNames())); - confsToRemove.removeAll(Arrays.asList(confs)); - - try { - XmlModuleDescriptorUpdater.update(settings, ivyFileURL, new File(publishedIvy), - resolvedDependencies, options.getStatus(), revision, options.getPubdate(), null, - true, (String[]) confsToRemove.toArray(new String[confsToRemove.size()])); - } catch (SAXException ex) { - throw new RuntimeException("bad ivy file in cache for " + mrid - + ": please clean and resolve again", ex); - } - - Message.verbose("\tdeliver done (" + (System.currentTimeMillis() - start) + "ms)"); - } -} +/* + * 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.core.deliver; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.ParseException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater; +import org.apache.ivy.plugins.report.XmlReportParser; +import org.apache.ivy.util.ConfigurationUtils; +import org.apache.ivy.util.Message; +import org.xml.sax.SAXException; + +public class DeliverEngine { + private IvySettings settings; + + public DeliverEngine(IvySettings settings) { + this.settings = settings; + } + + /** + * Delivers a resolved ivy file based upon last resolve call status. If resolve report file + * cannot be found in cache, then it throws an IllegalStateException (maybe resolve has not been + * called before ?). + * + * @param revision + * the revision to which the module should be delivered + * @param destIvyPattern + * the pattern to which the delivered ivy file should be written + * @param options + * the options with which deliver should be done + */ + public void deliver(String revision, String destIvyPattern, DeliverOptions options) + throws IOException, ParseException { + String resolveId = options.getResolveId(); + if (resolveId == null) { + throw new IllegalArgumentException("A resolveId must be specified for delivering."); + } + File[] files = options.getCache().getConfigurationResolveReportsInCache(resolveId); + if (files.length == 0) { + throw new IllegalStateException("No previous resolve found for id '" + resolveId + + "' Please resolve dependencies before delivering."); + } + XmlReportParser parser = new XmlReportParser(); + parser.parse(files[0]); + ModuleRevisionId mrid = parser.getResolvedModule(); + deliver(mrid, revision, destIvyPattern, options); + } + + /** + * Delivers a resolved ivy file based upon last resolve call status. If resolve report file + * cannot be found in cache, then it throws an IllegalStateException (maybe resolve has not been + * called before ?). + * + * @param mrid + * the module revision id of the module to deliver + * @param revision + * the revision to which the module should be delivered + * @param destIvyPattern + * the pattern to which the delivered ivy file should be written + * @param options + * the options with which deliver should be done + */ + public void deliver(ModuleRevisionId mrid, String revision, String destIvyPattern, + DeliverOptions options) throws IOException, ParseException { + Message.info(":: delivering :: " + mrid + " :: " + revision + " :: " + options.getStatus() + + " :: " + options.getPubdate()); + Message.verbose("\toptions = " + options); + long start = System.currentTimeMillis(); + destIvyPattern = settings.substitute(destIvyPattern); + + // 1) find the resolved module descriptor in cache + File ivyFile = options.getCache().getResolvedIvyFileInCache(mrid); + if (!ivyFile.exists()) { + throw new IllegalStateException("ivy file not found in cache for " + mrid + + ": please resolve dependencies before delivering (" + ivyFile + ")"); + } + ModuleDescriptor md = null; + URL ivyFileURL = null; + try { + ivyFileURL = ivyFile.toURL(); + md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, + options.isValidate()); + md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(mrid, revision)); + md.setResolvedPublicationDate(options.getPubdate()); + } catch (MalformedURLException e) { + throw new RuntimeException("malformed url obtained for file " + ivyFile, e); + } catch (ParseException e) { + throw new RuntimeException("bad ivy file in cache for " + mrid + + ": please clean and resolve again", e); + } + + // 2) parse resolvedRevisions From properties file + Map resolvedRevisions = new HashMap(); // Map (ModuleId -> String revision) + Map dependenciesStatus = new HashMap(); // Map (ModuleId -> String status) + File ivyProperties = options.getCache().getResolvedIvyPropertiesInCache(mrid); + if (!ivyProperties.exists()) { + throw new IllegalStateException("ivy properties not found in cache for " + mrid + + ": please resolve dependencies before delivering (" + ivyFile + ")"); + } + Properties props = new Properties(); + FileInputStream in = new FileInputStream(ivyProperties); + props.load(in); + in.close(); + + for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { + String depMridStr = (String) iter.next(); + String[] parts = props.getProperty(depMridStr).split(" "); + ModuleRevisionId decodedMrid = ModuleRevisionId.decode(depMridStr); + if (options.isResolveDynamicRevisions()) { + resolvedRevisions.put(decodedMrid, parts[0]); + } + dependenciesStatus.put(decodedMrid, parts[1]); + } + + // 3) use pdrResolver to resolve dependencies info + Map resolvedDependencies = new HashMap(); // Map (ModuleRevisionId -> String revision) + DependencyDescriptor[] dependencies = md.getDependencies(); + for (int i = 0; i < dependencies.length; i++) { + String rev = (String) resolvedRevisions.get(dependencies[i].getDependencyRevisionId()); + if (rev == null) { + rev = dependencies[i].getDependencyRevisionId().getRevision(); + } + String depStatus = (String) dependenciesStatus.get(dependencies[i] + .getDependencyRevisionId()); + resolvedDependencies.put(dependencies[i].getDependencyRevisionId(), options + .getPdrResolver().resolve( + md, + options.getStatus(), + ModuleRevisionId + .newInstance(dependencies[i].getDependencyRevisionId(), rev), + depStatus)); + } + + // 4) copy the source resolved ivy to the destination specified, + // updating status, revision and dependency revisions obtained by + // PublishingDependencyRevisionResolver + String publishedIvy = IvyPatternHelper.substitute(destIvyPattern, md + .getResolvedModuleRevisionId()); + Message.info("\tdelivering ivy file to " + publishedIvy); + + String[] confs = ConfigurationUtils.replaceWildcards(options.getConfs(), md); + Set confsToRemove = new HashSet(Arrays.asList(md.getConfigurationsNames())); + confsToRemove.removeAll(Arrays.asList(confs)); + + try { + XmlModuleDescriptorUpdater.update(settings, ivyFileURL, new File(publishedIvy), + resolvedDependencies, options.getStatus(), revision, options.getPubdate(), null, + true, (String[]) confsToRemove.toArray(new String[confsToRemove.size()])); + } catch (SAXException ex) { + throw new RuntimeException("bad ivy file in cache for " + mrid + + ": please clean and resolve again", ex); + } + + Message.verbose("\tdeliver done (" + (System.currentTimeMillis() - start) + "ms)"); + } +} diff --git a/src/java/org/apache/ivy/core/deliver/DeliverOptions.java b/src/java/org/apache/ivy/core/deliver/DeliverOptions.java index 0e10b390..d1fc0bc5 100644 --- a/src/java/org/apache/ivy/core/deliver/DeliverOptions.java +++ b/src/java/org/apache/ivy/core/deliver/DeliverOptions.java @@ -1,220 +1,220 @@ -/* - * 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.core.deliver; - -import java.util.Date; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.settings.IvySettings; - -/** - * A set of options used to do a deliver. - */ -public class DeliverOptions { - private String status; - - private Date pubdate; - - private CacheManager cache; - - private PublishingDependencyRevisionResolver pdrResolver = new DefaultPublishingDRResolver(); - - private boolean validate = true; - - private boolean resolveDynamicRevisions = true; - - private String resolveId; - - private String[] confs; - - /** - * Returns an instance of DeliverOptions with options corresponding to default values taken from - * the given settings. - * - * @param settings - * The settings to use to get default option values - * @return a DeliverOptions instance ready to be used or customized - */ - public static DeliverOptions newInstance(IvySettings settings) { - return new DeliverOptions(null, new Date(), CacheManager.getInstance(settings), - new DefaultPublishingDRResolver(), settings.doValidate(), true, null); - } - - /** - * Creates an instance of DeliverOptions which require to be configured using the appropriate - * setters. - */ - public DeliverOptions() { - } - - /** - * Creates an instance of DeliverOptions with all options explicitly set. - */ - public DeliverOptions(String status, Date pubDate, CacheManager cache, - PublishingDependencyRevisionResolver pdrResolver, boolean validate, - boolean resolveDynamicRevisions, String[] confs) { - this.status = status; - this.pubdate = pubDate; - this.cache = cache; - this.pdrResolver = pdrResolver; - this.validate = validate; - this.resolveDynamicRevisions = resolveDynamicRevisions; - this.confs = confs; - } - - public CacheManager getCache() { - return cache; - } - - public DeliverOptions setCache(CacheManager cache) { - this.cache = cache; - return this; - } - - /** - * Return the pdrResolver that will be used during deliver for each dependency to get its - * published information. This can particularly useful when the deliver is made for a release, - * and when we wish to deliver each dependency which is still in integration. The - * PublishingDependencyRevisionResolver can then do the delivering work for the dependency and - * return the new (delivered) dependency info (with the delivered revision). Note that - * PublishingDependencyRevisionResolver is only called for each direct dependency. - * - * @return the pdrResolver that will be used during deliver - */ - public PublishingDependencyRevisionResolver getPdrResolver() { - return pdrResolver; - } - - /** - * Sets the pdrResolver that will be used during deliver for each dependency to get its - * published information. This can particularly useful when the deliver is made for a release, - * and when we wish to deliver each dependency which is still in integration. The - * PublishingDependencyRevisionResolver can then do the delivering work for the dependency and - * return the new (delivered) dependency info (with the delivered revision). Note that - * PublishingDependencyRevisionResolver is only called for each direct dependency. - * - * @return the instance of DeliverOptions on which the method has been called, for easy method - * chaining - */ - public DeliverOptions setPdrResolver(PublishingDependencyRevisionResolver pdrResolver) { - this.pdrResolver = pdrResolver; - return this; - } - - public boolean isResolveDynamicRevisions() { - return resolveDynamicRevisions; - } - - public DeliverOptions setResolveDynamicRevisions(boolean resolveDynamicRevisions) { - this.resolveDynamicRevisions = resolveDynamicRevisions; - return this; - } - - public boolean isValidate() { - return validate; - } - - public DeliverOptions setValidate(boolean validate) { - this.validate = validate; - return this; - } - - public Date getPubdate() { - return pubdate; - } - - public DeliverOptions setPubdate(Date pubdate) { - this.pubdate = pubdate; - return this; - } - - /** - * Returns the status to which the module should be delivered, or null if the current status - * should be kept. - * - * @return the status to which the module should be delivered - */ - public String getStatus() { - return status; - } - - /** - * Sets the status to which the module should be delivered, use null if the current status - * should be kept. - * - * @return the instance of DeliverOptions on which the method has been called, for easy method - * chaining - */ - public DeliverOptions setStatus(String status) { - this.status = status; - return this; - } - - /** - * Returns the id of a previous resolve to use for delivering. - * - * @return the id of a previous resolve - */ - public String getResolveId() { - return resolveId; - } - - /** - * Sets the id of a previous resolve to use for delivering. - * - * @param resolveId - * the id of a previous resolve - * @return the instance of DeliverOptions on which the method has been called, for easy method - * chaining - */ - public DeliverOptions setResolveId(String resolveId) { - this.resolveId = resolveId; - return this; - } - - /** - * Return the configurations which must be deliverd. Returns null if all - * configurations has to be deliverd. Attention: the returned array can contain wildcards! - * - * @return the configurations to deliver - */ - public String[] getConfs() { - return confs; - } - - /** - * Sets the configurations to deliver. - * - * @param confs - * the configurations to deliver - * @return the instance of DeliverOptions on which the method has been called, for easy method - * chaining - */ - public DeliverOptions setConfs(String[] confs) { - this.confs = confs; - return this; - } - - public String toString() { - return "status=" + status + " pubdate=" + pubdate + " validate=" + validate - + " resolveDynamicRevisions=" + resolveDynamicRevisions + " cache=" + cache - + " resolveId=" + resolveId; - - } - -} +/* + * 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.core.deliver; + +import java.util.Date; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.settings.IvySettings; + +/** + * A set of options used to do a deliver. + */ +public class DeliverOptions { + private String status; + + private Date pubdate; + + private CacheManager cache; + + private PublishingDependencyRevisionResolver pdrResolver = new DefaultPublishingDRResolver(); + + private boolean validate = true; + + private boolean resolveDynamicRevisions = true; + + private String resolveId; + + private String[] confs; + + /** + * Returns an instance of DeliverOptions with options corresponding to default values taken from + * the given settings. + * + * @param settings + * The settings to use to get default option values + * @return a DeliverOptions instance ready to be used or customized + */ + public static DeliverOptions newInstance(IvySettings settings) { + return new DeliverOptions(null, new Date(), CacheManager.getInstance(settings), + new DefaultPublishingDRResolver(), settings.doValidate(), true, null); + } + + /** + * Creates an instance of DeliverOptions which require to be configured using the appropriate + * setters. + */ + public DeliverOptions() { + } + + /** + * Creates an instance of DeliverOptions with all options explicitly set. + */ + public DeliverOptions(String status, Date pubDate, CacheManager cache, + PublishingDependencyRevisionResolver pdrResolver, boolean validate, + boolean resolveDynamicRevisions, String[] confs) { + this.status = status; + this.pubdate = pubDate; + this.cache = cache; + this.pdrResolver = pdrResolver; + this.validate = validate; + this.resolveDynamicRevisions = resolveDynamicRevisions; + this.confs = confs; + } + + public CacheManager getCache() { + return cache; + } + + public DeliverOptions setCache(CacheManager cache) { + this.cache = cache; + return this; + } + + /** + * Return the pdrResolver that will be used during deliver for each dependency to get its + * published information. This can particularly useful when the deliver is made for a release, + * and when we wish to deliver each dependency which is still in integration. The + * PublishingDependencyRevisionResolver can then do the delivering work for the dependency and + * return the new (delivered) dependency info (with the delivered revision). Note that + * PublishingDependencyRevisionResolver is only called for each direct dependency. + * + * @return the pdrResolver that will be used during deliver + */ + public PublishingDependencyRevisionResolver getPdrResolver() { + return pdrResolver; + } + + /** + * Sets the pdrResolver that will be used during deliver for each dependency to get its + * published information. This can particularly useful when the deliver is made for a release, + * and when we wish to deliver each dependency which is still in integration. The + * PublishingDependencyRevisionResolver can then do the delivering work for the dependency and + * return the new (delivered) dependency info (with the delivered revision). Note that + * PublishingDependencyRevisionResolver is only called for each direct dependency. + * + * @return the instance of DeliverOptions on which the method has been called, for easy method + * chaining + */ + public DeliverOptions setPdrResolver(PublishingDependencyRevisionResolver pdrResolver) { + this.pdrResolver = pdrResolver; + return this; + } + + public boolean isResolveDynamicRevisions() { + return resolveDynamicRevisions; + } + + public DeliverOptions setResolveDynamicRevisions(boolean resolveDynamicRevisions) { + this.resolveDynamicRevisions = resolveDynamicRevisions; + return this; + } + + public boolean isValidate() { + return validate; + } + + public DeliverOptions setValidate(boolean validate) { + this.validate = validate; + return this; + } + + public Date getPubdate() { + return pubdate; + } + + public DeliverOptions setPubdate(Date pubdate) { + this.pubdate = pubdate; + return this; + } + + /** + * Returns the status to which the module should be delivered, or null if the current status + * should be kept. + * + * @return the status to which the module should be delivered + */ + public String getStatus() { + return status; + } + + /** + * Sets the status to which the module should be delivered, use null if the current status + * should be kept. + * + * @return the instance of DeliverOptions on which the method has been called, for easy method + * chaining + */ + public DeliverOptions setStatus(String status) { + this.status = status; + return this; + } + + /** + * Returns the id of a previous resolve to use for delivering. + * + * @return the id of a previous resolve + */ + public String getResolveId() { + return resolveId; + } + + /** + * Sets the id of a previous resolve to use for delivering. + * + * @param resolveId + * the id of a previous resolve + * @return the instance of DeliverOptions on which the method has been called, for easy method + * chaining + */ + public DeliverOptions setResolveId(String resolveId) { + this.resolveId = resolveId; + return this; + } + + /** + * Return the configurations which must be deliverd. Returns null if all + * configurations has to be deliverd. Attention: the returned array can contain wildcards! + * + * @return the configurations to deliver + */ + public String[] getConfs() { + return confs; + } + + /** + * Sets the configurations to deliver. + * + * @param confs + * the configurations to deliver + * @return the instance of DeliverOptions on which the method has been called, for easy method + * chaining + */ + public DeliverOptions setConfs(String[] confs) { + this.confs = confs; + return this; + } + + public String toString() { + return "status=" + status + " pubdate=" + pubdate + " validate=" + validate + + " resolveDynamicRevisions=" + resolveDynamicRevisions + " cache=" + cache + + " resolveId=" + resolveId; + + } + +} diff --git a/src/java/org/apache/ivy/core/deliver/PublishingDependencyRevisionResolver.java b/src/java/org/apache/ivy/core/deliver/PublishingDependencyRevisionResolver.java index 8f7bf892..5a1b6b90 100644 --- a/src/java/org/apache/ivy/core/deliver/PublishingDependencyRevisionResolver.java +++ b/src/java/org/apache/ivy/core/deliver/PublishingDependencyRevisionResolver.java @@ -1,40 +1,40 @@ -/* - * 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.core.deliver; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -/** - * - */ -public interface PublishingDependencyRevisionResolver { - - /** - * Returns the revision of the dependency for the publishing of the 'published' module in - * 'publishedStatus' status. - * - * @param published - * @param publishedStatus - * @param dependency - * @return the revision of the dependency - */ - String resolve(ModuleDescriptor published, String publishedStatus, ModuleRevisionId depMrid, - String status); - -} +/* + * 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.core.deliver; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +/** + * + */ +public interface PublishingDependencyRevisionResolver { + + /** + * Returns the revision of the dependency for the publishing of the 'published' module in + * 'publishedStatus' status. + * + * @param published + * @param publishedStatus + * @param dependency + * @return the revision of the dependency + */ + String resolve(ModuleDescriptor published, String publishedStatus, ModuleRevisionId depMrid, + String status); + +} diff --git a/src/java/org/apache/ivy/core/event/EventManager.java b/src/java/org/apache/ivy/core/event/EventManager.java index 5ddbb8d5..6494ba08 100644 --- a/src/java/org/apache/ivy/core/event/EventManager.java +++ b/src/java/org/apache/ivy/core/event/EventManager.java @@ -1,95 +1,95 @@ -/* - * 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.core.event; - -import java.util.Arrays; - -import javax.swing.event.EventListenerList; - -import org.apache.ivy.plugins.repository.TransferEvent; -import org.apache.ivy.plugins.repository.TransferListener; -import org.apache.ivy.util.filter.Filter; - -public class EventManager implements TransferListener { - - private EventListenerList listeners = new EventListenerList(); - - public void addIvyListener(IvyListener listener) { - listeners.add(IvyListener.class, listener); - } - - public void addIvyListener(IvyListener listener, String eventName) { - addIvyListener(listener, new IvyEventFilter(eventName, null, null)); - } - - public void addIvyListener(IvyListener listener, Filter filter) { - listeners.add(IvyListener.class, new FilteredIvyListener(listener, filter)); - } - - public void removeIvyListener(IvyListener listener) { - listeners.remove(IvyListener.class, listener); - IvyListener[] listeners = (IvyListener[]) this.listeners.getListeners(IvyListener.class); - for (int i = 0; i < listeners.length; i++) { - if (listeners[i] instanceof FilteredIvyListener) { - if (listener.equals(((FilteredIvyListener) listeners[i]).getIvyListener())) { - this.listeners.remove(IvyListener.class, listeners[i]); - } - } - } - } - - public boolean hasIvyListener(IvyListener listener) { - return Arrays.asList(listeners.getListeners(IvyListener.class)).contains(listener); - } - - public void fireIvyEvent(IvyEvent evt) { - Object[] listeners = this.listeners.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == IvyListener.class) { - ((IvyListener) listeners[i + 1]).progress(evt); - } - } - } - - public void addTransferListener(TransferListener listener) { - listeners.add(TransferListener.class, listener); - } - - public void removeTransferListener(TransferListener listener) { - listeners.remove(TransferListener.class, listener); - } - - public boolean hasTransferListener(TransferListener listener) { - return Arrays.asList(listeners.getListeners(TransferListener.class)).contains(listener); - } - - protected void fireTransferEvent(TransferEvent evt) { - Object[] listeners = this.listeners.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == TransferListener.class) { - ((TransferListener) listeners[i + 1]).transferProgress(evt); - } - } - } - - public void transferProgress(TransferEvent evt) { - fireTransferEvent(evt); - fireIvyEvent(evt); - } - -} +/* + * 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.core.event; + +import java.util.Arrays; + +import javax.swing.event.EventListenerList; + +import org.apache.ivy.plugins.repository.TransferEvent; +import org.apache.ivy.plugins.repository.TransferListener; +import org.apache.ivy.util.filter.Filter; + +public class EventManager implements TransferListener { + + private EventListenerList listeners = new EventListenerList(); + + public void addIvyListener(IvyListener listener) { + listeners.add(IvyListener.class, listener); + } + + public void addIvyListener(IvyListener listener, String eventName) { + addIvyListener(listener, new IvyEventFilter(eventName, null, null)); + } + + public void addIvyListener(IvyListener listener, Filter filter) { + listeners.add(IvyListener.class, new FilteredIvyListener(listener, filter)); + } + + public void removeIvyListener(IvyListener listener) { + listeners.remove(IvyListener.class, listener); + IvyListener[] listeners = (IvyListener[]) this.listeners.getListeners(IvyListener.class); + for (int i = 0; i < listeners.length; i++) { + if (listeners[i] instanceof FilteredIvyListener) { + if (listener.equals(((FilteredIvyListener) listeners[i]).getIvyListener())) { + this.listeners.remove(IvyListener.class, listeners[i]); + } + } + } + } + + public boolean hasIvyListener(IvyListener listener) { + return Arrays.asList(listeners.getListeners(IvyListener.class)).contains(listener); + } + + public void fireIvyEvent(IvyEvent evt) { + Object[] listeners = this.listeners.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == IvyListener.class) { + ((IvyListener) listeners[i + 1]).progress(evt); + } + } + } + + public void addTransferListener(TransferListener listener) { + listeners.add(TransferListener.class, listener); + } + + public void removeTransferListener(TransferListener listener) { + listeners.remove(TransferListener.class, listener); + } + + public boolean hasTransferListener(TransferListener listener) { + return Arrays.asList(listeners.getListeners(TransferListener.class)).contains(listener); + } + + protected void fireTransferEvent(TransferEvent evt) { + Object[] listeners = this.listeners.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == TransferListener.class) { + ((TransferListener) listeners[i + 1]).transferProgress(evt); + } + } + } + + public void transferProgress(TransferEvent evt) { + fireTransferEvent(evt); + fireIvyEvent(evt); + } + +} diff --git a/src/java/org/apache/ivy/core/event/FilteredIvyListener.java b/src/java/org/apache/ivy/core/event/FilteredIvyListener.java index 0a4dbdd2..e52512d8 100644 --- a/src/java/org/apache/ivy/core/event/FilteredIvyListener.java +++ b/src/java/org/apache/ivy/core/event/FilteredIvyListener.java @@ -1,46 +1,46 @@ -/* - * 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.core.event; - -import org.apache.ivy.util.filter.Filter; - -public class FilteredIvyListener implements IvyListener { - private IvyListener listener; - - private Filter filter; - - public FilteredIvyListener(IvyListener listener, Filter filter) { - this.listener = listener; - this.filter = filter; - } - - public IvyListener getIvyListener() { - return listener; - } - - public Filter getFilter() { - return filter; - } - - public void progress(IvyEvent event) { - if (filter.accept(event)) { - listener.progress(event); - } - } - -} +/* + * 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.core.event; + +import org.apache.ivy.util.filter.Filter; + +public class FilteredIvyListener implements IvyListener { + private IvyListener listener; + + private Filter filter; + + public FilteredIvyListener(IvyListener listener, Filter filter) { + this.listener = listener; + this.filter = filter; + } + + public IvyListener getIvyListener() { + return listener; + } + + public Filter getFilter() { + return filter; + } + + public void progress(IvyEvent event) { + if (filter.accept(event)) { + listener.progress(event); + } + } + +} diff --git a/src/java/org/apache/ivy/core/event/IvyEvent.java b/src/java/org/apache/ivy/core/event/IvyEvent.java index e32d084d..a0c226bf 100644 --- a/src/java/org/apache/ivy/core/event/IvyEvent.java +++ b/src/java/org/apache/ivy/core/event/IvyEvent.java @@ -1,123 +1,123 @@ -/* - * 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.core.event; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.util.StringUtils; - -/** - * The root of all ivy events Any ivy event knows which ivy instance triggered the event (the - * source) and also has a name and a map of attributes. The name of the event represents the event - * type, usually there is a one - one mapping between event names and IvyEvent subclass, even if - * this is not mandatory. Example: pre-resolve pre-resolve-dependency post-download The map of - * attributes is a Map from String keys to String values. It is especially useful to filter events, - * and to get some of their essential data in some context where access to Java types is not easy - * (in an ant build file, for example), Example: pre-resolve (organisation=foo, module=bar, - * revision=1.0, conf=default) post-download (organisation=foo, module=bar, revision=1.0, - * artifact=foo-test, type=jar, ext=jar) - */ -public class IvyEvent { - private EventManager source; - - private String name; - - private Map attributes = new HashMap(); - - protected IvyEvent(String name) { - this.source = IvyContext.getContext().getEventManager(); - this.name = name; - } - - /** - * Should only be called during event object construction, since events should be immutable - * - * @param key - * @param value - */ - protected void addAttribute(String key, String value) { - attributes.put(key, value); - } - - protected void addMDAttributes(ModuleDescriptor md) { - addMridAttributes(md.getResolvedModuleRevisionId()); - } - - protected void addMridAttributes(ModuleRevisionId mrid) { - addModuleIdAttributes(mrid.getModuleId()); - addAttribute("revision", mrid.getRevision()); - addAttributes(mrid.getExtraAttributes()); - } - - protected void addModuleIdAttributes(ModuleId moduleId) { - addAttribute("organisation", moduleId.getOrganisation()); - addAttribute("module", moduleId.getName()); - } - - protected void addConfsAttribute(String[] confs) { - addAttribute("conf", StringUtils.join(confs, ", ")); - } - - protected void addAttributes(Map attributes) { - this.attributes.putAll(attributes); - } - - public EventManager getSource() { - return source; - } - - public String getName() { - return name; - } - - /** - * Returns the attributes of this event, as a Map(String->String) - * - * @return the attributes of this event, as a Map(String->String) - */ - public Map getAttributes() { - return new HashMap(attributes); - } - - public String toString() { - return getName() + " " + getAttributes(); - } - - public boolean equals(Object obj) { - if (!(obj instanceof IvyEvent)) { - return false; - } - IvyEvent e = (IvyEvent) obj; - - return getSource().equals(e.getSource()) && getName().equals(e.getName()) - && attributes.equals(e.attributes); - } - - public int hashCode() { - int hash = 37; - hash = 13 * hash + getSource().hashCode(); - hash = 13 * hash + getName().hashCode(); - hash = 13 * hash + attributes.hashCode(); - return hash; - } -} +/* + * 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.core.event; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.util.StringUtils; + +/** + * The root of all ivy events Any ivy event knows which ivy instance triggered the event (the + * source) and also has a name and a map of attributes. The name of the event represents the event + * type, usually there is a one - one mapping between event names and IvyEvent subclass, even if + * this is not mandatory. Example: pre-resolve pre-resolve-dependency post-download The map of + * attributes is a Map from String keys to String values. It is especially useful to filter events, + * and to get some of their essential data in some context where access to Java types is not easy + * (in an ant build file, for example), Example: pre-resolve (organisation=foo, module=bar, + * revision=1.0, conf=default) post-download (organisation=foo, module=bar, revision=1.0, + * artifact=foo-test, type=jar, ext=jar) + */ +public class IvyEvent { + private EventManager source; + + private String name; + + private Map attributes = new HashMap(); + + protected IvyEvent(String name) { + this.source = IvyContext.getContext().getEventManager(); + this.name = name; + } + + /** + * Should only be called during event object construction, since events should be immutable + * + * @param key + * @param value + */ + protected void addAttribute(String key, String value) { + attributes.put(key, value); + } + + protected void addMDAttributes(ModuleDescriptor md) { + addMridAttributes(md.getResolvedModuleRevisionId()); + } + + protected void addMridAttributes(ModuleRevisionId mrid) { + addModuleIdAttributes(mrid.getModuleId()); + addAttribute("revision", mrid.getRevision()); + addAttributes(mrid.getExtraAttributes()); + } + + protected void addModuleIdAttributes(ModuleId moduleId) { + addAttribute("organisation", moduleId.getOrganisation()); + addAttribute("module", moduleId.getName()); + } + + protected void addConfsAttribute(String[] confs) { + addAttribute("conf", StringUtils.join(confs, ", ")); + } + + protected void addAttributes(Map attributes) { + this.attributes.putAll(attributes); + } + + public EventManager getSource() { + return source; + } + + public String getName() { + return name; + } + + /** + * Returns the attributes of this event, as a Map(String->String) + * + * @return the attributes of this event, as a Map(String->String) + */ + public Map getAttributes() { + return new HashMap(attributes); + } + + public String toString() { + return getName() + " " + getAttributes(); + } + + public boolean equals(Object obj) { + if (!(obj instanceof IvyEvent)) { + return false; + } + IvyEvent e = (IvyEvent) obj; + + return getSource().equals(e.getSource()) && getName().equals(e.getName()) + && attributes.equals(e.attributes); + } + + public int hashCode() { + int hash = 37; + hash = 13 * hash + getSource().hashCode(); + hash = 13 * hash + getName().hashCode(); + hash = 13 * hash + attributes.hashCode(); + return hash; + } +} diff --git a/src/java/org/apache/ivy/core/event/IvyEventFilter.java b/src/java/org/apache/ivy/core/event/IvyEventFilter.java index 0445c0c9..57a12ec1 100644 --- a/src/java/org/apache/ivy/core/event/IvyEventFilter.java +++ b/src/java/org/apache/ivy/core/event/IvyEventFilter.java @@ -1,157 +1,157 @@ -/* - * 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.core.event; - -import org.apache.ivy.plugins.matcher.ExactPatternMatcher; -import org.apache.ivy.plugins.matcher.Matcher; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.util.filter.AndFilter; -import org.apache.ivy.util.filter.Filter; -import org.apache.ivy.util.filter.NoFilter; -import org.apache.ivy.util.filter.NotFilter; -import org.apache.ivy.util.filter.OrFilter; - -/** - * A filter implementation filtering {@link IvyEvent} based upon an event name and a filter - * expression. The name will be matched against the event name using the {@link PatternMatcher} used - * to construct this object. The filter expression is a string describing how the event should be - * filtered according to its attributes values. The matching between the filter values and the event - * attribute values is done using the {@link PatternMatcher} used to construct this object. Here are - * some examples: - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
      expressioneffect
      type=zipaccepts event with a type attribute matching zip
      type=zip,jaraccepts event with a type attribute matching zip or jar
      type=src AND ext=zipaccepts event with a type attribute matching src AND an ext attribute matching zip
      type=src OR ext=zipaccepts event with a type attribute matching src OR an ext attribute matching zip
      NOT type=srcaccepts event with a type attribute NOT matching src
      Combination of these can be used, but no parentheses are supported right now, so only - * the default priority can be used. The priority order is this one: AND OR NOT = This means that - * artifact=foo AND ext=zip OR type=src will match event with artifact matching foo AND (ext - * matching zip OR type matching src) - * - * @since 1.4 - */ -public class IvyEventFilter implements Filter { - private static final String NOT = "NOT "; - - private static final String OR = " OR "; - - private static final String AND = " AND "; - - private PatternMatcher matcher; - - private Filter nameFilter; - - private Filter attFilter; - - public IvyEventFilter(String event, String filterExpression, PatternMatcher matcher) { - this.matcher = matcher == null ? ExactPatternMatcher.INSTANCE : matcher; - if (event == null) { - nameFilter = NoFilter.INSTANCE; - } else { - final Matcher eventNameMatcher = this.matcher.getMatcher(event); - nameFilter = new Filter() { - public boolean accept(Object o) { - IvyEvent e = (IvyEvent) o; - return eventNameMatcher.matches(e.getName()); - } - }; - } - attFilter = filterExpression == null || filterExpression.trim().length() == 0 ? NoFilter.INSTANCE - : parseExpression(filterExpression); - } - - private Filter parseExpression(String filterExpression) { - // expressions handled for the moment: (informal grammar) - // EXP := SIMPLE_EXP | AND_EXP | OR_EXP | NOT_EXP - // AND_EXP := EXP && EXP - // OR_EXP := EXP || EXP - // NOT_EXP := ! EXP - // SIMPLE_EXP := attname = comma, separated, list, of, accepted, values - // example: organisation = foo && module = bar, baz - filterExpression = filterExpression.trim(); - int index = filterExpression.indexOf(AND); - if (index == -1) { - index = filterExpression.indexOf(OR); - if (index == -1) { - if (filterExpression.startsWith(NOT)) { - return new NotFilter(parseExpression(filterExpression.substring(NOT.length()))); - } else { - index = filterExpression.indexOf("="); - if (index == -1) { - throw new IllegalArgumentException("bad filter expression: " - + filterExpression + ": no equal sign found"); - } - final String attname = filterExpression.substring(0, index).trim(); - String[] values = filterExpression.substring(index + 1).trim().split(","); - final Matcher[] matchers = new Matcher[values.length]; - for (int i = 0; i < values.length; i++) { - matchers[i] = matcher.getMatcher(values[i].trim()); - } - return new Filter() { - public boolean accept(Object o) { - IvyEvent e = (IvyEvent) o; - String val = (String) e.getAttributes().get(attname); - if (val == null) { - return false; - } - for (int i = 0; i < matchers.length; i++) { - if (matchers[i].matches(val)) { - return true; - } - } - return false; - } - }; - } - } else { - return new OrFilter(parseExpression(filterExpression.substring(0, index)), - parseExpression(filterExpression.substring(index + OR.length()))); - } - } else { - return new AndFilter(parseExpression(filterExpression.substring(0, index)), - parseExpression(filterExpression.substring(index + AND.length()))); - } - } - - public boolean accept(Object o) { - if (!(o instanceof IvyEvent)) { - return false; - } - return nameFilter.accept(o) && attFilter.accept(o); - } - -} +/* + * 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.core.event; + +import org.apache.ivy.plugins.matcher.ExactPatternMatcher; +import org.apache.ivy.plugins.matcher.Matcher; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.util.filter.AndFilter; +import org.apache.ivy.util.filter.Filter; +import org.apache.ivy.util.filter.NoFilter; +import org.apache.ivy.util.filter.NotFilter; +import org.apache.ivy.util.filter.OrFilter; + +/** + * A filter implementation filtering {@link IvyEvent} based upon an event name and a filter + * expression. The name will be matched against the event name using the {@link PatternMatcher} used + * to construct this object. The filter expression is a string describing how the event should be + * filtered according to its attributes values. The matching between the filter values and the event + * attribute values is done using the {@link PatternMatcher} used to construct this object. Here are + * some examples: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
      expressioneffect
      type=zipaccepts event with a type attribute matching zip
      type=zip,jaraccepts event with a type attribute matching zip or jar
      type=src AND ext=zipaccepts event with a type attribute matching src AND an ext attribute matching zip
      type=src OR ext=zipaccepts event with a type attribute matching src OR an ext attribute matching zip
      NOT type=srcaccepts event with a type attribute NOT matching src
      Combination of these can be used, but no parentheses are supported right now, so only + * the default priority can be used. The priority order is this one: AND OR NOT = This means that + * artifact=foo AND ext=zip OR type=src will match event with artifact matching foo AND (ext + * matching zip OR type matching src) + * + * @since 1.4 + */ +public class IvyEventFilter implements Filter { + private static final String NOT = "NOT "; + + private static final String OR = " OR "; + + private static final String AND = " AND "; + + private PatternMatcher matcher; + + private Filter nameFilter; + + private Filter attFilter; + + public IvyEventFilter(String event, String filterExpression, PatternMatcher matcher) { + this.matcher = matcher == null ? ExactPatternMatcher.INSTANCE : matcher; + if (event == null) { + nameFilter = NoFilter.INSTANCE; + } else { + final Matcher eventNameMatcher = this.matcher.getMatcher(event); + nameFilter = new Filter() { + public boolean accept(Object o) { + IvyEvent e = (IvyEvent) o; + return eventNameMatcher.matches(e.getName()); + } + }; + } + attFilter = filterExpression == null || filterExpression.trim().length() == 0 ? NoFilter.INSTANCE + : parseExpression(filterExpression); + } + + private Filter parseExpression(String filterExpression) { + // expressions handled for the moment: (informal grammar) + // EXP := SIMPLE_EXP | AND_EXP | OR_EXP | NOT_EXP + // AND_EXP := EXP && EXP + // OR_EXP := EXP || EXP + // NOT_EXP := ! EXP + // SIMPLE_EXP := attname = comma, separated, list, of, accepted, values + // example: organisation = foo && module = bar, baz + filterExpression = filterExpression.trim(); + int index = filterExpression.indexOf(AND); + if (index == -1) { + index = filterExpression.indexOf(OR); + if (index == -1) { + if (filterExpression.startsWith(NOT)) { + return new NotFilter(parseExpression(filterExpression.substring(NOT.length()))); + } else { + index = filterExpression.indexOf("="); + if (index == -1) { + throw new IllegalArgumentException("bad filter expression: " + + filterExpression + ": no equal sign found"); + } + final String attname = filterExpression.substring(0, index).trim(); + String[] values = filterExpression.substring(index + 1).trim().split(","); + final Matcher[] matchers = new Matcher[values.length]; + for (int i = 0; i < values.length; i++) { + matchers[i] = matcher.getMatcher(values[i].trim()); + } + return new Filter() { + public boolean accept(Object o) { + IvyEvent e = (IvyEvent) o; + String val = (String) e.getAttributes().get(attname); + if (val == null) { + return false; + } + for (int i = 0; i < matchers.length; i++) { + if (matchers[i].matches(val)) { + return true; + } + } + return false; + } + }; + } + } else { + return new OrFilter(parseExpression(filterExpression.substring(0, index)), + parseExpression(filterExpression.substring(index + OR.length()))); + } + } else { + return new AndFilter(parseExpression(filterExpression.substring(0, index)), + parseExpression(filterExpression.substring(index + AND.length()))); + } + } + + public boolean accept(Object o) { + if (!(o instanceof IvyEvent)) { + return false; + } + return nameFilter.accept(o) && attFilter.accept(o); + } + +} diff --git a/src/java/org/apache/ivy/core/event/IvyListener.java b/src/java/org/apache/ivy/core/event/IvyListener.java index 5743e544..881b3cdd 100644 --- a/src/java/org/apache/ivy/core/event/IvyListener.java +++ b/src/java/org/apache/ivy/core/event/IvyListener.java @@ -1,24 +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. - * - */ -package org.apache.ivy.core.event; - -import java.util.EventListener; - -public interface IvyListener extends EventListener { - public void progress(IvyEvent event); -} +/* + * 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.core.event; + +import java.util.EventListener; + +public interface IvyListener extends EventListener { + public void progress(IvyEvent event); +} diff --git a/src/java/org/apache/ivy/core/event/download/DownloadEvent.java b/src/java/org/apache/ivy/core/event/download/DownloadEvent.java index 5c99742e..ef670d3d 100644 --- a/src/java/org/apache/ivy/core/event/download/DownloadEvent.java +++ b/src/java/org/apache/ivy/core/event/download/DownloadEvent.java @@ -1,41 +1,41 @@ -/* - * 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.core.event.download; - -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.core.module.descriptor.Artifact; - -public abstract class DownloadEvent extends IvyEvent { - private Artifact artifact; - - public DownloadEvent(String name, Artifact artifact) { - super(name); - this.artifact = artifact; - addArtifactAttributes(this.artifact); - } - - protected void addArtifactAttributes(Artifact artifact) { - addMridAttributes(artifact.getModuleRevisionId()); - addAttributes(artifact.getAttributes()); - } - - public Artifact getArtifact() { - return artifact; - } - -} +/* + * 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.core.event.download; + +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.core.module.descriptor.Artifact; + +public abstract class DownloadEvent extends IvyEvent { + private Artifact artifact; + + public DownloadEvent(String name, Artifact artifact) { + super(name); + this.artifact = artifact; + addArtifactAttributes(this.artifact); + } + + protected void addArtifactAttributes(Artifact artifact) { + addMridAttributes(artifact.getModuleRevisionId()); + addAttributes(artifact.getAttributes()); + } + + public Artifact getArtifact() { + return artifact; + } + +} diff --git a/src/java/org/apache/ivy/core/event/download/EndArtifactDownloadEvent.java b/src/java/org/apache/ivy/core/event/download/EndArtifactDownloadEvent.java index 78d02d68..d8169638 100644 --- a/src/java/org/apache/ivy/core/event/download/EndArtifactDownloadEvent.java +++ b/src/java/org/apache/ivy/core/event/download/EndArtifactDownloadEvent.java @@ -1,61 +1,61 @@ -/* - * 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.core.event.download; - -import java.io.File; - -import org.apache.ivy.core.cache.ArtifactOrigin; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class EndArtifactDownloadEvent extends DownloadEvent { - public static final String NAME = "post-download-artifact"; - - private DependencyResolver resolver; - - private ArtifactDownloadReport report; - - public EndArtifactDownloadEvent(DependencyResolver resolver, Artifact artifact, - ArtifactDownloadReport report, File dest) { - super(NAME, artifact); - this.resolver = resolver; - this.report = report; - addAttribute("resolver", this.resolver.getName()); - addAttribute("status", this.report.getDownloadStatus().toString()); - addAttribute("size", String.valueOf(this.report.getSize())); - addAttribute("file", dest.getAbsolutePath()); - ArtifactOrigin origin = report.getArtifactOrigin(); - if (origin != null) { - addAttribute("origin", this.report.getArtifactOrigin().getLocation()); - addAttribute("local", String.valueOf(this.report.getArtifactOrigin().isLocal())); - } else { - addAttribute("origin", ""); - addAttribute("local", ""); - } - } - - public ArtifactDownloadReport getReport() { - return report; - } - - public DependencyResolver getResolver() { - return resolver; - } - -} +/* + * 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.core.event.download; + +import java.io.File; + +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class EndArtifactDownloadEvent extends DownloadEvent { + public static final String NAME = "post-download-artifact"; + + private DependencyResolver resolver; + + private ArtifactDownloadReport report; + + public EndArtifactDownloadEvent(DependencyResolver resolver, Artifact artifact, + ArtifactDownloadReport report, File dest) { + super(NAME, artifact); + this.resolver = resolver; + this.report = report; + addAttribute("resolver", this.resolver.getName()); + addAttribute("status", this.report.getDownloadStatus().toString()); + addAttribute("size", String.valueOf(this.report.getSize())); + addAttribute("file", dest.getAbsolutePath()); + ArtifactOrigin origin = report.getArtifactOrigin(); + if (origin != null) { + addAttribute("origin", this.report.getArtifactOrigin().getLocation()); + addAttribute("local", String.valueOf(this.report.getArtifactOrigin().isLocal())); + } else { + addAttribute("origin", ""); + addAttribute("local", ""); + } + } + + public ArtifactDownloadReport getReport() { + return report; + } + + public DependencyResolver getResolver() { + return resolver; + } + +} diff --git a/src/java/org/apache/ivy/core/event/download/NeedArtifactEvent.java b/src/java/org/apache/ivy/core/event/download/NeedArtifactEvent.java index db46790e..a1a9f2e0 100644 --- a/src/java/org/apache/ivy/core/event/download/NeedArtifactEvent.java +++ b/src/java/org/apache/ivy/core/event/download/NeedArtifactEvent.java @@ -1,38 +1,38 @@ -/* - * 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.core.event.download; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class NeedArtifactEvent extends DownloadEvent { - public static final String NAME = "need-artifact"; - - private DependencyResolver resolver; - - public NeedArtifactEvent(DependencyResolver resolver, Artifact artifact) { - super(NAME, artifact); - this.resolver = resolver; - addAttribute("resolver", this.resolver.getName()); - } - - public DependencyResolver getResolver() { - return resolver; - } - -} +/* + * 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.core.event.download; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class NeedArtifactEvent extends DownloadEvent { + public static final String NAME = "need-artifact"; + + private DependencyResolver resolver; + + public NeedArtifactEvent(DependencyResolver resolver, Artifact artifact) { + super(NAME, artifact); + this.resolver = resolver; + addAttribute("resolver", this.resolver.getName()); + } + + public DependencyResolver getResolver() { + return resolver; + } + +} diff --git a/src/java/org/apache/ivy/core/event/download/PrepareDownloadEvent.java b/src/java/org/apache/ivy/core/event/download/PrepareDownloadEvent.java index 12b493d0..a5df433f 100644 --- a/src/java/org/apache/ivy/core/event/download/PrepareDownloadEvent.java +++ b/src/java/org/apache/ivy/core/event/download/PrepareDownloadEvent.java @@ -1,36 +1,36 @@ -/* - * 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.core.event.download; - -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.core.module.descriptor.Artifact; - -public class PrepareDownloadEvent extends IvyEvent { - public static final String NAME = "prepare-download"; - - private Artifact[] artifacts; - - public PrepareDownloadEvent(Artifact[] artifacts) { - super(NAME); - this.artifacts = artifacts; - } - - public Artifact[] getArtifacts() { - return artifacts; - } -} +/* + * 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.core.event.download; + +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.core.module.descriptor.Artifact; + +public class PrepareDownloadEvent extends IvyEvent { + public static final String NAME = "prepare-download"; + + private Artifact[] artifacts; + + public PrepareDownloadEvent(Artifact[] artifacts) { + super(NAME); + this.artifacts = artifacts; + } + + public Artifact[] getArtifacts() { + return artifacts; + } +} diff --git a/src/java/org/apache/ivy/core/event/download/StartArtifactDownloadEvent.java b/src/java/org/apache/ivy/core/event/download/StartArtifactDownloadEvent.java index b42d8c82..a30d67c9 100644 --- a/src/java/org/apache/ivy/core/event/download/StartArtifactDownloadEvent.java +++ b/src/java/org/apache/ivy/core/event/download/StartArtifactDownloadEvent.java @@ -1,49 +1,49 @@ -/* - * 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.core.event.download; - -import org.apache.ivy.core.cache.ArtifactOrigin; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class StartArtifactDownloadEvent extends DownloadEvent { - public static final String NAME = "pre-download-artifact"; - - private DependencyResolver resolver; - - private ArtifactOrigin origin; - - public StartArtifactDownloadEvent(DependencyResolver resolver, Artifact artifact, - ArtifactOrigin origin) { - super(NAME, artifact); - this.resolver = resolver; - this.origin = origin; - addAttribute("resolver", this.resolver.getName()); - addAttribute("origin", origin.getLocation()); - addAttribute("local", String.valueOf(origin.isLocal())); - } - - public DependencyResolver getResolver() { - return resolver; - } - - public ArtifactOrigin getOrigin() { - return origin; - } - -} +/* + * 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.core.event.download; + +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class StartArtifactDownloadEvent extends DownloadEvent { + public static final String NAME = "pre-download-artifact"; + + private DependencyResolver resolver; + + private ArtifactOrigin origin; + + public StartArtifactDownloadEvent(DependencyResolver resolver, Artifact artifact, + ArtifactOrigin origin) { + super(NAME, artifact); + this.resolver = resolver; + this.origin = origin; + addAttribute("resolver", this.resolver.getName()); + addAttribute("origin", origin.getLocation()); + addAttribute("local", String.valueOf(origin.isLocal())); + } + + public DependencyResolver getResolver() { + return resolver; + } + + public ArtifactOrigin getOrigin() { + return origin; + } + +} diff --git a/src/java/org/apache/ivy/core/event/resolve/EndResolveDependencyEvent.java b/src/java/org/apache/ivy/core/event/resolve/EndResolveDependencyEvent.java index dff17d9a..cb33a23c 100644 --- a/src/java/org/apache/ivy/core/event/resolve/EndResolveDependencyEvent.java +++ b/src/java/org/apache/ivy/core/event/resolve/EndResolveDependencyEvent.java @@ -1,47 +1,47 @@ -/* - * 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.core.event.resolve; - -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class EndResolveDependencyEvent extends ResolveDependencyEvent { - public static final String NAME = "post-resolve-dependency"; - - private ResolvedModuleRevision module; - - public EndResolveDependencyEvent(DependencyResolver resolver, DependencyDescriptor dd, - ResolvedModuleRevision module) { - super(NAME, resolver, dd); - this.module = module; - if (this.module != null) { - // override revision from the dependency descriptor - addAttribute("revision", this.module.getDescriptor().getResolvedModuleRevisionId() - .getRevision()); - addAttribute("resolved", "true"); - } else { - addAttribute("resolved", "false"); - } - } - - public ResolvedModuleRevision getModule() { - return module; - } - -} +/* + * 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.core.event.resolve; + +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class EndResolveDependencyEvent extends ResolveDependencyEvent { + public static final String NAME = "post-resolve-dependency"; + + private ResolvedModuleRevision module; + + public EndResolveDependencyEvent(DependencyResolver resolver, DependencyDescriptor dd, + ResolvedModuleRevision module) { + super(NAME, resolver, dd); + this.module = module; + if (this.module != null) { + // override revision from the dependency descriptor + addAttribute("revision", this.module.getDescriptor().getResolvedModuleRevisionId() + .getRevision()); + addAttribute("resolved", "true"); + } else { + addAttribute("resolved", "false"); + } + } + + public ResolvedModuleRevision getModule() { + return module; + } + +} diff --git a/src/java/org/apache/ivy/core/event/resolve/EndResolveEvent.java b/src/java/org/apache/ivy/core/event/resolve/EndResolveEvent.java index bb634252..b5c2b627 100644 --- a/src/java/org/apache/ivy/core/event/resolve/EndResolveEvent.java +++ b/src/java/org/apache/ivy/core/event/resolve/EndResolveEvent.java @@ -1,37 +1,37 @@ -/* - * 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.core.event.resolve; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.report.ResolveReport; - -public class EndResolveEvent extends ResolveEvent { - public static final String NAME = "post-resolve"; - - private ResolveReport report; - - public EndResolveEvent(ModuleDescriptor md, String[] confs, ResolveReport report) { - super(NAME, md, confs); - this.report = report; - } - - public ResolveReport getReport() { - return report; - } - -} +/* + * 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.core.event.resolve; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.report.ResolveReport; + +public class EndResolveEvent extends ResolveEvent { + public static final String NAME = "post-resolve"; + + private ResolveReport report; + + public EndResolveEvent(ModuleDescriptor md, String[] confs, ResolveReport report) { + super(NAME, md, confs); + this.report = report; + } + + public ResolveReport getReport() { + return report; + } + +} diff --git a/src/java/org/apache/ivy/core/event/resolve/ResolveDependencyEvent.java b/src/java/org/apache/ivy/core/event/resolve/ResolveDependencyEvent.java index ace29326..29a73385 100644 --- a/src/java/org/apache/ivy/core/event/resolve/ResolveDependencyEvent.java +++ b/src/java/org/apache/ivy/core/event/resolve/ResolveDependencyEvent.java @@ -1,47 +1,47 @@ -/* - * 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.core.event.resolve; - -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class ResolveDependencyEvent extends IvyEvent { - private DependencyResolver resolver; - - private DependencyDescriptor dd; - - protected ResolveDependencyEvent(String name, DependencyResolver resolver, - DependencyDescriptor dd) { - super(name); - this.resolver = resolver; - this.dd = dd; - addAttribute("resolver", this.resolver.getName()); - addMridAttributes(this.dd.getDependencyRevisionId()); - addAttributes(this.dd.getExtraAttributes()); - } - - public DependencyDescriptor getDependencyDescriptor() { - return dd; - } - - public DependencyResolver getResolver() { - return resolver; - } - -} +/* + * 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.core.event.resolve; + +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class ResolveDependencyEvent extends IvyEvent { + private DependencyResolver resolver; + + private DependencyDescriptor dd; + + protected ResolveDependencyEvent(String name, DependencyResolver resolver, + DependencyDescriptor dd) { + super(name); + this.resolver = resolver; + this.dd = dd; + addAttribute("resolver", this.resolver.getName()); + addMridAttributes(this.dd.getDependencyRevisionId()); + addAttributes(this.dd.getExtraAttributes()); + } + + public DependencyDescriptor getDependencyDescriptor() { + return dd; + } + + public DependencyResolver getResolver() { + return resolver; + } + +} diff --git a/src/java/org/apache/ivy/core/event/resolve/ResolveEvent.java b/src/java/org/apache/ivy/core/event/resolve/ResolveEvent.java index dd1efb77..a06b0586 100644 --- a/src/java/org/apache/ivy/core/event/resolve/ResolveEvent.java +++ b/src/java/org/apache/ivy/core/event/resolve/ResolveEvent.java @@ -1,39 +1,39 @@ -/* - * 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.core.event.resolve; - -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; - -public class ResolveEvent extends IvyEvent { - private ModuleDescriptor md; - - private String[] confs; - - protected ResolveEvent(String name, ModuleDescriptor md, String[] confs) { - super(name); - this.md = md; - this.confs = confs; - addMDAttributes(md); - addConfsAttribute(confs); - } - - public ModuleDescriptor getModuleDescriptor() { - return md; - } -} +/* + * 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.core.event.resolve; + +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; + +public class ResolveEvent extends IvyEvent { + private ModuleDescriptor md; + + private String[] confs; + + protected ResolveEvent(String name, ModuleDescriptor md, String[] confs) { + super(name); + this.md = md; + this.confs = confs; + addMDAttributes(md); + addConfsAttribute(confs); + } + + public ModuleDescriptor getModuleDescriptor() { + return md; + } +} diff --git a/src/java/org/apache/ivy/core/event/resolve/StartResolveDependencyEvent.java b/src/java/org/apache/ivy/core/event/resolve/StartResolveDependencyEvent.java index b4f3cd21..9f2a9899 100644 --- a/src/java/org/apache/ivy/core/event/resolve/StartResolveDependencyEvent.java +++ b/src/java/org/apache/ivy/core/event/resolve/StartResolveDependencyEvent.java @@ -1,30 +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. - * - */ -package org.apache.ivy.core.event.resolve; - -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class StartResolveDependencyEvent extends ResolveDependencyEvent { - public static final String NAME = "pre-resolve-dependency"; - - public StartResolveDependencyEvent(DependencyResolver resolver, DependencyDescriptor dd) { - super(NAME, resolver, dd); - } - -} +/* + * 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.core.event.resolve; + +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class StartResolveDependencyEvent extends ResolveDependencyEvent { + public static final String NAME = "pre-resolve-dependency"; + + public StartResolveDependencyEvent(DependencyResolver resolver, DependencyDescriptor dd) { + super(NAME, resolver, dd); + } + +} diff --git a/src/java/org/apache/ivy/core/event/resolve/StartResolveEvent.java b/src/java/org/apache/ivy/core/event/resolve/StartResolveEvent.java index cbcc5a09..687ef73f 100644 --- a/src/java/org/apache/ivy/core/event/resolve/StartResolveEvent.java +++ b/src/java/org/apache/ivy/core/event/resolve/StartResolveEvent.java @@ -1,29 +1,29 @@ -/* - * 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.core.event.resolve; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; - -public class StartResolveEvent extends ResolveEvent { - public static final String NAME = "pre-resolve"; - - public StartResolveEvent(ModuleDescriptor md, String[] confs) { - super(NAME, md, confs); - } - -} +/* + * 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.core.event.resolve; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; + +public class StartResolveEvent extends ResolveEvent { + public static final String NAME = "pre-resolve"; + + public StartResolveEvent(ModuleDescriptor md, String[] confs) { + super(NAME, md, confs); + } + +} diff --git a/src/java/org/apache/ivy/core/install/InstallEngine.java b/src/java/org/apache/ivy/core/install/InstallEngine.java index cf9452b4..e941bf17 100644 --- a/src/java/org/apache/ivy/core/install/InstallEngine.java +++ b/src/java/org/apache/ivy/core/install/InstallEngine.java @@ -1,173 +1,173 @@ -/* - * 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.core.install; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.publish.PublishEngine; -import org.apache.ivy.core.publish.PublishOptions; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveEngine; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.search.SearchEngine; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.conflict.NoConflictManager; -import org.apache.ivy.plugins.matcher.ExactPatternMatcher; -import org.apache.ivy.plugins.matcher.MatcherHelper; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.filter.Filter; -import org.apache.ivy.util.filter.FilterHelper; - -public class InstallEngine { - private IvySettings settings; - - private ResolveEngine resolveEngine; - - private PublishEngine publishEngine; - - private SearchEngine searchEngine; - - public InstallEngine(IvySettings settings, SearchEngine searchEngine, - ResolveEngine resolveEngine, PublishEngine publishEngine) { - this.settings = settings; - this.searchEngine = searchEngine; - this.resolveEngine = resolveEngine; - this.publishEngine = publishEngine; - } - - public ResolveReport install(ModuleRevisionId mrid, String from, String to, boolean transitive, - boolean validate, boolean overwrite, Filter artifactFilter, File cache, - String matcherName) throws IOException { - if (cache == null) { - cache = settings.getDefaultCache(); - } - if (artifactFilter == null) { - artifactFilter = FilterHelper.NO_FILTER; - } - DependencyResolver fromResolver = settings.getResolver(from); - DependencyResolver toResolver = settings.getResolver(to); - if (fromResolver == null) { - throw new IllegalArgumentException("unknown resolver " + from - + ". Available resolvers are: " + settings.getResolverNames()); - } - if (toResolver == null) { - throw new IllegalArgumentException("unknown resolver " + to - + ". Available resolvers are: " + settings.getResolverNames()); - } - PatternMatcher matcher = settings.getMatcher(matcherName); - if (matcher == null) { - throw new IllegalArgumentException("unknown matcher " + matcherName - + ". Available matchers are: " + settings.getMatcherNames()); - } - - // build module file declaring the dependency - Message.info(":: installing " + mrid + " ::"); - DependencyResolver oldDicator = resolveEngine.getDictatorResolver(); - boolean log = settings.logNotConvertedExclusionRule(); - try { - settings.setLogNotConvertedExclusionRule(true); - resolveEngine.setDictatorResolver(fromResolver); - - DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance( - "apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), - new Date()); - String resolveId = ResolveOptions.getDefaultResolveId(md); - md.addConfiguration(new Configuration("default")); - md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, - ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, - new NoConflictManager()); - - if (MatcherHelper.isExact(matcher, mrid)) { - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, - false, transitive); - dd.addDependencyConfiguration("default", "*"); - md.addDependency(dd); - } else { - Collection mrids = searchEngine.findModuleRevisionIds(fromResolver, mrid, matcher); - - for (Iterator iter = mrids.iterator(); iter.hasNext();) { - ModuleRevisionId foundMrid = (ModuleRevisionId) iter.next(); - Message.info("\tfound " + foundMrid + " to install: adding to the list"); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, foundMrid, - false, false, transitive); - dd.addDependencyConfiguration("default", "*"); - md.addDependency(dd); - } - } - - // resolve using appropriate resolver - ResolveReport report = new ResolveReport(md, resolveId); - - Message.info(":: resolving dependencies ::"); - IvyNode[] dependencies = resolveEngine.getDependencies(md, new ResolveOptions() - .setResolveId(resolveId).setConfs(new String[] {"default"}).setCache( - CacheManager.getInstance(settings, cache)), report); - report.setDependencies(Arrays.asList(dependencies), artifactFilter); - - Message.info(":: downloading artifacts to cache ::"); - resolveEngine.downloadArtifacts(report, getCacheManager(cache), false, artifactFilter); - - // now that everything is in cache, we can publish all these modules - Message.info(":: installing in " + to + " ::"); - for (int i = 0; i < dependencies.length; i++) { - ModuleDescriptor depmd = dependencies[i].getDescriptor(); - if (depmd != null) { - Message.verbose("installing " + depmd.getModuleRevisionId()); - publishEngine.publish(depmd, Collections.singleton(cache.getAbsolutePath() - + "/" + settings.getCacheArtifactPattern()), toResolver, - new PublishOptions().setSrcIvyPattern( - cache.getAbsolutePath() + "/" + settings.getCacheIvyPattern()) - .setOverwrite(overwrite)); - } - } - - Message.info(":: install resolution report ::"); - - // output report - report.output(settings.getReportOutputters(), cache); - - return report; - } finally { - resolveEngine.setDictatorResolver(oldDicator); - settings.setLogNotConvertedExclusionRule(log); - } - } - - private CacheManager getCacheManager(File cache) { - // TODO : reuse instance - CacheManager cacheManager = new CacheManager(settings, cache); - return cacheManager; - } - -} +/* + * 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.core.install; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.publish.PublishEngine; +import org.apache.ivy.core.publish.PublishOptions; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveEngine; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.search.SearchEngine; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.conflict.NoConflictManager; +import org.apache.ivy.plugins.matcher.ExactPatternMatcher; +import org.apache.ivy.plugins.matcher.MatcherHelper; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.filter.Filter; +import org.apache.ivy.util.filter.FilterHelper; + +public class InstallEngine { + private IvySettings settings; + + private ResolveEngine resolveEngine; + + private PublishEngine publishEngine; + + private SearchEngine searchEngine; + + public InstallEngine(IvySettings settings, SearchEngine searchEngine, + ResolveEngine resolveEngine, PublishEngine publishEngine) { + this.settings = settings; + this.searchEngine = searchEngine; + this.resolveEngine = resolveEngine; + this.publishEngine = publishEngine; + } + + public ResolveReport install(ModuleRevisionId mrid, String from, String to, boolean transitive, + boolean validate, boolean overwrite, Filter artifactFilter, File cache, + String matcherName) throws IOException { + if (cache == null) { + cache = settings.getDefaultCache(); + } + if (artifactFilter == null) { + artifactFilter = FilterHelper.NO_FILTER; + } + DependencyResolver fromResolver = settings.getResolver(from); + DependencyResolver toResolver = settings.getResolver(to); + if (fromResolver == null) { + throw new IllegalArgumentException("unknown resolver " + from + + ". Available resolvers are: " + settings.getResolverNames()); + } + if (toResolver == null) { + throw new IllegalArgumentException("unknown resolver " + to + + ". Available resolvers are: " + settings.getResolverNames()); + } + PatternMatcher matcher = settings.getMatcher(matcherName); + if (matcher == null) { + throw new IllegalArgumentException("unknown matcher " + matcherName + + ". Available matchers are: " + settings.getMatcherNames()); + } + + // build module file declaring the dependency + Message.info(":: installing " + mrid + " ::"); + DependencyResolver oldDicator = resolveEngine.getDictatorResolver(); + boolean log = settings.logNotConvertedExclusionRule(); + try { + settings.setLogNotConvertedExclusionRule(true); + resolveEngine.setDictatorResolver(fromResolver); + + DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance( + "apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), + new Date()); + String resolveId = ResolveOptions.getDefaultResolveId(md); + md.addConfiguration(new Configuration("default")); + md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, + ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, + new NoConflictManager()); + + if (MatcherHelper.isExact(matcher, mrid)) { + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, + false, transitive); + dd.addDependencyConfiguration("default", "*"); + md.addDependency(dd); + } else { + Collection mrids = searchEngine.findModuleRevisionIds(fromResolver, mrid, matcher); + + for (Iterator iter = mrids.iterator(); iter.hasNext();) { + ModuleRevisionId foundMrid = (ModuleRevisionId) iter.next(); + Message.info("\tfound " + foundMrid + " to install: adding to the list"); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, foundMrid, + false, false, transitive); + dd.addDependencyConfiguration("default", "*"); + md.addDependency(dd); + } + } + + // resolve using appropriate resolver + ResolveReport report = new ResolveReport(md, resolveId); + + Message.info(":: resolving dependencies ::"); + IvyNode[] dependencies = resolveEngine.getDependencies(md, new ResolveOptions() + .setResolveId(resolveId).setConfs(new String[] {"default"}).setCache( + CacheManager.getInstance(settings, cache)), report); + report.setDependencies(Arrays.asList(dependencies), artifactFilter); + + Message.info(":: downloading artifacts to cache ::"); + resolveEngine.downloadArtifacts(report, getCacheManager(cache), false, artifactFilter); + + // now that everything is in cache, we can publish all these modules + Message.info(":: installing in " + to + " ::"); + for (int i = 0; i < dependencies.length; i++) { + ModuleDescriptor depmd = dependencies[i].getDescriptor(); + if (depmd != null) { + Message.verbose("installing " + depmd.getModuleRevisionId()); + publishEngine.publish(depmd, Collections.singleton(cache.getAbsolutePath() + + "/" + settings.getCacheArtifactPattern()), toResolver, + new PublishOptions().setSrcIvyPattern( + cache.getAbsolutePath() + "/" + settings.getCacheIvyPattern()) + .setOverwrite(overwrite)); + } + } + + Message.info(":: install resolution report ::"); + + // output report + report.output(settings.getReportOutputters(), cache); + + return report; + } finally { + resolveEngine.setDictatorResolver(oldDicator); + settings.setLogNotConvertedExclusionRule(log); + } + } + + private CacheManager getCacheManager(File cache) { + // TODO : reuse instance + CacheManager cacheManager = new CacheManager(settings, cache); + return cacheManager; + } + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/AbstractArtifact.java b/src/java/org/apache/ivy/core/module/descriptor/AbstractArtifact.java index fc2cf774..53ea92e4 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/AbstractArtifact.java +++ b/src/java/org/apache/ivy/core/module/descriptor/AbstractArtifact.java @@ -1,84 +1,84 @@ -/* - * 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.core.module.descriptor; - -import java.util.Map; - -/** - * - */ -public abstract class AbstractArtifact implements Artifact { - public AbstractArtifact() { - } - - public boolean equals(Object obj) { - if (!(obj instanceof Artifact)) { - return false; - } - Artifact art = (Artifact) obj; - return getModuleRevisionId().equals(art.getModuleRevisionId()) - && getPublicationDate() == null ? true : getPublicationDate().equals( - art.getPublicationDate()) - && getName().equals(art.getName()) - && getExt().equals(art.getExt()) - && getType().equals(art.getType()) - && getExtraAttributes().equals(art.getExtraAttributes()); - } - - public int hashCode() { - int hash = 33; - hash = hash * 17 + getModuleRevisionId().hashCode(); - if (getPublicationDate() != null) { - hash = hash * 17 + getPublicationDate().hashCode(); - } - hash = hash * 17 + getName().hashCode(); - hash = hash * 17 + getExt().hashCode(); - hash = hash * 17 + getType().hashCode(); - hash = hash * 17 + getExtraAttributes().hashCode(); - return hash; - } - - public String toString() { - return getModuleRevisionId() + "/" + getName() + "." + getExt() + "[" + getType() + "]"; - } - - public String getAttribute(String attName) { - return getId().getAttribute(attName); - } - - public Map getAttributes() { - return getId().getAttributes(); - } - - public String getExtraAttribute(String attName) { - return getId().getExtraAttribute(attName); - } - - public Map getExtraAttributes() { - return getId().getExtraAttributes(); - } - - public String getStandardAttribute(String attName) { - return getId().getStandardAttribute(attName); - } - - public Map getStandardAttributes() { - return getId().getStandardAttributes(); - } - -} +/* + * 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.core.module.descriptor; + +import java.util.Map; + +/** + * + */ +public abstract class AbstractArtifact implements Artifact { + public AbstractArtifact() { + } + + public boolean equals(Object obj) { + if (!(obj instanceof Artifact)) { + return false; + } + Artifact art = (Artifact) obj; + return getModuleRevisionId().equals(art.getModuleRevisionId()) + && getPublicationDate() == null ? true : getPublicationDate().equals( + art.getPublicationDate()) + && getName().equals(art.getName()) + && getExt().equals(art.getExt()) + && getType().equals(art.getType()) + && getExtraAttributes().equals(art.getExtraAttributes()); + } + + public int hashCode() { + int hash = 33; + hash = hash * 17 + getModuleRevisionId().hashCode(); + if (getPublicationDate() != null) { + hash = hash * 17 + getPublicationDate().hashCode(); + } + hash = hash * 17 + getName().hashCode(); + hash = hash * 17 + getExt().hashCode(); + hash = hash * 17 + getType().hashCode(); + hash = hash * 17 + getExtraAttributes().hashCode(); + return hash; + } + + public String toString() { + return getModuleRevisionId() + "/" + getName() + "." + getExt() + "[" + getType() + "]"; + } + + public String getAttribute(String attName) { + return getId().getAttribute(attName); + } + + public Map getAttributes() { + return getId().getAttributes(); + } + + public String getExtraAttribute(String attName) { + return getId().getExtraAttribute(attName); + } + + public Map getExtraAttributes() { + return getId().getExtraAttributes(); + } + + public String getStandardAttribute(String attName) { + return getId().getStandardAttribute(attName); + } + + public Map getStandardAttributes() { + return getId().getStandardAttributes(); + } + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/AbstractIncludeExcludeRule.java b/src/java/org/apache/ivy/core/module/descriptor/AbstractIncludeExcludeRule.java index 94ed0bb1..24bb75d0 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/AbstractIncludeExcludeRule.java +++ b/src/java/org/apache/ivy/core/module/descriptor/AbstractIncludeExcludeRule.java @@ -1,94 +1,94 @@ -/* - * 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.core.module.descriptor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; - -/** - * Abstract class used as implementation for both {@link IncludeRule} and {@link ExcludeRule}, - * since their contract is almost identical - */ -public abstract class AbstractIncludeExcludeRule extends UnmodifiableExtendableItem implements - ConfigurationAware { - - private ArtifactId id; - - private Collection confs = new ArrayList(); - - private PatternMatcher patternMatcher; - - public AbstractIncludeExcludeRule(ArtifactId aid, PatternMatcher matcher, Map extraAttributes) { - super(null, extraAttributes); - id = aid; - patternMatcher = matcher; - initStandardAttributes(); - } - - private void initStandardAttributes() { - setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, id.getModuleId().getOrganisation()); - setStandardAttribute(IvyPatternHelper.MODULE_KEY, id.getModuleId().getName()); - setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, id.getName()); - setStandardAttribute(IvyPatternHelper.TYPE_KEY, id.getType()); - setStandardAttribute(IvyPatternHelper.EXT_KEY, id.getExt()); - setStandardAttribute("matcher", patternMatcher.getName()); - } - - public boolean equals(Object obj) { - if (!(obj instanceof AbstractIncludeExcludeRule)) { - return false; - } - AbstractIncludeExcludeRule rule = (AbstractIncludeExcludeRule) obj; - return getId().equals(rule.getId()); - } - - public int hashCode() { - return getId().hashCode(); - } - - /** - * Add a configuration for this rule - * - * @param conf - */ - public void addConfiguration(String conf) { - confs.add(conf); - } - - public ArtifactId getId() { - return id; - } - - public String[] getConfigurations() { - return (String[]) confs.toArray(new String[confs.size()]); - } - - public PatternMatcher getMatcher() { - return patternMatcher; - } - - public String toString() { - return id + "(" + confs + ")"; - } -} +/* + * 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.core.module.descriptor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; + +/** + * Abstract class used as implementation for both {@link IncludeRule} and {@link ExcludeRule}, + * since their contract is almost identical + */ +public abstract class AbstractIncludeExcludeRule extends UnmodifiableExtendableItem implements + ConfigurationAware { + + private ArtifactId id; + + private Collection confs = new ArrayList(); + + private PatternMatcher patternMatcher; + + public AbstractIncludeExcludeRule(ArtifactId aid, PatternMatcher matcher, Map extraAttributes) { + super(null, extraAttributes); + id = aid; + patternMatcher = matcher; + initStandardAttributes(); + } + + private void initStandardAttributes() { + setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, id.getModuleId().getOrganisation()); + setStandardAttribute(IvyPatternHelper.MODULE_KEY, id.getModuleId().getName()); + setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, id.getName()); + setStandardAttribute(IvyPatternHelper.TYPE_KEY, id.getType()); + setStandardAttribute(IvyPatternHelper.EXT_KEY, id.getExt()); + setStandardAttribute("matcher", patternMatcher.getName()); + } + + public boolean equals(Object obj) { + if (!(obj instanceof AbstractIncludeExcludeRule)) { + return false; + } + AbstractIncludeExcludeRule rule = (AbstractIncludeExcludeRule) obj; + return getId().equals(rule.getId()); + } + + public int hashCode() { + return getId().hashCode(); + } + + /** + * Add a configuration for this rule + * + * @param conf + */ + public void addConfiguration(String conf) { + confs.add(conf); + } + + public ArtifactId getId() { + return id; + } + + public String[] getConfigurations() { + return (String[]) confs.toArray(new String[confs.size()]); + } + + public PatternMatcher getMatcher() { + return patternMatcher; + } + + public String toString() { + return id + "(" + confs + ")"; + } +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/Artifact.java b/src/java/org/apache/ivy/core/module/descriptor/Artifact.java index 5c5285eb..3c79120c 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/Artifact.java +++ b/src/java/org/apache/ivy/core/module/descriptor/Artifact.java @@ -1,91 +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.core.module.descriptor; - -import java.net.URL; -import java.util.Date; - -import org.apache.ivy.core.module.id.ArtifactRevisionId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.util.extendable.ExtendableItem; - -/** - * Representation of a published 'file' in the development environment. An artifact is generally a - * file that is produced by a project build. This is typically a jar, a war, an ear, a zip, a deb, - * ... - */ -public interface Artifact extends ExtendableItem { - - /** - * Returns the resolved module revision id for this artifact - * - * @return the resolved module revision id. - */ - ModuleRevisionId getModuleRevisionId(); - - /** - * Returns the resolved publication date for this artifact - * - * @return the resolved publication date. Never null. - */ - Date getPublicationDate(); - - /** - * Return the name of the artifact, generally 'part' of the basename of the file. - * - * @return the name of the artifact. Never null. - */ - String getName(); - - /** - * Returns the type of the artifact, typically 'jar', 'source', 'javadoc', 'debian', ... - * - * @return the type of the artifact. Never null. - */ - String getType(); - - /** - * Retrieve the extension of the artifact. The extension is without dot (ie. 'jar' and not - * '.jar') - * - * @return the extension of the artifact. Never null. - */ - String getExt(); - - /** - * Returns the url at which this artifact can be found independently of ivy configuration. This - * can be null (and is usually for standard artifacts) - * - * @return url at which this artifact can be found independently of ivy configuration - */ - URL getUrl(); - - /** - * Returns the list of configurations where this artifact is associated to. - * - * @return the list of configuration this artifact is associated to. Never null. - */ - String[] getConfigurations(); - - /** - * Return the specific identifier of this artifact. - * - * @return the id of the artifact - */ - ArtifactRevisionId getId(); -} +/* + * 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.core.module.descriptor; + +import java.net.URL; +import java.util.Date; + +import org.apache.ivy.core.module.id.ArtifactRevisionId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.util.extendable.ExtendableItem; + +/** + * Representation of a published 'file' in the development environment. An artifact is generally a + * file that is produced by a project build. This is typically a jar, a war, an ear, a zip, a deb, + * ... + */ +public interface Artifact extends ExtendableItem { + + /** + * Returns the resolved module revision id for this artifact + * + * @return the resolved module revision id. + */ + ModuleRevisionId getModuleRevisionId(); + + /** + * Returns the resolved publication date for this artifact + * + * @return the resolved publication date. Never null. + */ + Date getPublicationDate(); + + /** + * Return the name of the artifact, generally 'part' of the basename of the file. + * + * @return the name of the artifact. Never null. + */ + String getName(); + + /** + * Returns the type of the artifact, typically 'jar', 'source', 'javadoc', 'debian', ... + * + * @return the type of the artifact. Never null. + */ + String getType(); + + /** + * Retrieve the extension of the artifact. The extension is without dot (ie. 'jar' and not + * '.jar') + * + * @return the extension of the artifact. Never null. + */ + String getExt(); + + /** + * Returns the url at which this artifact can be found independently of ivy configuration. This + * can be null (and is usually for standard artifacts) + * + * @return url at which this artifact can be found independently of ivy configuration + */ + URL getUrl(); + + /** + * Returns the list of configurations where this artifact is associated to. + * + * @return the list of configuration this artifact is associated to. Never null. + */ + String[] getConfigurations(); + + /** + * Return the specific identifier of this artifact. + * + * @return the id of the artifact + */ + ArtifactRevisionId getId(); +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/Configuration.java b/src/java/org/apache/ivy/core/module/descriptor/Configuration.java index de172e8f..fbbe045e 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/Configuration.java +++ b/src/java/org/apache/ivy/core/module/descriptor/Configuration.java @@ -1,195 +1,195 @@ -/* - * 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.core.module.descriptor; - -import java.util.LinkedHashSet; -import java.util.Set; - -import org.apache.ivy.util.extendable.DefaultExtendableItem; - -/** - * Represents a module configuration - */ -public class Configuration extends DefaultExtendableItem { - public static class Visibility { - public static Visibility PUBLIC = new Visibility("public"); - - public static Visibility PRIVATE = new Visibility("private"); - - public static Visibility getVisibility(String name) { - if ("private".equals(name)) { - return PRIVATE; - } else if ("public".equals(name)) { - return PUBLIC; - } else { - throw new IllegalArgumentException("unknwon visibility " + name); - } - } - - private String name; - - private Visibility(String name) { - this.name = name; - } - - public String toString() { - return name; - } - } - - private String name; - - private String description; - - private String[] _extends; - - private Visibility visibility; - - private boolean transitive = true; - - /** - * @param name - * @param visibility - * @param description - * @param ext - */ - public Configuration(String name, Visibility visibility, String description, String[] ext) { - this(name, visibility, description, ext, true); - } - - /** - * @param name - * @param visibility - * @param description - * @param ext - * @param transitive - */ - public Configuration(String name, Visibility visibility, String description, String[] ext, - boolean transitive) { - if (name == null) { - throw new NullPointerException("null configuration name not allowed"); - } - if (visibility == null) { - throw new NullPointerException("null visibility not allowed"); - } - this.name = name; - this.visibility = visibility; - this.description = description; - if (ext == null) { - _extends = new String[0]; - } else { - _extends = new String[ext.length]; - for (int i = 0; i < ext.length; i++) { - _extends[i] = ext[i].trim(); - } - } - this.transitive = transitive; - } - - /** - * @param name - */ - public Configuration(String name) { - this(name, Visibility.PUBLIC, null, null); - } - - /** - * @return Returns the description. It may be null. - */ - public String getDescription() { - return description; - } - - /** - * @return Returns the extends. May be empty, but never null. - */ - public String[] getExtends() { - return _extends; - } - - /** - * @return Returns the name. Never null; - */ - public String getName() { - return name; - } - - /** - * @return Returns the visibility. Never null. - */ - public Visibility getVisibility() { - return visibility; - } - - /** - * @return Returns the transitive. - */ - public final boolean isTransitive() { - return transitive; - } - - public String toString() { - return name; - } - - public boolean equals(Object obj) { - if (!(obj instanceof Configuration)) { - return false; - } - return ((Configuration) obj).getName().equals(getName()); - } - - public int hashCode() { - return getName().hashCode(); - } - - public void replaceWildcards(ModuleDescriptor md) { - if (this != md.getConfiguration(name)) { - throw new IllegalArgumentException( - "The given ModuleDescriptor doesn't own this configuration!"); - } - - Configuration[] configs = md.getConfigurations(); - - Set newExtends = new LinkedHashSet(); - for (int j = 0; j < _extends.length; j++) { - if ("*".equals(_extends[j])) { - addOther(configs, null, newExtends); - } else if ("*(public)".equals(_extends[j])) { - addOther(configs, Visibility.PUBLIC, newExtends); - } else if ("*(private)".equals(_extends[j])) { - addOther(configs, Visibility.PRIVATE, newExtends); - } else { - newExtends.add(_extends[j]); - } - } - - this._extends = (String[]) newExtends.toArray(new String[newExtends.size()]); - } - - private void addOther(Configuration[] allConfigs, Visibility visibility, Set configs) { - for (int i = 0; i < allConfigs.length; i++) { - String currentName = allConfigs[i].getName(); - if (!name.equals(currentName) - && ((visibility == null) || visibility.equals(allConfigs[i].getVisibility()))) { - configs.add(currentName); - } - } - } - -} +/* + * 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.core.module.descriptor; + +import java.util.LinkedHashSet; +import java.util.Set; + +import org.apache.ivy.util.extendable.DefaultExtendableItem; + +/** + * Represents a module configuration + */ +public class Configuration extends DefaultExtendableItem { + public static class Visibility { + public static Visibility PUBLIC = new Visibility("public"); + + public static Visibility PRIVATE = new Visibility("private"); + + public static Visibility getVisibility(String name) { + if ("private".equals(name)) { + return PRIVATE; + } else if ("public".equals(name)) { + return PUBLIC; + } else { + throw new IllegalArgumentException("unknwon visibility " + name); + } + } + + private String name; + + private Visibility(String name) { + this.name = name; + } + + public String toString() { + return name; + } + } + + private String name; + + private String description; + + private String[] _extends; + + private Visibility visibility; + + private boolean transitive = true; + + /** + * @param name + * @param visibility + * @param description + * @param ext + */ + public Configuration(String name, Visibility visibility, String description, String[] ext) { + this(name, visibility, description, ext, true); + } + + /** + * @param name + * @param visibility + * @param description + * @param ext + * @param transitive + */ + public Configuration(String name, Visibility visibility, String description, String[] ext, + boolean transitive) { + if (name == null) { + throw new NullPointerException("null configuration name not allowed"); + } + if (visibility == null) { + throw new NullPointerException("null visibility not allowed"); + } + this.name = name; + this.visibility = visibility; + this.description = description; + if (ext == null) { + _extends = new String[0]; + } else { + _extends = new String[ext.length]; + for (int i = 0; i < ext.length; i++) { + _extends[i] = ext[i].trim(); + } + } + this.transitive = transitive; + } + + /** + * @param name + */ + public Configuration(String name) { + this(name, Visibility.PUBLIC, null, null); + } + + /** + * @return Returns the description. It may be null. + */ + public String getDescription() { + return description; + } + + /** + * @return Returns the extends. May be empty, but never null. + */ + public String[] getExtends() { + return _extends; + } + + /** + * @return Returns the name. Never null; + */ + public String getName() { + return name; + } + + /** + * @return Returns the visibility. Never null. + */ + public Visibility getVisibility() { + return visibility; + } + + /** + * @return Returns the transitive. + */ + public final boolean isTransitive() { + return transitive; + } + + public String toString() { + return name; + } + + public boolean equals(Object obj) { + if (!(obj instanceof Configuration)) { + return false; + } + return ((Configuration) obj).getName().equals(getName()); + } + + public int hashCode() { + return getName().hashCode(); + } + + public void replaceWildcards(ModuleDescriptor md) { + if (this != md.getConfiguration(name)) { + throw new IllegalArgumentException( + "The given ModuleDescriptor doesn't own this configuration!"); + } + + Configuration[] configs = md.getConfigurations(); + + Set newExtends = new LinkedHashSet(); + for (int j = 0; j < _extends.length; j++) { + if ("*".equals(_extends[j])) { + addOther(configs, null, newExtends); + } else if ("*(public)".equals(_extends[j])) { + addOther(configs, Visibility.PUBLIC, newExtends); + } else if ("*(private)".equals(_extends[j])) { + addOther(configs, Visibility.PRIVATE, newExtends); + } else { + newExtends.add(_extends[j]); + } + } + + this._extends = (String[]) newExtends.toArray(new String[newExtends.size()]); + } + + private void addOther(Configuration[] allConfigs, Visibility visibility, Set configs) { + for (int i = 0; i < allConfigs.length; i++) { + String currentName = allConfigs[i].getName(); + if (!name.equals(currentName) + && ((visibility == null) || visibility.equals(allConfigs[i].getVisibility()))) { + configs.add(currentName); + } + } + } + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/ConfigurationAware.java b/src/java/org/apache/ivy/core/module/descriptor/ConfigurationAware.java index 5ee25960..2982f7ae 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/ConfigurationAware.java +++ b/src/java/org/apache/ivy/core/module/descriptor/ConfigurationAware.java @@ -1,39 +1,39 @@ -/* - * 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.core.module.descriptor; - -/** - * Objects implementing this interface are aware of module configurations, and can thus be added to - * configurations, and list their configurations. - */ -public interface ConfigurationAware { - /** - * Returns the configurations of the module to which the object is attached - * - * @return an array of configuration names to which the object is attached - */ - public String[] getConfigurations(); - - /** - * Tells this object that it will now be part of the given configuration - * - * @param confName - * the name of the configuration to which the object is now attached - */ - public void addConfiguration(String confName); -} +/* + * 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.core.module.descriptor; + +/** + * Objects implementing this interface are aware of module configurations, and can thus be added to + * configurations, and list their configurations. + */ +public interface ConfigurationAware { + /** + * Returns the configurations of the module to which the object is attached + * + * @return an array of configuration names to which the object is attached + */ + public String[] getConfigurations(); + + /** + * Tells this object that it will now be part of the given configuration + * + * @param confName + * the name of the configuration to which the object is now attached + */ + public void addConfiguration(String confName); +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DefaultArtifact.java b/src/java/org/apache/ivy/core/module/descriptor/DefaultArtifact.java index 20fb7c68..456bb426 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DefaultArtifact.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DefaultArtifact.java @@ -1,129 +1,129 @@ -/* - * 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.core.module.descriptor; - -import java.net.URL; -import java.util.Date; -import java.util.Map; - -import org.apache.ivy.core.module.id.ArtifactRevisionId; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -/** - * - */ -public class DefaultArtifact extends AbstractArtifact { - - public static Artifact newIvyArtifact(ModuleRevisionId mrid, Date pubDate) { - return new DefaultArtifact(mrid, pubDate, "ivy", "ivy", "xml"); - } - - public static Artifact newPomArtifact(ModuleRevisionId mrid, Date pubDate) { - return new DefaultArtifact(mrid, pubDate, mrid.getName(), "pom", "pom"); - } - - public static Artifact cloneWithAnotherType(Artifact artifact, String newType) { - return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(), - artifact.getName(), newType, artifact.getExt(), artifact.getUrl(), artifact - .getExtraAttributes()); - } - - public static Artifact cloneWithAnotherTypeAndExt(Artifact artifact, String newType, - String newExt) { - return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(), - artifact.getName(), newType, newExt, artifact.getUrl(), artifact - .getExtraAttributes()); - } - - public static Artifact cloneWithAnotherMrid(Artifact artifact, ModuleRevisionId mrid) { - return new DefaultArtifact(mrid, artifact.getPublicationDate(), artifact.getName(), - artifact.getType(), artifact.getExt(), artifact.getUrl(), artifact - .getExtraAttributes()); - } - - Date publicationDate; - - ArtifactRevisionId arid; - - URL url; - - public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, - String ext) { - this(mrid, publicationDate, name, type, ext, null, null); - } - - public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, - String ext, Map extraAttributes) { - this(mrid, publicationDate, name, type, ext, null, extraAttributes); - } - - public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, - String ext, URL url, Map extraAttributes) { - if (mrid == null) { - throw new NullPointerException("null mrid not allowed"); - } - if (publicationDate == null) { - publicationDate = new Date(); - } - if (name == null) { - throw new NullPointerException("null name not allowed"); - } - if (type == null) { - throw new NullPointerException("null type not allowed"); - } - if (ext == null) { - throw new NullPointerException("null ext not allowed"); - } - this.publicationDate = publicationDate; - this.arid = ArtifactRevisionId.newInstance(mrid, name, type, ext, extraAttributes); - this.url = url; - } - - public ModuleRevisionId getModuleRevisionId() { - return arid.getModuleRevisionId(); - } - - public String getName() { - return arid.getName(); - } - - public Date getPublicationDate() { - return publicationDate; - } - - public String getType() { - return arid.getType(); - } - - public String getExt() { - return arid.getExt(); - } - - public ArtifactRevisionId getId() { - return arid; - } - - public String[] getConfigurations() { - return new String[0]; - } - - public URL getUrl() { - return url; - } - -} +/* + * 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.core.module.descriptor; + +import java.net.URL; +import java.util.Date; +import java.util.Map; + +import org.apache.ivy.core.module.id.ArtifactRevisionId; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +/** + * + */ +public class DefaultArtifact extends AbstractArtifact { + + public static Artifact newIvyArtifact(ModuleRevisionId mrid, Date pubDate) { + return new DefaultArtifact(mrid, pubDate, "ivy", "ivy", "xml"); + } + + public static Artifact newPomArtifact(ModuleRevisionId mrid, Date pubDate) { + return new DefaultArtifact(mrid, pubDate, mrid.getName(), "pom", "pom"); + } + + public static Artifact cloneWithAnotherType(Artifact artifact, String newType) { + return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(), + artifact.getName(), newType, artifact.getExt(), artifact.getUrl(), artifact + .getExtraAttributes()); + } + + public static Artifact cloneWithAnotherTypeAndExt(Artifact artifact, String newType, + String newExt) { + return new DefaultArtifact(artifact.getModuleRevisionId(), artifact.getPublicationDate(), + artifact.getName(), newType, newExt, artifact.getUrl(), artifact + .getExtraAttributes()); + } + + public static Artifact cloneWithAnotherMrid(Artifact artifact, ModuleRevisionId mrid) { + return new DefaultArtifact(mrid, artifact.getPublicationDate(), artifact.getName(), + artifact.getType(), artifact.getExt(), artifact.getUrl(), artifact + .getExtraAttributes()); + } + + Date publicationDate; + + ArtifactRevisionId arid; + + URL url; + + public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, + String ext) { + this(mrid, publicationDate, name, type, ext, null, null); + } + + public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, + String ext, Map extraAttributes) { + this(mrid, publicationDate, name, type, ext, null, extraAttributes); + } + + public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate, String name, String type, + String ext, URL url, Map extraAttributes) { + if (mrid == null) { + throw new NullPointerException("null mrid not allowed"); + } + if (publicationDate == null) { + publicationDate = new Date(); + } + if (name == null) { + throw new NullPointerException("null name not allowed"); + } + if (type == null) { + throw new NullPointerException("null type not allowed"); + } + if (ext == null) { + throw new NullPointerException("null ext not allowed"); + } + this.publicationDate = publicationDate; + this.arid = ArtifactRevisionId.newInstance(mrid, name, type, ext, extraAttributes); + this.url = url; + } + + public ModuleRevisionId getModuleRevisionId() { + return arid.getModuleRevisionId(); + } + + public String getName() { + return arid.getName(); + } + + public Date getPublicationDate() { + return publicationDate; + } + + public String getType() { + return arid.getType(); + } + + public String getExt() { + return arid.getExt(); + } + + public ArtifactRevisionId getId() { + return arid; + } + + public String[] getConfigurations() { + return new String[0]; + } + + public URL getUrl() { + return url; + } + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyArtifactDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyArtifactDescriptor.java index 9d50c88c..3e985791 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyArtifactDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyArtifactDescriptor.java @@ -1,118 +1,118 @@ -/* - * 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.core.module.descriptor; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; - -public class DefaultDependencyArtifactDescriptor extends UnmodifiableExtendableItem implements - DependencyArtifactDescriptor, ConfigurationAware { - - private Collection confs = new ArrayList(); - - private URL url; - - private String name; - - private String type; - - private String ext; - - /** - * @param dd - * @param name - * @param type - * @param url - */ - public DefaultDependencyArtifactDescriptor(String name, String type, String ext, URL url, - Map extraAttributes) { - super(null, extraAttributes); - if (name == null) { - throw new NullPointerException("name must not be null"); - } - if (type == null) { - throw new NullPointerException("type must not be null"); - } - if (ext == null) { - throw new NullPointerException("ext must not be null"); - } - this.name = name; - this.type = type; - this.ext = ext; - this.url = url; - initStandardAttributes(); - } - - private void initStandardAttributes() { - setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, getName()); - setStandardAttribute(IvyPatternHelper.TYPE_KEY, getType()); - setStandardAttribute(IvyPatternHelper.EXT_KEY, getExt()); - setStandardAttribute("url", url != null ? String.valueOf(url) : ""); - } - - public boolean equals(Object obj) { - if (!(obj instanceof DependencyArtifactDescriptor)) { - return false; - } - DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor) obj; - return getAttributes().equals(dad.getAttributes()); - } - - public int hashCode() { - return getAttributes().hashCode(); - } - - /** - * Add a configuration for this artifact. - * - * @param conf - */ - public void addConfiguration(String conf) { - confs.add(conf); - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public String getExt() { - return ext; - } - - public String[] getConfigurations() { - return (String[]) confs.toArray(new String[confs.size()]); - } - - public URL getUrl() { - return url; - } - - public String toString() { - return "DA:" + name + "." + ext + "(" + type + ") " + "(" + confs + ")" - + (url == null ? "" : url.toString()); - } -} +/* + * 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.core.module.descriptor; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; + +public class DefaultDependencyArtifactDescriptor extends UnmodifiableExtendableItem implements + DependencyArtifactDescriptor, ConfigurationAware { + + private Collection confs = new ArrayList(); + + private URL url; + + private String name; + + private String type; + + private String ext; + + /** + * @param dd + * @param name + * @param type + * @param url + */ + public DefaultDependencyArtifactDescriptor(String name, String type, String ext, URL url, + Map extraAttributes) { + super(null, extraAttributes); + if (name == null) { + throw new NullPointerException("name must not be null"); + } + if (type == null) { + throw new NullPointerException("type must not be null"); + } + if (ext == null) { + throw new NullPointerException("ext must not be null"); + } + this.name = name; + this.type = type; + this.ext = ext; + this.url = url; + initStandardAttributes(); + } + + private void initStandardAttributes() { + setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, getName()); + setStandardAttribute(IvyPatternHelper.TYPE_KEY, getType()); + setStandardAttribute(IvyPatternHelper.EXT_KEY, getExt()); + setStandardAttribute("url", url != null ? String.valueOf(url) : ""); + } + + public boolean equals(Object obj) { + if (!(obj instanceof DependencyArtifactDescriptor)) { + return false; + } + DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor) obj; + return getAttributes().equals(dad.getAttributes()); + } + + public int hashCode() { + return getAttributes().hashCode(); + } + + /** + * Add a configuration for this artifact. + * + * @param conf + */ + public void addConfiguration(String conf) { + confs.add(conf); + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String getExt() { + return ext; + } + + public String[] getConfigurations() { + return (String[]) confs.toArray(new String[confs.size()]); + } + + public URL getUrl() { + return url; + } + + public String toString() { + return "DA:" + name + "." + ext + "(" + type + ") " + "(" + confs + ")" + + (url == null ? "" : url.toString()); + } +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java index 50ce0eed..d2c13853 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java @@ -1,519 +1,519 @@ -/* - * 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.core.module.descriptor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.matcher.MatcherHelper; -import org.apache.ivy.plugins.namespace.NameSpaceHelper; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.plugins.namespace.NamespaceTransformer; - -/** - * This class can be used as the default implementation for DependencyDescriptor. It implements - * required methods and enables to fill dependency information with the addDependencyConfiguration - * method. - */ -public class DefaultDependencyDescriptor implements DependencyDescriptor { - private static final Pattern SELF_FALLBACK_PATTERN = Pattern.compile("@(\\(.*\\))?"); - - private static final Pattern THIS_FALLBACK_PATTERN = Pattern.compile("#(\\(.*\\))?"); - - /** - * Transforms the given dependency descriptor of the given namespace and return a new dependency - * descriptor in the system namespace. Note that exclude rules are not converted in system - * namespace, because they aren't transformable (the name space hasn't the ability to convert - * regular expressions). However, method doesExclude will work with system artifacts. - * - * @param md - * @param ns - * @return - */ - public static DependencyDescriptor transformInstance(DependencyDescriptor dd, Namespace ns) { - NamespaceTransformer t = ns.getToSystemTransformer(); - if (t.isIdentity()) { - return dd; - } - DefaultDependencyDescriptor newdd = transformInstance(dd, t, false); - newdd._namespace = ns; - return newdd; - } - - /** - * Transforms a dependency descriptor using the given transformer. Note that no namespace info - * will be attached to the transformed dependency descriptor, so calling doesExclude is not - * recommended (doesExclude only works when namespace is properly set) - * - * @param dd - * @param t - * @return - */ - public static DefaultDependencyDescriptor transformInstance(DependencyDescriptor dd, - NamespaceTransformer t, boolean fromSystem) { - ModuleRevisionId transformParentId = t.transform(dd.getParentRevisionId()); - ModuleRevisionId transformMrid = t.transform(dd.getDependencyRevisionId()); - DefaultDependencyDescriptor newdd = new DefaultDependencyDescriptor(null, transformMrid, dd - .isForce(), dd.isChanging(), dd.isTransitive()); - newdd._parentId = transformParentId; - String[] moduleConfs = dd.getModuleConfigurations(); - if (moduleConfs.length == 1 && "*".equals(moduleConfs[0])) { - if (dd instanceof DefaultDependencyDescriptor) { - DefaultDependencyDescriptor ddd = (DefaultDependencyDescriptor) dd; - newdd._confs = new LinkedHashMap(ddd._confs); - newdd._excludeRules = new LinkedHashMap(ddd._excludeRules); - newdd._includeRules = new LinkedHashMap(ddd._includeRules); - newdd._dependencyArtifacts = new LinkedHashMap(ddd._dependencyArtifacts); - } else { - throw new IllegalArgumentException( - "dependency descriptor transformation does not support * module confs with descriptors which aren't DefaultDependencyDescriptor"); - } - } else { - for (int i = 0; i < moduleConfs.length; i++) { - newdd._confs.put(moduleConfs[i], new ArrayList(Arrays.asList(dd - .getDependencyConfigurations(moduleConfs[i])))); - newdd._excludeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd - .getExcludeRules(moduleConfs[i])))); - newdd._includeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd - .getIncludeRules(moduleConfs[i])))); - newdd._dependencyArtifacts.put(moduleConfs[i], new ArrayList(Arrays.asList(dd - .getDependencyArtifacts(moduleConfs[i])))); - } - } - if (fromSystem) { - newdd._asSystem = dd; - } - return newdd; - } - - private ModuleRevisionId _revId; - - private Map _confs = new LinkedHashMap(); - - private Map _dependencyArtifacts = new LinkedHashMap(); // Map (String masterConf -> - - // Collection(DependencyArtifactDescriptor)) - - private Map _includeRules = new LinkedHashMap(); // Map (String masterConf -> - - // Collection(IncludeRule)) - - private Map _excludeRules = new LinkedHashMap(); // Map (String masterConf -> - - // Collection(ExcludeRule)) - - private Set _extends = new LinkedHashSet(); - - /** - * Used to indicate that this revision must be used in case of conflicts, independently of - * conflicts manager - */ - private boolean _force; - - /** - * Used to indicate that the dependency is a changing one, i.e. that ivy should not rely on the - * version to know if it can trust artifacts in cache - */ - private boolean _changing; - - private ModuleRevisionId _parentId; - - private boolean _transitive = true; - - /** - * This namespace should be used to check - */ - private Namespace _namespace = null; - - private final ModuleDescriptor _md; - - private DependencyDescriptor _asSystem = this; - - public DefaultDependencyDescriptor(DependencyDescriptor dd, String revision) { - _md = null; - _parentId = dd.getParentRevisionId(); - _revId = ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), revision); - _force = dd.isForce(); - _changing = dd.isChanging(); - _transitive = dd.isTransitive(); - String[] moduleConfs = dd.getModuleConfigurations(); - for (int i = 0; i < moduleConfs.length; i++) { - _confs.put(moduleConfs[i], new ArrayList(Arrays.asList(dd - .getDependencyConfigurations(moduleConfs[i])))); - _excludeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd - .getExcludeRules(moduleConfs[i])))); - _includeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd - .getIncludeRules(moduleConfs[i])))); - } - } - - public DefaultDependencyDescriptor(ModuleDescriptor md, ModuleRevisionId mrid, boolean force, - boolean changing, boolean transitive) { - _md = md; - _revId = mrid; - _force = force; - _changing = changing; - _transitive = transitive; - } - - public DefaultDependencyDescriptor(ModuleRevisionId mrid, boolean force) { - this(mrid, force, false); - } - - public DefaultDependencyDescriptor(ModuleRevisionId mrid, boolean force, boolean changing) { - _md = null; - _revId = mrid; - _force = force; - _changing = changing; - } - - public ModuleId getDependencyId() { - return getDependencyRevisionId().getModuleId(); - } - - public ModuleRevisionId getDependencyRevisionId() { - return _revId; - } - - public String[] getModuleConfigurations() { - return (String[]) _confs.keySet().toArray(new String[_confs.keySet().size()]); - } - - public String[] getDependencyConfigurations(String moduleConfiguration) { - return getDependencyConfigurations(moduleConfiguration, moduleConfiguration); - } - - /** - * Return the dependency configurations mapped to the given moduleConfiguration, actually - * resolved because of the given requestedConfiguration Usually requestedConfiguration and - * moduleConfiguration are the same, except when a conf extends another, then the - * moduleConfiguration is the configuration currently resolved (the extended one), and - * requestedConfiguration is the one actually requested initially (the extending one). Both - * moduleConfiguration and requestedConfiguration are configurations of the caller, the array - * returned is composed of the required configurations of the dependency described by this - * descriptor. - */ - public String[] getDependencyConfigurations(String moduleConfiguration, - String requestedConfiguration) { - List confs = (List) _confs.get(moduleConfiguration); - if (confs == null) { - // there is no mapping defined for this configuration, add the 'other' mappings. - confs = (List) _confs.get("%"); - } - List defConfs = (List) _confs.get("*"); - Collection ret = new LinkedHashSet(); - if (confs != null) { - ret.addAll(confs); - } - if (defConfs != null) { - ret.addAll(defConfs); - } - - Collection replacedRet = new LinkedHashSet(); - for (Iterator iter = ret.iterator(); iter.hasNext();) { - String c = (String) iter.next(); - String replacedConf = replaceSelfFallbackPattern(c, moduleConfiguration); - if (replacedConf == null) { - replacedConf = replaceThisFallbackPattern(c, requestedConfiguration); - } - if (replacedConf != null) { - c = replacedConf; - } - replacedRet.add(c); - } - ret = replacedRet; - if (ret.remove("*")) { - StringBuffer r = new StringBuffer("*"); - // merge excluded configurations as one conf like *!A!B - for (Iterator iter = ret.iterator(); iter.hasNext();) { - String c = (String) iter.next(); - if (c.startsWith("!")) { - r.append(c); - } - } - return new String[] {r.toString()}; - } - return (String[]) ret.toArray(new String[ret.size()]); - } - - protected static String replaceSelfFallbackPattern(final String conf, - final String moduleConfiguration) { - return replaceFallbackConfigurationPattern(SELF_FALLBACK_PATTERN, conf, moduleConfiguration); - } - - protected static String replaceThisFallbackPattern(final String conf, - final String requestedConfiguration) { - return replaceFallbackConfigurationPattern(THIS_FALLBACK_PATTERN, conf, - requestedConfiguration); - } - - /** - * Replaces fallback patterns with correct values if fallback pattern exists. - * - * @param pattern - * pattern to look for - * @param conf - * configuration mapping from dependency element - * @param moduleConfiguration - * module's configuration to use for replacement - * @return Replaced string if pattern matched. Otherwise null. - */ - protected static String replaceFallbackConfigurationPattern(final Pattern pattern, - final String conf, final String moduleConfiguration) { - Matcher matcher = pattern.matcher(conf); - if (matcher.matches()) { - if (matcher.group(1) != null) { - return moduleConfiguration + matcher.group(1); - } else { - return moduleConfiguration; - } - } - return null; - } - - public String[] getDependencyConfigurations(String[] moduleConfigurations) { - Set confs = new LinkedHashSet(); - for (int i = 0; i < moduleConfigurations.length; i++) { - confs.addAll(Arrays.asList(getDependencyConfigurations(moduleConfigurations[i]))); - } - if (confs.contains("*")) { - return new String[] {"*"}; - } - return (String[]) confs.toArray(new String[confs.size()]); - } - - public DependencyArtifactDescriptor[] getDependencyArtifacts(String moduleConfiguration) { - Collection artifacts = getCollectionForConfiguration(moduleConfiguration, - _dependencyArtifacts); - return (DependencyArtifactDescriptor[]) artifacts - .toArray(new DependencyArtifactDescriptor[artifacts.size()]); - } - - public IncludeRule[] getIncludeRules(String moduleConfiguration) { - Collection rules = getCollectionForConfiguration(moduleConfiguration, _includeRules); - return (IncludeRule[]) rules.toArray(new IncludeRule[rules.size()]); - } - - public ExcludeRule[] getExcludeRules(String moduleConfiguration) { - Collection rules = getCollectionForConfiguration(moduleConfiguration, _excludeRules); - return (ExcludeRule[]) rules.toArray(new ExcludeRule[rules.size()]); - } - - private Set getCollectionForConfiguration(String moduleConfiguration, Map collectionMap) { - if (collectionMap.isEmpty()) { - return Collections.EMPTY_SET; - } - Collection artifacts = (Collection) collectionMap.get(moduleConfiguration); - Collection defArtifacts = (Collection) collectionMap.get("*"); - Set ret = new LinkedHashSet(); - if (artifacts != null) { - ret.addAll(artifacts); - } - if (defArtifacts != null) { - ret.addAll(defArtifacts); - } - return ret; - } - - public DependencyArtifactDescriptor[] getDependencyArtifacts(String[] moduleConfigurations) { - Set artifacts = new LinkedHashSet(); - for (int i = 0; i < moduleConfigurations.length; i++) { - artifacts.addAll(Arrays.asList(getDependencyArtifacts(moduleConfigurations[i]))); - } - return (DependencyArtifactDescriptor[]) artifacts - .toArray(new DependencyArtifactDescriptor[artifacts.size()]); - } - - public IncludeRule[] getIncludeRules(String[] moduleConfigurations) { - Set rules = new LinkedHashSet(); - for (int i = 0; i < moduleConfigurations.length; i++) { - rules.addAll(Arrays.asList(getIncludeRules(moduleConfigurations[i]))); - } - return (IncludeRule[]) rules.toArray(new IncludeRule[rules.size()]); - } - - public ExcludeRule[] getExcludeRules(String[] moduleConfigurations) { - Set rules = new LinkedHashSet(); - for (int i = 0; i < moduleConfigurations.length; i++) { - rules.addAll(Arrays.asList(getExcludeRules(moduleConfigurations[i]))); - } - return (ExcludeRule[]) rules.toArray(new ExcludeRule[rules.size()]); - } - - public DependencyArtifactDescriptor[] getAllDependencyArtifacts() { - Set ret = mergeAll(_dependencyArtifacts); - return (DependencyArtifactDescriptor[]) ret.toArray(new DependencyArtifactDescriptor[ret - .size()]); - } - - public IncludeRule[] getAllIncludeRules() { - Set ret = mergeAll(_includeRules); - return (IncludeRule[]) ret.toArray(new IncludeRule[ret.size()]); - } - - public ExcludeRule[] getAllExcludeRules() { - Set ret = mergeAll(_excludeRules); - return (ExcludeRule[]) ret.toArray(new ExcludeRule[ret.size()]); - } - - private Set mergeAll(Map artifactsMap) { - Set ret = new LinkedHashSet(); - for (Iterator it = artifactsMap.values().iterator(); it.hasNext();) { - Collection artifacts = (Collection) it.next(); - ret.addAll(artifacts); - } - return ret; - } - - public void addDependencyConfiguration(String masterConf, String depConf) { - if ((_md != null) && !"*".equals(masterConf) && !"%".equals(masterConf)) { - Configuration config = _md.getConfiguration(masterConf); - if (config == null) { - throw new IllegalArgumentException("Configuration '" + masterConf - + "' does not exist in module " + _md); - } - } - - List confs = (List) _confs.get(masterConf); - if (confs == null) { - confs = new ArrayList(); - _confs.put(masterConf, confs); - } - if (!confs.contains(depConf)) { - confs.add(depConf); - } - } - - public void addDependencyArtifact(String masterConf, DependencyArtifactDescriptor dad) { - addObjectToConfiguration(masterConf, dad, _dependencyArtifacts); - } - - public void addIncludeRule(String masterConf, IncludeRule rule) { - addObjectToConfiguration(masterConf, rule, _includeRules); - } - - public void addExcludeRule(String masterConf, ExcludeRule rule) { - addObjectToConfiguration(masterConf, rule, _excludeRules); - } - - private void addObjectToConfiguration(String callerConf, Object toAdd, Map confsMap) { - Collection col = (Collection) confsMap.get(callerConf); - if (col == null) { - col = new ArrayList(); - confsMap.put(callerConf, col); - } - col.add(toAdd); - } - - /** - * only works when namespace is properly set. The behaviour is not specified if namespace is not - * set - */ - public boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId) { - if (_namespace != null) { - artifactId = NameSpaceHelper.transform(artifactId, _namespace - .getFromSystemTransformer()); - } - ExcludeRule[] rules = getExcludeRules(moduleConfigurations); - for (int i = 0; i < rules.length; i++) { - if (MatcherHelper.matches(rules[i].getMatcher(), rules[i].getId(), artifactId)) { - return true; - } - } - return false; - } - - /** - * Returns true if this descriptor contains any exclusion rule - * - * @return - */ - public boolean canExclude() { - return !_excludeRules.isEmpty(); - } - - public void addExtends(String conf) { - _extends.add(conf); - } - - public String toString() { - return "dependency: " + _revId + " " + _confs; - } - - public boolean isForce() { - return _force; - } - - public ModuleRevisionId getParentRevisionId() { - return _md != null ? _md.getResolvedModuleRevisionId() : _parentId; - } - - public boolean isChanging() { - return _changing; - } - - public boolean isTransitive() { - return _transitive; - } - - public Namespace getNamespace() { - return _namespace; - } - - public String getAttribute(String attName) { - return _revId.getAttribute(attName); - } - - public Map getAttributes() { - return _revId.getAttributes(); - } - - public String getExtraAttribute(String attName) { - return _revId.getExtraAttribute(attName); - } - - public Map getExtraAttributes() { - return _revId.getExtraAttributes(); - } - - public String getStandardAttribute(String attName) { - return _revId.getStandardAttribute(attName); - } - - public Map getStandardAttributes() { - return _revId.getStandardAttributes(); - } - - public DependencyDescriptor asSystem() { - return _asSystem; - } - -} +/* + * 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.core.module.descriptor; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.matcher.MatcherHelper; +import org.apache.ivy.plugins.namespace.NameSpaceHelper; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.plugins.namespace.NamespaceTransformer; + +/** + * This class can be used as the default implementation for DependencyDescriptor. It implements + * required methods and enables to fill dependency information with the addDependencyConfiguration + * method. + */ +public class DefaultDependencyDescriptor implements DependencyDescriptor { + private static final Pattern SELF_FALLBACK_PATTERN = Pattern.compile("@(\\(.*\\))?"); + + private static final Pattern THIS_FALLBACK_PATTERN = Pattern.compile("#(\\(.*\\))?"); + + /** + * Transforms the given dependency descriptor of the given namespace and return a new dependency + * descriptor in the system namespace. Note that exclude rules are not converted in system + * namespace, because they aren't transformable (the name space hasn't the ability to convert + * regular expressions). However, method doesExclude will work with system artifacts. + * + * @param md + * @param ns + * @return + */ + public static DependencyDescriptor transformInstance(DependencyDescriptor dd, Namespace ns) { + NamespaceTransformer t = ns.getToSystemTransformer(); + if (t.isIdentity()) { + return dd; + } + DefaultDependencyDescriptor newdd = transformInstance(dd, t, false); + newdd._namespace = ns; + return newdd; + } + + /** + * Transforms a dependency descriptor using the given transformer. Note that no namespace info + * will be attached to the transformed dependency descriptor, so calling doesExclude is not + * recommended (doesExclude only works when namespace is properly set) + * + * @param dd + * @param t + * @return + */ + public static DefaultDependencyDescriptor transformInstance(DependencyDescriptor dd, + NamespaceTransformer t, boolean fromSystem) { + ModuleRevisionId transformParentId = t.transform(dd.getParentRevisionId()); + ModuleRevisionId transformMrid = t.transform(dd.getDependencyRevisionId()); + DefaultDependencyDescriptor newdd = new DefaultDependencyDescriptor(null, transformMrid, dd + .isForce(), dd.isChanging(), dd.isTransitive()); + newdd._parentId = transformParentId; + String[] moduleConfs = dd.getModuleConfigurations(); + if (moduleConfs.length == 1 && "*".equals(moduleConfs[0])) { + if (dd instanceof DefaultDependencyDescriptor) { + DefaultDependencyDescriptor ddd = (DefaultDependencyDescriptor) dd; + newdd._confs = new LinkedHashMap(ddd._confs); + newdd._excludeRules = new LinkedHashMap(ddd._excludeRules); + newdd._includeRules = new LinkedHashMap(ddd._includeRules); + newdd._dependencyArtifacts = new LinkedHashMap(ddd._dependencyArtifacts); + } else { + throw new IllegalArgumentException( + "dependency descriptor transformation does not support * module confs with descriptors which aren't DefaultDependencyDescriptor"); + } + } else { + for (int i = 0; i < moduleConfs.length; i++) { + newdd._confs.put(moduleConfs[i], new ArrayList(Arrays.asList(dd + .getDependencyConfigurations(moduleConfs[i])))); + newdd._excludeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd + .getExcludeRules(moduleConfs[i])))); + newdd._includeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd + .getIncludeRules(moduleConfs[i])))); + newdd._dependencyArtifacts.put(moduleConfs[i], new ArrayList(Arrays.asList(dd + .getDependencyArtifacts(moduleConfs[i])))); + } + } + if (fromSystem) { + newdd._asSystem = dd; + } + return newdd; + } + + private ModuleRevisionId _revId; + + private Map _confs = new LinkedHashMap(); + + private Map _dependencyArtifacts = new LinkedHashMap(); // Map (String masterConf -> + + // Collection(DependencyArtifactDescriptor)) + + private Map _includeRules = new LinkedHashMap(); // Map (String masterConf -> + + // Collection(IncludeRule)) + + private Map _excludeRules = new LinkedHashMap(); // Map (String masterConf -> + + // Collection(ExcludeRule)) + + private Set _extends = new LinkedHashSet(); + + /** + * Used to indicate that this revision must be used in case of conflicts, independently of + * conflicts manager + */ + private boolean _force; + + /** + * Used to indicate that the dependency is a changing one, i.e. that ivy should not rely on the + * version to know if it can trust artifacts in cache + */ + private boolean _changing; + + private ModuleRevisionId _parentId; + + private boolean _transitive = true; + + /** + * This namespace should be used to check + */ + private Namespace _namespace = null; + + private final ModuleDescriptor _md; + + private DependencyDescriptor _asSystem = this; + + public DefaultDependencyDescriptor(DependencyDescriptor dd, String revision) { + _md = null; + _parentId = dd.getParentRevisionId(); + _revId = ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), revision); + _force = dd.isForce(); + _changing = dd.isChanging(); + _transitive = dd.isTransitive(); + String[] moduleConfs = dd.getModuleConfigurations(); + for (int i = 0; i < moduleConfs.length; i++) { + _confs.put(moduleConfs[i], new ArrayList(Arrays.asList(dd + .getDependencyConfigurations(moduleConfs[i])))); + _excludeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd + .getExcludeRules(moduleConfs[i])))); + _includeRules.put(moduleConfs[i], new ArrayList(Arrays.asList(dd + .getIncludeRules(moduleConfs[i])))); + } + } + + public DefaultDependencyDescriptor(ModuleDescriptor md, ModuleRevisionId mrid, boolean force, + boolean changing, boolean transitive) { + _md = md; + _revId = mrid; + _force = force; + _changing = changing; + _transitive = transitive; + } + + public DefaultDependencyDescriptor(ModuleRevisionId mrid, boolean force) { + this(mrid, force, false); + } + + public DefaultDependencyDescriptor(ModuleRevisionId mrid, boolean force, boolean changing) { + _md = null; + _revId = mrid; + _force = force; + _changing = changing; + } + + public ModuleId getDependencyId() { + return getDependencyRevisionId().getModuleId(); + } + + public ModuleRevisionId getDependencyRevisionId() { + return _revId; + } + + public String[] getModuleConfigurations() { + return (String[]) _confs.keySet().toArray(new String[_confs.keySet().size()]); + } + + public String[] getDependencyConfigurations(String moduleConfiguration) { + return getDependencyConfigurations(moduleConfiguration, moduleConfiguration); + } + + /** + * Return the dependency configurations mapped to the given moduleConfiguration, actually + * resolved because of the given requestedConfiguration Usually requestedConfiguration and + * moduleConfiguration are the same, except when a conf extends another, then the + * moduleConfiguration is the configuration currently resolved (the extended one), and + * requestedConfiguration is the one actually requested initially (the extending one). Both + * moduleConfiguration and requestedConfiguration are configurations of the caller, the array + * returned is composed of the required configurations of the dependency described by this + * descriptor. + */ + public String[] getDependencyConfigurations(String moduleConfiguration, + String requestedConfiguration) { + List confs = (List) _confs.get(moduleConfiguration); + if (confs == null) { + // there is no mapping defined for this configuration, add the 'other' mappings. + confs = (List) _confs.get("%"); + } + List defConfs = (List) _confs.get("*"); + Collection ret = new LinkedHashSet(); + if (confs != null) { + ret.addAll(confs); + } + if (defConfs != null) { + ret.addAll(defConfs); + } + + Collection replacedRet = new LinkedHashSet(); + for (Iterator iter = ret.iterator(); iter.hasNext();) { + String c = (String) iter.next(); + String replacedConf = replaceSelfFallbackPattern(c, moduleConfiguration); + if (replacedConf == null) { + replacedConf = replaceThisFallbackPattern(c, requestedConfiguration); + } + if (replacedConf != null) { + c = replacedConf; + } + replacedRet.add(c); + } + ret = replacedRet; + if (ret.remove("*")) { + StringBuffer r = new StringBuffer("*"); + // merge excluded configurations as one conf like *!A!B + for (Iterator iter = ret.iterator(); iter.hasNext();) { + String c = (String) iter.next(); + if (c.startsWith("!")) { + r.append(c); + } + } + return new String[] {r.toString()}; + } + return (String[]) ret.toArray(new String[ret.size()]); + } + + protected static String replaceSelfFallbackPattern(final String conf, + final String moduleConfiguration) { + return replaceFallbackConfigurationPattern(SELF_FALLBACK_PATTERN, conf, moduleConfiguration); + } + + protected static String replaceThisFallbackPattern(final String conf, + final String requestedConfiguration) { + return replaceFallbackConfigurationPattern(THIS_FALLBACK_PATTERN, conf, + requestedConfiguration); + } + + /** + * Replaces fallback patterns with correct values if fallback pattern exists. + * + * @param pattern + * pattern to look for + * @param conf + * configuration mapping from dependency element + * @param moduleConfiguration + * module's configuration to use for replacement + * @return Replaced string if pattern matched. Otherwise null. + */ + protected static String replaceFallbackConfigurationPattern(final Pattern pattern, + final String conf, final String moduleConfiguration) { + Matcher matcher = pattern.matcher(conf); + if (matcher.matches()) { + if (matcher.group(1) != null) { + return moduleConfiguration + matcher.group(1); + } else { + return moduleConfiguration; + } + } + return null; + } + + public String[] getDependencyConfigurations(String[] moduleConfigurations) { + Set confs = new LinkedHashSet(); + for (int i = 0; i < moduleConfigurations.length; i++) { + confs.addAll(Arrays.asList(getDependencyConfigurations(moduleConfigurations[i]))); + } + if (confs.contains("*")) { + return new String[] {"*"}; + } + return (String[]) confs.toArray(new String[confs.size()]); + } + + public DependencyArtifactDescriptor[] getDependencyArtifacts(String moduleConfiguration) { + Collection artifacts = getCollectionForConfiguration(moduleConfiguration, + _dependencyArtifacts); + return (DependencyArtifactDescriptor[]) artifacts + .toArray(new DependencyArtifactDescriptor[artifacts.size()]); + } + + public IncludeRule[] getIncludeRules(String moduleConfiguration) { + Collection rules = getCollectionForConfiguration(moduleConfiguration, _includeRules); + return (IncludeRule[]) rules.toArray(new IncludeRule[rules.size()]); + } + + public ExcludeRule[] getExcludeRules(String moduleConfiguration) { + Collection rules = getCollectionForConfiguration(moduleConfiguration, _excludeRules); + return (ExcludeRule[]) rules.toArray(new ExcludeRule[rules.size()]); + } + + private Set getCollectionForConfiguration(String moduleConfiguration, Map collectionMap) { + if (collectionMap.isEmpty()) { + return Collections.EMPTY_SET; + } + Collection artifacts = (Collection) collectionMap.get(moduleConfiguration); + Collection defArtifacts = (Collection) collectionMap.get("*"); + Set ret = new LinkedHashSet(); + if (artifacts != null) { + ret.addAll(artifacts); + } + if (defArtifacts != null) { + ret.addAll(defArtifacts); + } + return ret; + } + + public DependencyArtifactDescriptor[] getDependencyArtifacts(String[] moduleConfigurations) { + Set artifacts = new LinkedHashSet(); + for (int i = 0; i < moduleConfigurations.length; i++) { + artifacts.addAll(Arrays.asList(getDependencyArtifacts(moduleConfigurations[i]))); + } + return (DependencyArtifactDescriptor[]) artifacts + .toArray(new DependencyArtifactDescriptor[artifacts.size()]); + } + + public IncludeRule[] getIncludeRules(String[] moduleConfigurations) { + Set rules = new LinkedHashSet(); + for (int i = 0; i < moduleConfigurations.length; i++) { + rules.addAll(Arrays.asList(getIncludeRules(moduleConfigurations[i]))); + } + return (IncludeRule[]) rules.toArray(new IncludeRule[rules.size()]); + } + + public ExcludeRule[] getExcludeRules(String[] moduleConfigurations) { + Set rules = new LinkedHashSet(); + for (int i = 0; i < moduleConfigurations.length; i++) { + rules.addAll(Arrays.asList(getExcludeRules(moduleConfigurations[i]))); + } + return (ExcludeRule[]) rules.toArray(new ExcludeRule[rules.size()]); + } + + public DependencyArtifactDescriptor[] getAllDependencyArtifacts() { + Set ret = mergeAll(_dependencyArtifacts); + return (DependencyArtifactDescriptor[]) ret.toArray(new DependencyArtifactDescriptor[ret + .size()]); + } + + public IncludeRule[] getAllIncludeRules() { + Set ret = mergeAll(_includeRules); + return (IncludeRule[]) ret.toArray(new IncludeRule[ret.size()]); + } + + public ExcludeRule[] getAllExcludeRules() { + Set ret = mergeAll(_excludeRules); + return (ExcludeRule[]) ret.toArray(new ExcludeRule[ret.size()]); + } + + private Set mergeAll(Map artifactsMap) { + Set ret = new LinkedHashSet(); + for (Iterator it = artifactsMap.values().iterator(); it.hasNext();) { + Collection artifacts = (Collection) it.next(); + ret.addAll(artifacts); + } + return ret; + } + + public void addDependencyConfiguration(String masterConf, String depConf) { + if ((_md != null) && !"*".equals(masterConf) && !"%".equals(masterConf)) { + Configuration config = _md.getConfiguration(masterConf); + if (config == null) { + throw new IllegalArgumentException("Configuration '" + masterConf + + "' does not exist in module " + _md); + } + } + + List confs = (List) _confs.get(masterConf); + if (confs == null) { + confs = new ArrayList(); + _confs.put(masterConf, confs); + } + if (!confs.contains(depConf)) { + confs.add(depConf); + } + } + + public void addDependencyArtifact(String masterConf, DependencyArtifactDescriptor dad) { + addObjectToConfiguration(masterConf, dad, _dependencyArtifacts); + } + + public void addIncludeRule(String masterConf, IncludeRule rule) { + addObjectToConfiguration(masterConf, rule, _includeRules); + } + + public void addExcludeRule(String masterConf, ExcludeRule rule) { + addObjectToConfiguration(masterConf, rule, _excludeRules); + } + + private void addObjectToConfiguration(String callerConf, Object toAdd, Map confsMap) { + Collection col = (Collection) confsMap.get(callerConf); + if (col == null) { + col = new ArrayList(); + confsMap.put(callerConf, col); + } + col.add(toAdd); + } + + /** + * only works when namespace is properly set. The behaviour is not specified if namespace is not + * set + */ + public boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId) { + if (_namespace != null) { + artifactId = NameSpaceHelper.transform(artifactId, _namespace + .getFromSystemTransformer()); + } + ExcludeRule[] rules = getExcludeRules(moduleConfigurations); + for (int i = 0; i < rules.length; i++) { + if (MatcherHelper.matches(rules[i].getMatcher(), rules[i].getId(), artifactId)) { + return true; + } + } + return false; + } + + /** + * Returns true if this descriptor contains any exclusion rule + * + * @return + */ + public boolean canExclude() { + return !_excludeRules.isEmpty(); + } + + public void addExtends(String conf) { + _extends.add(conf); + } + + public String toString() { + return "dependency: " + _revId + " " + _confs; + } + + public boolean isForce() { + return _force; + } + + public ModuleRevisionId getParentRevisionId() { + return _md != null ? _md.getResolvedModuleRevisionId() : _parentId; + } + + public boolean isChanging() { + return _changing; + } + + public boolean isTransitive() { + return _transitive; + } + + public Namespace getNamespace() { + return _namespace; + } + + public String getAttribute(String attName) { + return _revId.getAttribute(attName); + } + + public Map getAttributes() { + return _revId.getAttributes(); + } + + public String getExtraAttribute(String attName) { + return _revId.getExtraAttribute(attName); + } + + public Map getExtraAttributes() { + return _revId.getExtraAttributes(); + } + + public String getStandardAttribute(String attName) { + return _revId.getStandardAttribute(attName); + } + + public Map getStandardAttributes() { + return _revId.getStandardAttributes(); + } + + public DependencyDescriptor asSystem() { + return _asSystem; + } + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DefaultExcludeRule.java b/src/java/org/apache/ivy/core/module/descriptor/DefaultExcludeRule.java index 55a6a3d8..52acf82f 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DefaultExcludeRule.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DefaultExcludeRule.java @@ -1,34 +1,34 @@ -/* - * 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.core.module.descriptor; - -import java.util.Map; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.plugins.matcher.PatternMatcher; - -public class DefaultExcludeRule extends AbstractIncludeExcludeRule implements ExcludeRule { - - public DefaultExcludeRule(ArtifactId aid, PatternMatcher matcher, Map extraAttributes) { - super(aid, matcher, extraAttributes); - } - - public String toString() { - return "E:" + super.toString(); - } -} +/* + * 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.core.module.descriptor; + +import java.util.Map; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.plugins.matcher.PatternMatcher; + +public class DefaultExcludeRule extends AbstractIncludeExcludeRule implements ExcludeRule { + + public DefaultExcludeRule(ArtifactId aid, PatternMatcher matcher, Map extraAttributes) { + super(aid, matcher, extraAttributes); + } + + public String toString() { + return "E:" + super.toString(); + } +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DefaultIncludeRule.java b/src/java/org/apache/ivy/core/module/descriptor/DefaultIncludeRule.java index 24657f6c..87ddc586 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DefaultIncludeRule.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DefaultIncludeRule.java @@ -1,34 +1,34 @@ -/* - * 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.core.module.descriptor; - -import java.util.Map; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.plugins.matcher.PatternMatcher; - -public class DefaultIncludeRule extends AbstractIncludeExcludeRule implements IncludeRule { - - public DefaultIncludeRule(ArtifactId aid, PatternMatcher matcher, Map extraAttributes) { - super(aid, matcher, extraAttributes); - } - - public String toString() { - return "I:" + super.toString(); - } -} +/* + * 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.core.module.descriptor; + +import java.util.Map; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.plugins.matcher.PatternMatcher; + +public class DefaultIncludeRule extends AbstractIncludeExcludeRule implements IncludeRule { + + public DefaultIncludeRule(ArtifactId aid, PatternMatcher matcher, Map extraAttributes) { + super(aid, matcher, extraAttributes); + } + + public String toString() { + return "I:" + super.toString(); + } +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java index cf68b119..29e1f56d 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java @@ -1,594 +1,594 @@ -/* - * 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.core.module.descriptor; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.module.status.StatusManager; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.matcher.MatcherHelper; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.namespace.NameSpaceHelper; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.plugins.namespace.NamespaceTransformer; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.version.VersionMatcher; -import org.apache.ivy.util.Message; - -/** - * - */ -public class DefaultModuleDescriptor implements ModuleDescriptor { - - public static DefaultModuleDescriptor newDefaultInstance(ModuleRevisionId mrid) { - return newDefaultInstance(mrid, null); - } - - public static DefaultModuleDescriptor newCallerInstance(ModuleRevisionId mrid, String[] confs, - boolean transitive, boolean changing) { - DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(ModuleRevisionId - .newInstance(mrid.getOrganisation(), mrid.getName() + "-caller", "working"), - "integration", null, true); - for (int i = 0; i < confs.length; i++) { - moduleDescriptor.addConfiguration(new Configuration(confs[i])); - } - moduleDescriptor.setLastModified(System.currentTimeMillis()); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(moduleDescriptor, mrid, - true, changing, transitive); - for (int j = 0; j < confs.length; j++) { - dd.addDependencyConfiguration(confs[j], confs[j]); - } - moduleDescriptor.addDependency(dd); - - return moduleDescriptor; - } - - public static DefaultModuleDescriptor newCallerInstance(ModuleRevisionId[] mrid, - boolean transitive, boolean changing) { - DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(ModuleRevisionId - .newInstance("caller", "all-caller", "working"), "integration", null, true); - moduleDescriptor.addConfiguration(new Configuration(DEFAULT_CONFIGURATION)); - moduleDescriptor.setLastModified(System.currentTimeMillis()); - for (int i = 0; i < mrid.length; i++) { - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(moduleDescriptor, - mrid[i], true, changing, transitive); - dd.addDependencyConfiguration(DEFAULT_CONFIGURATION, "*"); - moduleDescriptor.addDependency(dd); - } - - return moduleDescriptor; - } - - public static DefaultModuleDescriptor newDefaultInstance(ModuleRevisionId mrid, - DependencyArtifactDescriptor[] artifacts) { - DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(mrid, "release", - null, true); - moduleDescriptor.addConfiguration(new Configuration(DEFAULT_CONFIGURATION)); - if (artifacts != null && artifacts.length > 0) { - for (int i = 0; i < artifacts.length; i++) { - moduleDescriptor.addArtifact(DEFAULT_CONFIGURATION, new MDArtifact( - moduleDescriptor, artifacts[i].getName(), artifacts[i].getType(), - artifacts[i].getExt(), artifacts[i].getUrl(), null)); - } - } else { - moduleDescriptor.addArtifact(DEFAULT_CONFIGURATION, new MDArtifact(moduleDescriptor, - mrid.getName(), "jar", "jar")); - } - moduleDescriptor.setLastModified(System.currentTimeMillis()); - return moduleDescriptor; - } - - public static DefaultModuleDescriptor newBasicInstance(ModuleRevisionId mrid, - Date publicationDate) { - DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(mrid, "release", - publicationDate, false); - moduleDescriptor.addConfiguration(new Configuration(DEFAULT_CONFIGURATION)); - moduleDescriptor.addArtifact(DEFAULT_CONFIGURATION, new MDArtifact(moduleDescriptor, mrid - .getName(), "jar", "jar")); - return moduleDescriptor; - } - - /** - * Transforms the given module descriptor of the given namespace and return a new module - * descriptor in the system namespace. Note that dependency exclude rules are not converted - * in system namespace, because they aren't transformable (the name space hasn't the ability to - * convert regular expressions) - * - * @param md - * @param ns - * @return - */ - public static ModuleDescriptor transformInstance(ModuleDescriptor md, Namespace ns) { - NamespaceTransformer t = ns.getToSystemTransformer(); - if (t.isIdentity()) { - return md; - } - DefaultModuleDescriptor nmd = new DefaultModuleDescriptor(md.getParser(), md.getResource()); - nmd._revId = t.transform(md.getModuleRevisionId()); - nmd._resolvedRevId = t.transform(md.getResolvedModuleRevisionId()); - nmd._status = md.getStatus(); - nmd._publicationDate = md.getPublicationDate(); - nmd._resolvedPublicationDate = md.getResolvedPublicationDate(); - DependencyDescriptor[] dd = md.getDependencies(); - for (int i = 0; i < dd.length; i++) { - nmd._dependencies.add(NameSpaceHelper.toSystem(dd[i], ns)); - } - Configuration[] confs = md.getConfigurations(); - for (int i = 0; i < confs.length; i++) { - nmd._configurations.put(confs[i].getName(), confs[i]); - Artifact[] arts = md.getArtifacts(confs[i].getName()); - for (int j = 0; j < arts.length; j++) { - nmd.addArtifact(confs[i].getName(), NameSpaceHelper.transform(arts[j], t)); - } - } - nmd.setDefault(md.isDefault()); - if (md instanceof DefaultModuleDescriptor) { - DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md; - nmd._conflictManagers.putAll(dmd._conflictManagers); - } else { - Message - .warn("transformed module descriptor is not a default module descriptor: impossible to copy conflict manager configuration: " - + md); - } - nmd._licenses.addAll(Arrays.asList(md.getLicenses())); - nmd._homePage = md.getHomePage(); - nmd._lastModified = md.getLastModified(); - nmd._namespace = ns; - - return nmd; - } - - private ModuleRevisionId _revId; - - private ModuleRevisionId _resolvedRevId; - - private String _status = StatusManager.getCurrent().getDefaultStatus(); - - private Date _publicationDate; - - private Date _resolvedPublicationDate; - - private List _dependencies = new ArrayList(); // List (DependencyDescriptor) - - private Map _configurations = new LinkedHashMap(); // Map(String conf -> Configuration) - - private Map _artifactsByConf = new HashMap(); // Map (String conf -> Collection(Artifact)) - - private Collection _artifacts = new LinkedHashSet(); // Collection(Artifact) // all artifacts - - // could also be found in the - // artifactsByConf map, but here we can - // preserve the order - - private boolean _isDefault = false; - - private Map _conflictManagers = new LinkedHashMap(); // Map (ModuleId -> ) - - private List _licenses = new ArrayList(); // List(License) - - private String _homePage; - - private long _lastModified = 0; - - private Namespace _namespace; - - private boolean _mappingOverride; - - private ModuleDescriptorParser _parser; - - private Resource _resource; - - private List _excludeRules = new ArrayList(); // List(ExcludeRule) - - public DefaultModuleDescriptor(ModuleRevisionId id, String status, Date pubDate) { - this(id, status, pubDate, false); - } - - public DefaultModuleDescriptor(ModuleRevisionId id, String status, Date pubDate, - boolean isDefault) { - if (id == null) { - throw new NullPointerException("null module revision id not allowed"); - } - if (status == null) { - throw new NullPointerException("null status not allowed"); - } - _revId = id; - _resolvedRevId = id; - _status = status; - _publicationDate = pubDate; - _resolvedPublicationDate = _publicationDate == null ? new Date() : _publicationDate; - _isDefault = isDefault; - } - - /** - * IMPORTANT : at least call setModuleRevisionId and setResolvedPublicationDate with instances - * created by this constructor ! - */ - public DefaultModuleDescriptor(ModuleDescriptorParser parser, Resource res) { - _parser = parser; - _resource = res; - } - - public boolean isDefault() { - return _isDefault; - } - - public void setPublicationDate(Date publicationDate) { - _publicationDate = publicationDate; - if (_resolvedPublicationDate == null) { - _resolvedPublicationDate = _publicationDate == null ? new Date() : _publicationDate; - } - } - - public Date getPublicationDate() { - return _publicationDate; - } - - public void setResolvedPublicationDate(Date publicationDate) { - if (publicationDate == null) { - throw new NullPointerException("null publication date not allowed"); - } - _resolvedPublicationDate = publicationDate; - } - - public Date getResolvedPublicationDate() { - return _resolvedPublicationDate; - } - - public void setModuleRevisionId(ModuleRevisionId revId) { - if (revId == null) { - throw new NullPointerException("null module revision id not allowed"); - } - _revId = revId; - if (_resolvedRevId == null) { - _resolvedRevId = _revId; - } - } - - public void setResolvedModuleRevisionId(ModuleRevisionId revId) { - _resolvedRevId = revId; - } - - public void setStatus(String status) { - _status = status; - } - - public void addDependency(DependencyDescriptor dependency) { - _dependencies.add(dependency); - } - - public void addConfiguration(Configuration conf) { - _configurations.put(conf.getName(), conf); - } - - /** - * Artifact configurations are not used since added artifact may not be entirely completed, so - * its configurations data may not be accurate - * - * @param conf - * @param artifact - */ - public void addArtifact(String conf, Artifact artifact) { - if (!_configurations.containsKey(conf)) { - throw new IllegalArgumentException("Configuration '" + conf - + "' doesn't exist in module " + this); - } - - Collection artifacts = (Collection) _artifactsByConf.get(conf); - if (artifacts == null) { - artifacts = new ArrayList(); - _artifactsByConf.put(conf, artifacts); - } - artifacts.add(artifact); - _artifacts.add(artifact); - } - - public ModuleRevisionId getModuleRevisionId() { - return _revId; - } - - public ModuleRevisionId getResolvedModuleRevisionId() { - return _resolvedRevId; - } - - public String getStatus() { - return _status; - } - - public Configuration[] getConfigurations() { - return (Configuration[]) _configurations.values().toArray( - new Configuration[_configurations.size()]); - } - - public String[] getConfigurationsNames() { - return (String[]) _configurations.keySet().toArray(new String[_configurations.size()]); - } - - public String[] getPublicConfigurationsNames() { - List ret = new ArrayList(); - for (Iterator iter = _configurations.values().iterator(); iter.hasNext();) { - Configuration conf = (Configuration) iter.next(); - if (conf.getVisibility() == Configuration.Visibility.PUBLIC) { - ret.add(conf.getName()); - } - } - return (String[]) ret.toArray(new String[ret.size()]); - } - - /** - * Returns the configuration object with the given name in the current module descriptor, null - * if not found. - */ - public Configuration getConfiguration(String confName) { - return (Configuration) _configurations.get(confName); - } - - public Artifact[] getArtifacts(String conf) { - Collection artifacts = (Collection) _artifactsByConf.get(conf); - if (artifacts == null) { - return new Artifact[0]; - } else { - return (Artifact[]) artifacts.toArray(new Artifact[artifacts.size()]); - } - } - - public Artifact[] getAllArtifacts() { - return (Artifact[]) _artifacts.toArray(new Artifact[_artifacts.size()]); - } - - public DependencyDescriptor[] getDependencies() { - return (DependencyDescriptor[]) _dependencies - .toArray(new DependencyDescriptor[_dependencies.size()]); - } - - public boolean dependsOn(VersionMatcher matcher, ModuleDescriptor md) { - for (Iterator iter = _dependencies.iterator(); iter.hasNext();) { - DependencyDescriptor dd = (DependencyDescriptor) iter.next(); - if (dd.getDependencyId().equals(md.getModuleRevisionId().getModuleId())) { - if (md.getResolvedModuleRevisionId().getRevision() == null) { - return true; - } else if (matcher.accept(dd.getDependencyRevisionId(), md)) { - return true; - } - } - } - return false; - } - - public void toIvyFile(File destFile) throws ParseException, IOException { - if (_parser != null && _resource != null) { - _parser.toIvyFile(_resource.openStream(), _resource, destFile, this); - } else { - XmlModuleDescriptorWriter.write(this, destFile); - } - } - - public String toString() { - return "module: " + _revId + " status=" + _status + " publication=" + _publicationDate - + " configurations=" + _configurations + " artifacts=" + _artifactsByConf - + " dependencies=" + _dependencies; - } - - public void setDefault(boolean b) { - _isDefault = b; - } - - private static class ModuleIdMatcher { - private PatternMatcher _matcher; - - private ModuleId _mid; - - public ModuleIdMatcher(PatternMatcher matcher, ModuleId mid) { - _matcher = matcher; - _mid = mid; - } - - public boolean matches(ModuleId mid) { - return MatcherHelper.matches(_matcher, _mid, mid); - } - } - - /** - * regular expressions as explained in Pattern class may be used in ModuleId organisation and - * name - * - * @param moduleId - * @param matcher - * @param resolverName - */ - public void addConflictManager(ModuleId moduleId, PatternMatcher matcher, - ConflictManager manager) { - _conflictManagers.put(new ModuleIdMatcher(matcher, moduleId), manager); - } - - public ConflictManager getConflictManager(ModuleId moduleId) { - for (Iterator iter = _conflictManagers.keySet().iterator(); iter.hasNext();) { - ModuleIdMatcher matcher = (ModuleIdMatcher) iter.next(); - if (matcher.matches(moduleId)) { - return (ConflictManager) _conflictManagers.get(matcher); - } - } - return null; - } - - public void addLicense(License license) { - _licenses.add(license); - } - - public License[] getLicenses() { - return (License[]) _licenses.toArray(new License[_licenses.size()]); - } - - public String getHomePage() { - return _homePage; - } - - public void setHomePage(String homePage) { - _homePage = homePage; - } - - public long getLastModified() { - return _lastModified; - } - - public void setLastModified(long lastModified) { - _lastModified = lastModified; - } - - public Namespace getNamespace() { - if (_namespace == null || !isNamespaceUseful()) { - return null; - } - return _namespace; - } - - public boolean isNamespaceUseful() { - for (Iterator iter = _dependencies.iterator(); iter.hasNext();) { - DependencyDescriptor dd = (DependencyDescriptor) iter.next(); - if (dd.getAllExcludeRules().length > 0) { - return true; - } - } - return false; - } - - public void setNamespace(Namespace ns) { - _namespace = ns; - } - - /** - * Throws an exception if the module descriptor is inconsistent For the moment, only extended - * configurations existence is checked - */ - public void check() { - for (Iterator iter = _configurations.values().iterator(); iter.hasNext();) { - Configuration conf = (Configuration) iter.next(); - String[] ext = conf.getExtends(); - for (int i = 0; i < ext.length; i++) { - if (!_configurations.containsKey(ext[i].trim())) { - throw new IllegalStateException("unknown configuration '" + ext[i] - + "'. It is extended by " + conf.getName()); - } - } - } - } - - public void setMappingOverride(boolean override) { - _mappingOverride = override; - } - - public boolean isMappingOverride() { - return _mappingOverride; - } - - public String getAttribute(String attName) { - return _resolvedRevId.getAttribute(attName); - } - - public Map getAttributes() { - return _resolvedRevId.getAttributes(); - } - - public String getExtraAttribute(String attName) { - return _resolvedRevId.getExtraAttribute(attName); - } - - public Map getExtraAttributes() { - return _resolvedRevId.getExtraAttributes(); - } - - public String getStandardAttribute(String attName) { - return _resolvedRevId.getStandardAttribute(attName); - } - - public Map getStandardAttributes() { - return _resolvedRevId.getStandardAttributes(); - } - - public ModuleDescriptorParser getParser() { - return _parser; - } - - public Resource getResource() { - return _resource; - } - - public void addExcludeRule(ExcludeRule rule) { - _excludeRules.add(rule); - } - - public boolean canExclude() { - return !_excludeRules.isEmpty(); - } - - /** - * only works when namespace is properly set. The behaviour is not specified if namespace is not - * set - */ - public boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId) { - if (_namespace != null) { - artifactId = NameSpaceHelper.transform(artifactId, _namespace - .getFromSystemTransformer()); - } - ExcludeRule[] rules = getExcludeRules(moduleConfigurations); - for (int i = 0; i < rules.length; i++) { - if (MatcherHelper.matches(rules[i].getMatcher(), rules[i].getId(), artifactId)) { - return true; - } - } - return false; - } - - public ExcludeRule[] getAllExcludeRules() { - return (ExcludeRule[]) _excludeRules.toArray(new ExcludeRule[_excludeRules.size()]); - } - - public ExcludeRule[] getExcludeRules(String[] moduleConfigurations) { - Set rules = new LinkedHashSet(); - for (Iterator iter = _excludeRules.iterator(); iter.hasNext();) { - ExcludeRule rule = (ExcludeRule) iter.next(); - String[] ruleConfs = rule.getConfigurations(); - if (containsAny(ruleConfs, moduleConfigurations)) { - rules.add(rule); - } - } - return (ExcludeRule[]) rules.toArray(new ExcludeRule[rules.size()]); - } - - private boolean containsAny(String[] arr1, String[] arr2) { - return new ArrayList(Arrays.asList(arr1)).removeAll(Arrays.asList(arr2)); - } -} +/* + * 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.core.module.descriptor; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.module.status.StatusManager; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.matcher.MatcherHelper; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.namespace.NameSpaceHelper; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.plugins.namespace.NamespaceTransformer; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.version.VersionMatcher; +import org.apache.ivy.util.Message; + +/** + * + */ +public class DefaultModuleDescriptor implements ModuleDescriptor { + + public static DefaultModuleDescriptor newDefaultInstance(ModuleRevisionId mrid) { + return newDefaultInstance(mrid, null); + } + + public static DefaultModuleDescriptor newCallerInstance(ModuleRevisionId mrid, String[] confs, + boolean transitive, boolean changing) { + DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(ModuleRevisionId + .newInstance(mrid.getOrganisation(), mrid.getName() + "-caller", "working"), + "integration", null, true); + for (int i = 0; i < confs.length; i++) { + moduleDescriptor.addConfiguration(new Configuration(confs[i])); + } + moduleDescriptor.setLastModified(System.currentTimeMillis()); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(moduleDescriptor, mrid, + true, changing, transitive); + for (int j = 0; j < confs.length; j++) { + dd.addDependencyConfiguration(confs[j], confs[j]); + } + moduleDescriptor.addDependency(dd); + + return moduleDescriptor; + } + + public static DefaultModuleDescriptor newCallerInstance(ModuleRevisionId[] mrid, + boolean transitive, boolean changing) { + DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(ModuleRevisionId + .newInstance("caller", "all-caller", "working"), "integration", null, true); + moduleDescriptor.addConfiguration(new Configuration(DEFAULT_CONFIGURATION)); + moduleDescriptor.setLastModified(System.currentTimeMillis()); + for (int i = 0; i < mrid.length; i++) { + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(moduleDescriptor, + mrid[i], true, changing, transitive); + dd.addDependencyConfiguration(DEFAULT_CONFIGURATION, "*"); + moduleDescriptor.addDependency(dd); + } + + return moduleDescriptor; + } + + public static DefaultModuleDescriptor newDefaultInstance(ModuleRevisionId mrid, + DependencyArtifactDescriptor[] artifacts) { + DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(mrid, "release", + null, true); + moduleDescriptor.addConfiguration(new Configuration(DEFAULT_CONFIGURATION)); + if (artifacts != null && artifacts.length > 0) { + for (int i = 0; i < artifacts.length; i++) { + moduleDescriptor.addArtifact(DEFAULT_CONFIGURATION, new MDArtifact( + moduleDescriptor, artifacts[i].getName(), artifacts[i].getType(), + artifacts[i].getExt(), artifacts[i].getUrl(), null)); + } + } else { + moduleDescriptor.addArtifact(DEFAULT_CONFIGURATION, new MDArtifact(moduleDescriptor, + mrid.getName(), "jar", "jar")); + } + moduleDescriptor.setLastModified(System.currentTimeMillis()); + return moduleDescriptor; + } + + public static DefaultModuleDescriptor newBasicInstance(ModuleRevisionId mrid, + Date publicationDate) { + DefaultModuleDescriptor moduleDescriptor = new DefaultModuleDescriptor(mrid, "release", + publicationDate, false); + moduleDescriptor.addConfiguration(new Configuration(DEFAULT_CONFIGURATION)); + moduleDescriptor.addArtifact(DEFAULT_CONFIGURATION, new MDArtifact(moduleDescriptor, mrid + .getName(), "jar", "jar")); + return moduleDescriptor; + } + + /** + * Transforms the given module descriptor of the given namespace and return a new module + * descriptor in the system namespace. Note that dependency exclude rules are not converted + * in system namespace, because they aren't transformable (the name space hasn't the ability to + * convert regular expressions) + * + * @param md + * @param ns + * @return + */ + public static ModuleDescriptor transformInstance(ModuleDescriptor md, Namespace ns) { + NamespaceTransformer t = ns.getToSystemTransformer(); + if (t.isIdentity()) { + return md; + } + DefaultModuleDescriptor nmd = new DefaultModuleDescriptor(md.getParser(), md.getResource()); + nmd._revId = t.transform(md.getModuleRevisionId()); + nmd._resolvedRevId = t.transform(md.getResolvedModuleRevisionId()); + nmd._status = md.getStatus(); + nmd._publicationDate = md.getPublicationDate(); + nmd._resolvedPublicationDate = md.getResolvedPublicationDate(); + DependencyDescriptor[] dd = md.getDependencies(); + for (int i = 0; i < dd.length; i++) { + nmd._dependencies.add(NameSpaceHelper.toSystem(dd[i], ns)); + } + Configuration[] confs = md.getConfigurations(); + for (int i = 0; i < confs.length; i++) { + nmd._configurations.put(confs[i].getName(), confs[i]); + Artifact[] arts = md.getArtifacts(confs[i].getName()); + for (int j = 0; j < arts.length; j++) { + nmd.addArtifact(confs[i].getName(), NameSpaceHelper.transform(arts[j], t)); + } + } + nmd.setDefault(md.isDefault()); + if (md instanceof DefaultModuleDescriptor) { + DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md; + nmd._conflictManagers.putAll(dmd._conflictManagers); + } else { + Message + .warn("transformed module descriptor is not a default module descriptor: impossible to copy conflict manager configuration: " + + md); + } + nmd._licenses.addAll(Arrays.asList(md.getLicenses())); + nmd._homePage = md.getHomePage(); + nmd._lastModified = md.getLastModified(); + nmd._namespace = ns; + + return nmd; + } + + private ModuleRevisionId _revId; + + private ModuleRevisionId _resolvedRevId; + + private String _status = StatusManager.getCurrent().getDefaultStatus(); + + private Date _publicationDate; + + private Date _resolvedPublicationDate; + + private List _dependencies = new ArrayList(); // List (DependencyDescriptor) + + private Map _configurations = new LinkedHashMap(); // Map(String conf -> Configuration) + + private Map _artifactsByConf = new HashMap(); // Map (String conf -> Collection(Artifact)) + + private Collection _artifacts = new LinkedHashSet(); // Collection(Artifact) // all artifacts + + // could also be found in the + // artifactsByConf map, but here we can + // preserve the order + + private boolean _isDefault = false; + + private Map _conflictManagers = new LinkedHashMap(); // Map (ModuleId -> ) + + private List _licenses = new ArrayList(); // List(License) + + private String _homePage; + + private long _lastModified = 0; + + private Namespace _namespace; + + private boolean _mappingOverride; + + private ModuleDescriptorParser _parser; + + private Resource _resource; + + private List _excludeRules = new ArrayList(); // List(ExcludeRule) + + public DefaultModuleDescriptor(ModuleRevisionId id, String status, Date pubDate) { + this(id, status, pubDate, false); + } + + public DefaultModuleDescriptor(ModuleRevisionId id, String status, Date pubDate, + boolean isDefault) { + if (id == null) { + throw new NullPointerException("null module revision id not allowed"); + } + if (status == null) { + throw new NullPointerException("null status not allowed"); + } + _revId = id; + _resolvedRevId = id; + _status = status; + _publicationDate = pubDate; + _resolvedPublicationDate = _publicationDate == null ? new Date() : _publicationDate; + _isDefault = isDefault; + } + + /** + * IMPORTANT : at least call setModuleRevisionId and setResolvedPublicationDate with instances + * created by this constructor ! + */ + public DefaultModuleDescriptor(ModuleDescriptorParser parser, Resource res) { + _parser = parser; + _resource = res; + } + + public boolean isDefault() { + return _isDefault; + } + + public void setPublicationDate(Date publicationDate) { + _publicationDate = publicationDate; + if (_resolvedPublicationDate == null) { + _resolvedPublicationDate = _publicationDate == null ? new Date() : _publicationDate; + } + } + + public Date getPublicationDate() { + return _publicationDate; + } + + public void setResolvedPublicationDate(Date publicationDate) { + if (publicationDate == null) { + throw new NullPointerException("null publication date not allowed"); + } + _resolvedPublicationDate = publicationDate; + } + + public Date getResolvedPublicationDate() { + return _resolvedPublicationDate; + } + + public void setModuleRevisionId(ModuleRevisionId revId) { + if (revId == null) { + throw new NullPointerException("null module revision id not allowed"); + } + _revId = revId; + if (_resolvedRevId == null) { + _resolvedRevId = _revId; + } + } + + public void setResolvedModuleRevisionId(ModuleRevisionId revId) { + _resolvedRevId = revId; + } + + public void setStatus(String status) { + _status = status; + } + + public void addDependency(DependencyDescriptor dependency) { + _dependencies.add(dependency); + } + + public void addConfiguration(Configuration conf) { + _configurations.put(conf.getName(), conf); + } + + /** + * Artifact configurations are not used since added artifact may not be entirely completed, so + * its configurations data may not be accurate + * + * @param conf + * @param artifact + */ + public void addArtifact(String conf, Artifact artifact) { + if (!_configurations.containsKey(conf)) { + throw new IllegalArgumentException("Configuration '" + conf + + "' doesn't exist in module " + this); + } + + Collection artifacts = (Collection) _artifactsByConf.get(conf); + if (artifacts == null) { + artifacts = new ArrayList(); + _artifactsByConf.put(conf, artifacts); + } + artifacts.add(artifact); + _artifacts.add(artifact); + } + + public ModuleRevisionId getModuleRevisionId() { + return _revId; + } + + public ModuleRevisionId getResolvedModuleRevisionId() { + return _resolvedRevId; + } + + public String getStatus() { + return _status; + } + + public Configuration[] getConfigurations() { + return (Configuration[]) _configurations.values().toArray( + new Configuration[_configurations.size()]); + } + + public String[] getConfigurationsNames() { + return (String[]) _configurations.keySet().toArray(new String[_configurations.size()]); + } + + public String[] getPublicConfigurationsNames() { + List ret = new ArrayList(); + for (Iterator iter = _configurations.values().iterator(); iter.hasNext();) { + Configuration conf = (Configuration) iter.next(); + if (conf.getVisibility() == Configuration.Visibility.PUBLIC) { + ret.add(conf.getName()); + } + } + return (String[]) ret.toArray(new String[ret.size()]); + } + + /** + * Returns the configuration object with the given name in the current module descriptor, null + * if not found. + */ + public Configuration getConfiguration(String confName) { + return (Configuration) _configurations.get(confName); + } + + public Artifact[] getArtifacts(String conf) { + Collection artifacts = (Collection) _artifactsByConf.get(conf); + if (artifacts == null) { + return new Artifact[0]; + } else { + return (Artifact[]) artifacts.toArray(new Artifact[artifacts.size()]); + } + } + + public Artifact[] getAllArtifacts() { + return (Artifact[]) _artifacts.toArray(new Artifact[_artifacts.size()]); + } + + public DependencyDescriptor[] getDependencies() { + return (DependencyDescriptor[]) _dependencies + .toArray(new DependencyDescriptor[_dependencies.size()]); + } + + public boolean dependsOn(VersionMatcher matcher, ModuleDescriptor md) { + for (Iterator iter = _dependencies.iterator(); iter.hasNext();) { + DependencyDescriptor dd = (DependencyDescriptor) iter.next(); + if (dd.getDependencyId().equals(md.getModuleRevisionId().getModuleId())) { + if (md.getResolvedModuleRevisionId().getRevision() == null) { + return true; + } else if (matcher.accept(dd.getDependencyRevisionId(), md)) { + return true; + } + } + } + return false; + } + + public void toIvyFile(File destFile) throws ParseException, IOException { + if (_parser != null && _resource != null) { + _parser.toIvyFile(_resource.openStream(), _resource, destFile, this); + } else { + XmlModuleDescriptorWriter.write(this, destFile); + } + } + + public String toString() { + return "module: " + _revId + " status=" + _status + " publication=" + _publicationDate + + " configurations=" + _configurations + " artifacts=" + _artifactsByConf + + " dependencies=" + _dependencies; + } + + public void setDefault(boolean b) { + _isDefault = b; + } + + private static class ModuleIdMatcher { + private PatternMatcher _matcher; + + private ModuleId _mid; + + public ModuleIdMatcher(PatternMatcher matcher, ModuleId mid) { + _matcher = matcher; + _mid = mid; + } + + public boolean matches(ModuleId mid) { + return MatcherHelper.matches(_matcher, _mid, mid); + } + } + + /** + * regular expressions as explained in Pattern class may be used in ModuleId organisation and + * name + * + * @param moduleId + * @param matcher + * @param resolverName + */ + public void addConflictManager(ModuleId moduleId, PatternMatcher matcher, + ConflictManager manager) { + _conflictManagers.put(new ModuleIdMatcher(matcher, moduleId), manager); + } + + public ConflictManager getConflictManager(ModuleId moduleId) { + for (Iterator iter = _conflictManagers.keySet().iterator(); iter.hasNext();) { + ModuleIdMatcher matcher = (ModuleIdMatcher) iter.next(); + if (matcher.matches(moduleId)) { + return (ConflictManager) _conflictManagers.get(matcher); + } + } + return null; + } + + public void addLicense(License license) { + _licenses.add(license); + } + + public License[] getLicenses() { + return (License[]) _licenses.toArray(new License[_licenses.size()]); + } + + public String getHomePage() { + return _homePage; + } + + public void setHomePage(String homePage) { + _homePage = homePage; + } + + public long getLastModified() { + return _lastModified; + } + + public void setLastModified(long lastModified) { + _lastModified = lastModified; + } + + public Namespace getNamespace() { + if (_namespace == null || !isNamespaceUseful()) { + return null; + } + return _namespace; + } + + public boolean isNamespaceUseful() { + for (Iterator iter = _dependencies.iterator(); iter.hasNext();) { + DependencyDescriptor dd = (DependencyDescriptor) iter.next(); + if (dd.getAllExcludeRules().length > 0) { + return true; + } + } + return false; + } + + public void setNamespace(Namespace ns) { + _namespace = ns; + } + + /** + * Throws an exception if the module descriptor is inconsistent For the moment, only extended + * configurations existence is checked + */ + public void check() { + for (Iterator iter = _configurations.values().iterator(); iter.hasNext();) { + Configuration conf = (Configuration) iter.next(); + String[] ext = conf.getExtends(); + for (int i = 0; i < ext.length; i++) { + if (!_configurations.containsKey(ext[i].trim())) { + throw new IllegalStateException("unknown configuration '" + ext[i] + + "'. It is extended by " + conf.getName()); + } + } + } + } + + public void setMappingOverride(boolean override) { + _mappingOverride = override; + } + + public boolean isMappingOverride() { + return _mappingOverride; + } + + public String getAttribute(String attName) { + return _resolvedRevId.getAttribute(attName); + } + + public Map getAttributes() { + return _resolvedRevId.getAttributes(); + } + + public String getExtraAttribute(String attName) { + return _resolvedRevId.getExtraAttribute(attName); + } + + public Map getExtraAttributes() { + return _resolvedRevId.getExtraAttributes(); + } + + public String getStandardAttribute(String attName) { + return _resolvedRevId.getStandardAttribute(attName); + } + + public Map getStandardAttributes() { + return _resolvedRevId.getStandardAttributes(); + } + + public ModuleDescriptorParser getParser() { + return _parser; + } + + public Resource getResource() { + return _resource; + } + + public void addExcludeRule(ExcludeRule rule) { + _excludeRules.add(rule); + } + + public boolean canExclude() { + return !_excludeRules.isEmpty(); + } + + /** + * only works when namespace is properly set. The behaviour is not specified if namespace is not + * set + */ + public boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId) { + if (_namespace != null) { + artifactId = NameSpaceHelper.transform(artifactId, _namespace + .getFromSystemTransformer()); + } + ExcludeRule[] rules = getExcludeRules(moduleConfigurations); + for (int i = 0; i < rules.length; i++) { + if (MatcherHelper.matches(rules[i].getMatcher(), rules[i].getId(), artifactId)) { + return true; + } + } + return false; + } + + public ExcludeRule[] getAllExcludeRules() { + return (ExcludeRule[]) _excludeRules.toArray(new ExcludeRule[_excludeRules.size()]); + } + + public ExcludeRule[] getExcludeRules(String[] moduleConfigurations) { + Set rules = new LinkedHashSet(); + for (Iterator iter = _excludeRules.iterator(); iter.hasNext();) { + ExcludeRule rule = (ExcludeRule) iter.next(); + String[] ruleConfs = rule.getConfigurations(); + if (containsAny(ruleConfs, moduleConfigurations)) { + rules.add(rule); + } + } + return (ExcludeRule[]) rules.toArray(new ExcludeRule[rules.size()]); + } + + private boolean containsAny(String[] arr1, String[] arr2) { + return new ArrayList(Arrays.asList(arr1)).removeAll(Arrays.asList(arr2)); + } +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DependencyArtifactDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/DependencyArtifactDescriptor.java index 0b9cbec3..e5ce7b50 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DependencyArtifactDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DependencyArtifactDescriptor.java @@ -1,63 +1,63 @@ -/* - * 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.core.module.descriptor; - -import java.net.URL; - -import org.apache.ivy.util.extendable.ExtendableItem; - -/** - * This describes an artifact that is asked for a dependency. It is used to define an (additional) - * artifact not declared by a dependency module descriptor. - */ -public interface DependencyArtifactDescriptor extends ExtendableItem { - /** - * Returns the name of the artifact asked - * - * @return - */ - public String getName(); - - /** - * Returns the type of the artifact asked - * - * @return - */ - public String getType(); - - /** - * Returns the ext of the artifact asked - * - * @return - */ - public String getExt(); - - /** - * Returns the url to look this artifact at - * - * @return - */ - public URL getUrl(); - - /** - * Returns the configurations of the module in which the artifact is asked - * - * @return an array of configuration names in which the artifact is asked - */ - public String[] getConfigurations(); -} +/* + * 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.core.module.descriptor; + +import java.net.URL; + +import org.apache.ivy.util.extendable.ExtendableItem; + +/** + * This describes an artifact that is asked for a dependency. It is used to define an (additional) + * artifact not declared by a dependency module descriptor. + */ +public interface DependencyArtifactDescriptor extends ExtendableItem { + /** + * Returns the name of the artifact asked + * + * @return + */ + public String getName(); + + /** + * Returns the type of the artifact asked + * + * @return + */ + public String getType(); + + /** + * Returns the ext of the artifact asked + * + * @return + */ + public String getExt(); + + /** + * Returns the url to look this artifact at + * + * @return + */ + public URL getUrl(); + + /** + * Returns the configurations of the module in which the artifact is asked + * + * @return an array of configuration names in which the artifact is asked + */ + public String[] getConfigurations(); +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/DependencyDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/DependencyDescriptor.java index 17f57617..7278f92d 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DependencyDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DependencyDescriptor.java @@ -1,101 +1,101 @@ -/* - * 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.core.module.descriptor; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.util.extendable.ExtendableItem; - -/** - * - */ -public interface DependencyDescriptor extends ExtendableItem { - ModuleId getDependencyId(); - - /** - * Used to indicate that this revision must be used in case of conflicts, independently of - * conflicts manager. This only works for direct dependencies, and not transitive ones. - * - * @return true if this dependency should be used, false if conflicts manager can do its work. - */ - boolean isForce(); - - /** - * Used to indicate that this dependency is a changing one. A changing dependency in ivy means - * that the revision may have its artifacts modified without revision change. When new artifacts - * are published a new ivy file should also be published with a new publication date to indicate - * to ivy that artifacts have changed and that they should be downloaded again. - * - * @return true if this dependency is a changing one - */ - boolean isChanging(); - - boolean isTransitive(); - - ModuleRevisionId getParentRevisionId(); - - ModuleRevisionId getDependencyRevisionId(); - - String[] getModuleConfigurations(); - - String[] getDependencyConfigurations(String moduleConfiguration, String requestedConfiguration); - - String[] getDependencyConfigurations(String moduleConfiguration); - - String[] getDependencyConfigurations(String[] moduleConfigurations); - - Namespace getNamespace(); - - DependencyArtifactDescriptor[] getAllDependencyArtifacts(); - - DependencyArtifactDescriptor[] getDependencyArtifacts(String moduleConfigurations); - - DependencyArtifactDescriptor[] getDependencyArtifacts(String[] moduleConfigurations); - - IncludeRule[] getAllIncludeRules(); - - IncludeRule[] getIncludeRules(String moduleConfigurations); - - IncludeRule[] getIncludeRules(String[] moduleConfigurations); - - ExcludeRule[] getAllExcludeRules(); - - ExcludeRule[] getExcludeRules(String moduleConfigurations); - - ExcludeRule[] getExcludeRules(String[] moduleConfigurations); - - /** - * Returns true if - * - * @param moduleConfigurations - * @param artifactId - * @return - */ - boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId); - - /** - * Returns true if this descriptor contains any exclusion rule - * - * @return true if this descriptor contains any exclusion rule - */ - public boolean canExclude(); - - DependencyDescriptor asSystem(); -} +/* + * 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.core.module.descriptor; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.util.extendable.ExtendableItem; + +/** + * + */ +public interface DependencyDescriptor extends ExtendableItem { + ModuleId getDependencyId(); + + /** + * Used to indicate that this revision must be used in case of conflicts, independently of + * conflicts manager. This only works for direct dependencies, and not transitive ones. + * + * @return true if this dependency should be used, false if conflicts manager can do its work. + */ + boolean isForce(); + + /** + * Used to indicate that this dependency is a changing one. A changing dependency in ivy means + * that the revision may have its artifacts modified without revision change. When new artifacts + * are published a new ivy file should also be published with a new publication date to indicate + * to ivy that artifacts have changed and that they should be downloaded again. + * + * @return true if this dependency is a changing one + */ + boolean isChanging(); + + boolean isTransitive(); + + ModuleRevisionId getParentRevisionId(); + + ModuleRevisionId getDependencyRevisionId(); + + String[] getModuleConfigurations(); + + String[] getDependencyConfigurations(String moduleConfiguration, String requestedConfiguration); + + String[] getDependencyConfigurations(String moduleConfiguration); + + String[] getDependencyConfigurations(String[] moduleConfigurations); + + Namespace getNamespace(); + + DependencyArtifactDescriptor[] getAllDependencyArtifacts(); + + DependencyArtifactDescriptor[] getDependencyArtifacts(String moduleConfigurations); + + DependencyArtifactDescriptor[] getDependencyArtifacts(String[] moduleConfigurations); + + IncludeRule[] getAllIncludeRules(); + + IncludeRule[] getIncludeRules(String moduleConfigurations); + + IncludeRule[] getIncludeRules(String[] moduleConfigurations); + + ExcludeRule[] getAllExcludeRules(); + + ExcludeRule[] getExcludeRules(String moduleConfigurations); + + ExcludeRule[] getExcludeRules(String[] moduleConfigurations); + + /** + * Returns true if + * + * @param moduleConfigurations + * @param artifactId + * @return + */ + boolean doesExclude(String[] moduleConfigurations, ArtifactId artifactId); + + /** + * Returns true if this descriptor contains any exclusion rule + * + * @return true if this descriptor contains any exclusion rule + */ + public boolean canExclude(); + + DependencyDescriptor asSystem(); +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/ExcludeRule.java b/src/java/org/apache/ivy/core/module/descriptor/ExcludeRule.java index 1f53ea58..0d7cc1be 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/ExcludeRule.java +++ b/src/java/org/apache/ivy/core/module/descriptor/ExcludeRule.java @@ -1,50 +1,50 @@ -/* - * 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.core.module.descriptor; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.util.extendable.ExtendableItem; - -/** - * This describes a rule of exclusion. It is used to resctrict the artifacts asked for a dependency, - * by excluding a whole module or some artifacts of a dependency. - */ -public interface ExcludeRule extends ExtendableItem { - - /** - * Returns the id of the described artifact, without revision information - * - * @return - */ - public ArtifactId getId(); - - /** - * Returns the configurations of the module in which the artifact is asked - * - * @return an array of configuration names in which the artifact is asked - */ - public String[] getConfigurations(); - - /** - * Returns the matcher to use to know if an artifact match the current descriptor - * - * @return - */ - public PatternMatcher getMatcher(); -} +/* + * 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.core.module.descriptor; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.util.extendable.ExtendableItem; + +/** + * This describes a rule of exclusion. It is used to resctrict the artifacts asked for a dependency, + * by excluding a whole module or some artifacts of a dependency. + */ +public interface ExcludeRule extends ExtendableItem { + + /** + * Returns the id of the described artifact, without revision information + * + * @return + */ + public ArtifactId getId(); + + /** + * Returns the configurations of the module in which the artifact is asked + * + * @return an array of configuration names in which the artifact is asked + */ + public String[] getConfigurations(); + + /** + * Returns the matcher to use to know if an artifact match the current descriptor + * + * @return + */ + public PatternMatcher getMatcher(); +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/IncludeRule.java b/src/java/org/apache/ivy/core/module/descriptor/IncludeRule.java index 1c15ea2f..7cbeada1 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/IncludeRule.java +++ b/src/java/org/apache/ivy/core/module/descriptor/IncludeRule.java @@ -1,51 +1,51 @@ -/* - * 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.core.module.descriptor; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.util.extendable.ExtendableItem; - -/** - * This describes a rule of inclusion. It is used to resctrict the artifacts and modules asked for a - * dependency, by including only modules and artifacts matching the rule - */ -public interface IncludeRule extends ExtendableItem { - - /** - * Returns the id of the described artifact, without revision information - * - * @return - */ - public ArtifactId getId(); - - /** - * Returns the configurations of the module in which the artifact is asked - * - * @return an array of configuration names in which the artifact is asked - */ - public String[] getConfigurations(); - - /** - * Returns the matcher to use to know if an artifact match the current descriptor - * - * @return - */ - public PatternMatcher getMatcher(); - -} +/* + * 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.core.module.descriptor; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.util.extendable.ExtendableItem; + +/** + * This describes a rule of inclusion. It is used to resctrict the artifacts and modules asked for a + * dependency, by including only modules and artifacts matching the rule + */ +public interface IncludeRule extends ExtendableItem { + + /** + * Returns the id of the described artifact, without revision information + * + * @return + */ + public ArtifactId getId(); + + /** + * Returns the configurations of the module in which the artifact is asked + * + * @return an array of configuration names in which the artifact is asked + */ + public String[] getConfigurations(); + + /** + * Returns the matcher to use to know if an artifact match the current descriptor + * + * @return + */ + public PatternMatcher getMatcher(); + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/License.java b/src/java/org/apache/ivy/core/module/descriptor/License.java index 68338a50..db1c823b 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/License.java +++ b/src/java/org/apache/ivy/core/module/descriptor/License.java @@ -1,38 +1,38 @@ -/* - * 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.core.module.descriptor; - -public class License { - private String name; - - private String url; - - public License(String name, String url) { - this.name = name; - this.url = url; - } - - public String getName() { - return name; - } - - public String getUrl() { - return url; - } - -} +/* + * 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.core.module.descriptor; + +public class License { + private String name; + + private String url; + + public License(String name, String url) { + this.name = name; + this.url = url; + } + + public String getName() { + return name; + } + + public String getUrl() { + return url; + } + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/MDArtifact.java b/src/java/org/apache/ivy/core/module/descriptor/MDArtifact.java index 94843afb..5d78701e 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/MDArtifact.java +++ b/src/java/org/apache/ivy/core/module/descriptor/MDArtifact.java @@ -1,120 +1,120 @@ -/* - * 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.core.module.descriptor; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.module.id.ArtifactRevisionId; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -/** - * - */ -public class MDArtifact extends AbstractArtifact { - - public static Artifact newIvyArtifact(ModuleDescriptor md) { - return new MDArtifact(md, "ivy", "ivy", "xml"); - } - - private ModuleDescriptor md; - - private String name; - - private String type; - - private String ext; - - private List confs = new ArrayList(); - - private ArtifactRevisionId arid; - - private Map extraAttributes = null; - - private URL url; - - public MDArtifact(ModuleDescriptor md, String name, String type, String ext) { - this(md, name, type, ext, null, null); - } - - public MDArtifact(ModuleDescriptor md, String name, String type, String ext, URL url, - Map extraAttributes) { - if (md == null) { - throw new NullPointerException("null module descriptor not allowed"); - } - if (name == null) { - throw new NullPointerException("null name not allowed"); - } - if (type == null) { - throw new NullPointerException("null type not allowed"); - } - if (ext == null) { - throw new NullPointerException("null ext not allowed"); - } - this.md = md; - this.name = name; - this.type = type; - this.ext = ext; - this.url = url; - this.extraAttributes = extraAttributes; - } - - public ModuleRevisionId getModuleRevisionId() { - return md.getResolvedModuleRevisionId(); - } - - public Date getPublicationDate() { - return md.getResolvedPublicationDate(); - } - - public ArtifactRevisionId getId() { - if (arid == null) { - arid = ArtifactRevisionId.newInstance(md.getResolvedModuleRevisionId(), name, type, - ext, extraAttributes); - } - return arid; - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public String getExt() { - return ext; - } - - public String[] getConfigurations() { - return (String[]) confs.toArray(new String[confs.size()]); - } - - public void addConfiguration(String conf) { - confs.add(conf); - } - - public URL getUrl() { - return url; - } - -} +/* + * 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.core.module.descriptor; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.module.id.ArtifactRevisionId; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +/** + * + */ +public class MDArtifact extends AbstractArtifact { + + public static Artifact newIvyArtifact(ModuleDescriptor md) { + return new MDArtifact(md, "ivy", "ivy", "xml"); + } + + private ModuleDescriptor md; + + private String name; + + private String type; + + private String ext; + + private List confs = new ArrayList(); + + private ArtifactRevisionId arid; + + private Map extraAttributes = null; + + private URL url; + + public MDArtifact(ModuleDescriptor md, String name, String type, String ext) { + this(md, name, type, ext, null, null); + } + + public MDArtifact(ModuleDescriptor md, String name, String type, String ext, URL url, + Map extraAttributes) { + if (md == null) { + throw new NullPointerException("null module descriptor not allowed"); + } + if (name == null) { + throw new NullPointerException("null name not allowed"); + } + if (type == null) { + throw new NullPointerException("null type not allowed"); + } + if (ext == null) { + throw new NullPointerException("null ext not allowed"); + } + this.md = md; + this.name = name; + this.type = type; + this.ext = ext; + this.url = url; + this.extraAttributes = extraAttributes; + } + + public ModuleRevisionId getModuleRevisionId() { + return md.getResolvedModuleRevisionId(); + } + + public Date getPublicationDate() { + return md.getResolvedPublicationDate(); + } + + public ArtifactRevisionId getId() { + if (arid == null) { + arid = ArtifactRevisionId.newInstance(md.getResolvedModuleRevisionId(), name, type, + ext, extraAttributes); + } + return arid; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String getExt() { + return ext; + } + + public String[] getConfigurations() { + return (String[]) confs.toArray(new String[confs.size()]); + } + + public void addConfiguration(String conf) { + confs.add(conf); + } + + public URL getUrl() { + return url; + } + +} diff --git a/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java index 0daf10ca..3721eb6b 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/ModuleDescriptor.java @@ -1,198 +1,198 @@ -/* - * 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.core.module.descriptor; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.util.Date; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.version.VersionMatcher; -import org.apache.ivy.util.extendable.ExtendableItem; - -/** - * - */ -public interface ModuleDescriptor extends ExtendableItem { - public static final String DEFAULT_CONFIGURATION = "default"; - - public static final String CALLER_ALL_CONFIGURATION = "all"; - - /** - * Returns true if this descriptor is a default one, i.e. one generated for a module not - * actually having one. - * - * @return - */ - boolean isDefault(); - - ModuleRevisionId getModuleRevisionId(); - - /** - * The module revision id returned here is the resolved one, i.e. it is never a latest one. If - * the revision has not been resolved, a null revision should be returned by getRevision() of - * the returned ModuleRevisionId. This revision must be the same as the module descriptor - * resolved revision id unless no module descriptor is defined - * - * @return - */ - ModuleRevisionId getResolvedModuleRevisionId(); - - /** - * This method update the resolved module revision id - * - * @param revId - */ - void setResolvedModuleRevisionId(ModuleRevisionId revId); - - /** - * This method update the resolved publication date - * - * @param publicationDate - */ - void setResolvedPublicationDate(Date publicationDate); - - String getStatus(); - - /** - * may be null if unknown in the descriptor itself - * - * @return - */ - Date getPublicationDate(); - - /** - * the publication date of the module revision should be the date at which it has been - * published, i.e. in general the date of any of its published artifacts, since all published - * artifact of a module should follow the same publishing cycle. - */ - Date getResolvedPublicationDate(); - - /** - * Returns all the configurations declared by this module as an array. This array is never empty - * (a 'default' conf is assumed when none is declared in the ivy file) - * - * @return all the configurations declared by this module as an array. - */ - Configuration[] getConfigurations(); - - String[] getConfigurationsNames(); - - String[] getPublicConfigurationsNames(); - - Artifact[] getArtifacts(String conf); - - Artifact[] getAllArtifacts(); - - /** - * @retun The dependencies of the module. If there is no dependencies return an empty array (non - * null) - */ - DependencyDescriptor[] getDependencies(); - - /** - * Returns true if the module described by this descriptor dependes directly upon the given - * module descriptor - * - * @param md - * @return - */ - boolean dependsOn(VersionMatcher matcher, ModuleDescriptor md); - - /** - * @param confName - * @return - */ - Configuration getConfiguration(String confName); - - /** - * Returns the conflict manager to use for the given ModuleId - * - * @param id - * @return - */ - ConflictManager getConflictManager(ModuleId id); - - /** - * Returns the licenses of the module described by this descriptor - * - * @return - */ - License[] getLicenses(); - - String getHomePage(); - - long getLastModified(); - - /** - * Writes this module descriptor as an ivy file. If this descriptor was obtained through the - * parsing of an ivy file, it should keep the layout of the file the most possible similar to - * the original one. - * - * @param ivyFile - * the destination ivy file - */ - void toIvyFile(File ivyFile) throws ParseException, IOException; - - /** - * The ModuleDescriptorParser used to parse this module descriptor, null is no parser was used. - * - * @return - */ - ModuleDescriptorParser getParser(); - - /** - * The resource being the source of this module descriptor, null if no resource corresponds to - * this module descriptor - * - * @return - */ - Resource getResource(); - - /** - * Returns true if this descriptor contains any exclusion rule - * - * @return true if this descriptor contains any exclusion rule - */ - boolean canExclude(); - - /** - * Returns true if an exclude rule of this module attached to any of the given configurations - * matches the given artifact id, and thus exclude it - * - * @param moduleConfs - * @param artifactId - * @return - */ - boolean doesExclude(String[] moduleConfs, ArtifactId artifactId); - - /** - * Returns an array of all the exclude rules this module descriptor currently holds. Module - * Descriptor exclude rules are used to exclude (usually transitive) dependencies for the whole - * module. - * - * @return an array of {@link ExcludeRule} this module descriptor holds - */ - public ExcludeRule[] getAllExcludeRules(); -} +/* + * 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.core.module.descriptor; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import java.util.Date; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.version.VersionMatcher; +import org.apache.ivy.util.extendable.ExtendableItem; + +/** + * + */ +public interface ModuleDescriptor extends ExtendableItem { + public static final String DEFAULT_CONFIGURATION = "default"; + + public static final String CALLER_ALL_CONFIGURATION = "all"; + + /** + * Returns true if this descriptor is a default one, i.e. one generated for a module not + * actually having one. + * + * @return + */ + boolean isDefault(); + + ModuleRevisionId getModuleRevisionId(); + + /** + * The module revision id returned here is the resolved one, i.e. it is never a latest one. If + * the revision has not been resolved, a null revision should be returned by getRevision() of + * the returned ModuleRevisionId. This revision must be the same as the module descriptor + * resolved revision id unless no module descriptor is defined + * + * @return + */ + ModuleRevisionId getResolvedModuleRevisionId(); + + /** + * This method update the resolved module revision id + * + * @param revId + */ + void setResolvedModuleRevisionId(ModuleRevisionId revId); + + /** + * This method update the resolved publication date + * + * @param publicationDate + */ + void setResolvedPublicationDate(Date publicationDate); + + String getStatus(); + + /** + * may be null if unknown in the descriptor itself + * + * @return + */ + Date getPublicationDate(); + + /** + * the publication date of the module revision should be the date at which it has been + * published, i.e. in general the date of any of its published artifacts, since all published + * artifact of a module should follow the same publishing cycle. + */ + Date getResolvedPublicationDate(); + + /** + * Returns all the configurations declared by this module as an array. This array is never empty + * (a 'default' conf is assumed when none is declared in the ivy file) + * + * @return all the configurations declared by this module as an array. + */ + Configuration[] getConfigurations(); + + String[] getConfigurationsNames(); + + String[] getPublicConfigurationsNames(); + + Artifact[] getArtifacts(String conf); + + Artifact[] getAllArtifacts(); + + /** + * @retun The dependencies of the module. If there is no dependencies return an empty array (non + * null) + */ + DependencyDescriptor[] getDependencies(); + + /** + * Returns true if the module described by this descriptor dependes directly upon the given + * module descriptor + * + * @param md + * @return + */ + boolean dependsOn(VersionMatcher matcher, ModuleDescriptor md); + + /** + * @param confName + * @return + */ + Configuration getConfiguration(String confName); + + /** + * Returns the conflict manager to use for the given ModuleId + * + * @param id + * @return + */ + ConflictManager getConflictManager(ModuleId id); + + /** + * Returns the licenses of the module described by this descriptor + * + * @return + */ + License[] getLicenses(); + + String getHomePage(); + + long getLastModified(); + + /** + * Writes this module descriptor as an ivy file. If this descriptor was obtained through the + * parsing of an ivy file, it should keep the layout of the file the most possible similar to + * the original one. + * + * @param ivyFile + * the destination ivy file + */ + void toIvyFile(File ivyFile) throws ParseException, IOException; + + /** + * The ModuleDescriptorParser used to parse this module descriptor, null is no parser was used. + * + * @return + */ + ModuleDescriptorParser getParser(); + + /** + * The resource being the source of this module descriptor, null if no resource corresponds to + * this module descriptor + * + * @return + */ + Resource getResource(); + + /** + * Returns true if this descriptor contains any exclusion rule + * + * @return true if this descriptor contains any exclusion rule + */ + boolean canExclude(); + + /** + * Returns true if an exclude rule of this module attached to any of the given configurations + * matches the given artifact id, and thus exclude it + * + * @param moduleConfs + * @param artifactId + * @return + */ + boolean doesExclude(String[] moduleConfs, ArtifactId artifactId); + + /** + * Returns an array of all the exclude rules this module descriptor currently holds. Module + * Descriptor exclude rules are used to exclude (usually transitive) dependencies for the whole + * module. + * + * @return an array of {@link ExcludeRule} this module descriptor holds + */ + public ExcludeRule[] getAllExcludeRules(); +} diff --git a/src/java/org/apache/ivy/core/module/id/ArtifactId.java b/src/java/org/apache/ivy/core/module/id/ArtifactId.java index 5c834649..e7af0d34 100644 --- a/src/java/org/apache/ivy/core/module/id/ArtifactId.java +++ b/src/java/org/apache/ivy/core/module/id/ArtifactId.java @@ -1,92 +1,92 @@ -/* - * 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.core.module.id; - -/** - * Identifies an artifact in a module, without revision information - */ -public class ArtifactId { - private ModuleId mid; - - private String name; - - private String type; - - private String ext; - - /** - * @param mid - * @param name - * @param type - */ - public ArtifactId(ModuleId mid, String name, String type, String ext) { - this.mid = mid; - this.name = name; - this.type = type; - this.ext = ext; - } - - public boolean equals(Object obj) { - if (!(obj instanceof ArtifactId)) { - return false; - } - ArtifactId aid = (ArtifactId) obj; - return getModuleId().equals(aid.getModuleId()) && getName().equals(aid.getName()) - && getExt().equals(aid.getExt()) && getType().equals(aid.getType()); - } - - public int hashCode() { - int hash = 17; - hash += getModuleId().hashCode() * 37; - hash += getName().hashCode() * 37; - hash += getType().hashCode() * 37; - return hash; - } - - public String toString() { - return getModuleId() + " " + getName() + "." + getType(); - } - - /** - * @return Returns the module id. - */ - public ModuleId getModuleId() { - return mid; - } - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } - - /** - * @return Returns the type. - */ - public String getType() { - return type; - } - - /** - * @return Returns the ext. - */ - public String getExt() { - return ext; - } -} +/* + * 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.core.module.id; + +/** + * Identifies an artifact in a module, without revision information + */ +public class ArtifactId { + private ModuleId mid; + + private String name; + + private String type; + + private String ext; + + /** + * @param mid + * @param name + * @param type + */ + public ArtifactId(ModuleId mid, String name, String type, String ext) { + this.mid = mid; + this.name = name; + this.type = type; + this.ext = ext; + } + + public boolean equals(Object obj) { + if (!(obj instanceof ArtifactId)) { + return false; + } + ArtifactId aid = (ArtifactId) obj; + return getModuleId().equals(aid.getModuleId()) && getName().equals(aid.getName()) + && getExt().equals(aid.getExt()) && getType().equals(aid.getType()); + } + + public int hashCode() { + int hash = 17; + hash += getModuleId().hashCode() * 37; + hash += getName().hashCode() * 37; + hash += getType().hashCode() * 37; + return hash; + } + + public String toString() { + return getModuleId() + " " + getName() + "." + getType(); + } + + /** + * @return Returns the module id. + */ + public ModuleId getModuleId() { + return mid; + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @return Returns the type. + */ + public String getType() { + return type; + } + + /** + * @return Returns the ext. + */ + public String getExt() { + return ext; + } +} diff --git a/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java b/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java index fde03b67..4eae6003 100644 --- a/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java +++ b/src/java/org/apache/ivy/core/module/id/ArtifactRevisionId.java @@ -1,125 +1,125 @@ -/* - * 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.core.module.id; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; - -/** - * identifies an artifact in a particular module revision - */ -public class ArtifactRevisionId extends UnmodifiableExtendableItem { - public static ArtifactRevisionId newInstance(ModuleRevisionId mrid, String name, String type, - String ext) { - return newInstance(mrid, name, type, ext, null); - } - - public static ArtifactRevisionId newInstance(ModuleRevisionId mrid, String name, String type, - String ext, Map extraAttributes) { - // we inject module extra attributes as extra attributes for the artifacts too - if (extraAttributes == null) { - extraAttributes = mrid.getExtraAttributes(); - } else { - extraAttributes = new HashMap(extraAttributes); - extraAttributes.putAll(mrid.getExtraAttributes()); - } - return new ArtifactRevisionId(new ArtifactId(mrid.getModuleId(), name, type, ext), mrid, - extraAttributes); - } - - private ArtifactId _artifactId; - - private ModuleRevisionId _mrid; - - public ArtifactRevisionId(ArtifactId artifactId, ModuleRevisionId mrid) { - this(artifactId, mrid, null); - } - - public ArtifactRevisionId(ArtifactId artifactId, ModuleRevisionId mrid, Map extraAttributes) { - super(null, extraAttributes); - _artifactId = artifactId; - _mrid = mrid; - - setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, getModuleRevisionId() - .getOrganisation()); - setStandardAttribute(IvyPatternHelper.MODULE_KEY, getModuleRevisionId().getName()); - setStandardAttribute(IvyPatternHelper.REVISION_KEY, getModuleRevisionId().getRevision()); - setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, getName()); - setStandardAttribute(IvyPatternHelper.TYPE_KEY, getType()); - setStandardAttribute(IvyPatternHelper.EXT_KEY, getExt()); - } - - public boolean equals(Object obj) { - if (!(obj instanceof ArtifactRevisionId)) { - return false; - } - ArtifactRevisionId arid = (ArtifactRevisionId) obj; - return getArtifactId().equals(arid.getArtifactId()) - && getModuleRevisionId().equals(arid.getModuleRevisionId()) - && getExtraAttributes().equals(arid.getExtraAttributes()); - } - - public int hashCode() { - // WARN: uniqueness needs to be relatively strong here - int hash = 17; - hash += getArtifactId().hashCode() * 37; - hash += getModuleRevisionId().hashCode() * 37; - hash += getExtraAttributes().hashCode() * 37; - return hash; - } - - public String toString() { - return "[ " + getModuleRevisionId().getOrganisation() + " | " - + getModuleRevisionId().getName() + " | " + getModuleRevisionId().getRevision() - + " :: " + getName() + " . " + getExt() + " ( " + getType() + " ) ]"; - } - - /** - * @return Returns the artifactId. - */ - public ArtifactId getArtifactId() { - return _artifactId; - } - - public ModuleRevisionId getModuleRevisionId() { - return _mrid; - } - - public String getName() { - return _artifactId.getName(); - } - - public String getType() { - return _artifactId.getType(); - } - - public String getExt() { - return _artifactId.getExt(); - } - - /** - * @return Returns the revision. - */ - public String getRevision() { - return _mrid.getRevision(); - } - -} +/* + * 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.core.module.id; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; + +/** + * identifies an artifact in a particular module revision + */ +public class ArtifactRevisionId extends UnmodifiableExtendableItem { + public static ArtifactRevisionId newInstance(ModuleRevisionId mrid, String name, String type, + String ext) { + return newInstance(mrid, name, type, ext, null); + } + + public static ArtifactRevisionId newInstance(ModuleRevisionId mrid, String name, String type, + String ext, Map extraAttributes) { + // we inject module extra attributes as extra attributes for the artifacts too + if (extraAttributes == null) { + extraAttributes = mrid.getExtraAttributes(); + } else { + extraAttributes = new HashMap(extraAttributes); + extraAttributes.putAll(mrid.getExtraAttributes()); + } + return new ArtifactRevisionId(new ArtifactId(mrid.getModuleId(), name, type, ext), mrid, + extraAttributes); + } + + private ArtifactId _artifactId; + + private ModuleRevisionId _mrid; + + public ArtifactRevisionId(ArtifactId artifactId, ModuleRevisionId mrid) { + this(artifactId, mrid, null); + } + + public ArtifactRevisionId(ArtifactId artifactId, ModuleRevisionId mrid, Map extraAttributes) { + super(null, extraAttributes); + _artifactId = artifactId; + _mrid = mrid; + + setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, getModuleRevisionId() + .getOrganisation()); + setStandardAttribute(IvyPatternHelper.MODULE_KEY, getModuleRevisionId().getName()); + setStandardAttribute(IvyPatternHelper.REVISION_KEY, getModuleRevisionId().getRevision()); + setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, getName()); + setStandardAttribute(IvyPatternHelper.TYPE_KEY, getType()); + setStandardAttribute(IvyPatternHelper.EXT_KEY, getExt()); + } + + public boolean equals(Object obj) { + if (!(obj instanceof ArtifactRevisionId)) { + return false; + } + ArtifactRevisionId arid = (ArtifactRevisionId) obj; + return getArtifactId().equals(arid.getArtifactId()) + && getModuleRevisionId().equals(arid.getModuleRevisionId()) + && getExtraAttributes().equals(arid.getExtraAttributes()); + } + + public int hashCode() { + // WARN: uniqueness needs to be relatively strong here + int hash = 17; + hash += getArtifactId().hashCode() * 37; + hash += getModuleRevisionId().hashCode() * 37; + hash += getExtraAttributes().hashCode() * 37; + return hash; + } + + public String toString() { + return "[ " + getModuleRevisionId().getOrganisation() + " | " + + getModuleRevisionId().getName() + " | " + getModuleRevisionId().getRevision() + + " :: " + getName() + " . " + getExt() + " ( " + getType() + " ) ]"; + } + + /** + * @return Returns the artifactId. + */ + public ArtifactId getArtifactId() { + return _artifactId; + } + + public ModuleRevisionId getModuleRevisionId() { + return _mrid; + } + + public String getName() { + return _artifactId.getName(); + } + + public String getType() { + return _artifactId.getType(); + } + + public String getExt() { + return _artifactId.getExt(); + } + + /** + * @return Returns the revision. + */ + public String getRevision() { + return _mrid.getRevision(); + } + +} diff --git a/src/java/org/apache/ivy/core/module/id/ModuleId.java b/src/java/org/apache/ivy/core/module/id/ModuleId.java index 966ce6d5..d637beff 100644 --- a/src/java/org/apache/ivy/core/module/id/ModuleId.java +++ b/src/java/org/apache/ivy/core/module/id/ModuleId.java @@ -1,96 +1,96 @@ -/* - * 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.core.module.id; - -/** - * - */ -public class ModuleId implements Comparable { - static final String ENCODE_SEPARATOR = ":#@#:"; - - private String organisation; - - private String name; - - private int hash; - - public ModuleId(String organisation, String name) { - if (name == null) { - throw new IllegalArgumentException("null name not allowed"); - } - this.organisation = organisation; - this.name = name; - hash = _hashCode(); // stored for performance reasons, hashCode is very used in many maps - } - - public String getName() { - return name; - } - - public String getOrganisation() { - return organisation; - } - - public boolean equals(Object obj) { - if (!(obj instanceof ModuleId)) { - return false; - } - ModuleId other = (ModuleId) obj; - if (other.organisation == null) { - return organisation == null && other.name.equals(name); - } else { - return other.organisation.equals(organisation) && other.name.equals(name); - } - } - - public int hashCode() { - return hash; - } - - public int _hashCode() { - int hash = 31; - hash = hash * 13 + (organisation == null ? 0 : organisation.hashCode()); - hash = hash * 13 + name.hashCode(); - return hash; - } - - public String toString() { - return "[ " + organisation + " | " + name + " ]"; - } - - public int compareTo(Object obj) { - ModuleId that = (ModuleId) obj; - int result = organisation.compareTo(that.organisation); - if (result == 0) { - result = name.compareTo(that.name); - } - return result; - } - - public String encodeToString() { - return getOrganisation() + ENCODE_SEPARATOR + getName(); - } - - public static ModuleId decode(String encoded) { - String[] parts = encoded.split(ENCODE_SEPARATOR); - if (parts.length != 2) { - throw new IllegalArgumentException("badly encoded module id: '" + encoded + "'"); - } - return new ModuleId(parts[0], parts[1]); - } -} +/* + * 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.core.module.id; + +/** + * + */ +public class ModuleId implements Comparable { + static final String ENCODE_SEPARATOR = ":#@#:"; + + private String organisation; + + private String name; + + private int hash; + + public ModuleId(String organisation, String name) { + if (name == null) { + throw new IllegalArgumentException("null name not allowed"); + } + this.organisation = organisation; + this.name = name; + hash = _hashCode(); // stored for performance reasons, hashCode is very used in many maps + } + + public String getName() { + return name; + } + + public String getOrganisation() { + return organisation; + } + + public boolean equals(Object obj) { + if (!(obj instanceof ModuleId)) { + return false; + } + ModuleId other = (ModuleId) obj; + if (other.organisation == null) { + return organisation == null && other.name.equals(name); + } else { + return other.organisation.equals(organisation) && other.name.equals(name); + } + } + + public int hashCode() { + return hash; + } + + public int _hashCode() { + int hash = 31; + hash = hash * 13 + (organisation == null ? 0 : organisation.hashCode()); + hash = hash * 13 + name.hashCode(); + return hash; + } + + public String toString() { + return "[ " + organisation + " | " + name + " ]"; + } + + public int compareTo(Object obj) { + ModuleId that = (ModuleId) obj; + int result = organisation.compareTo(that.organisation); + if (result == 0) { + result = name.compareTo(that.name); + } + return result; + } + + public String encodeToString() { + return getOrganisation() + ENCODE_SEPARATOR + getName(); + } + + public static ModuleId decode(String encoded) { + String[] parts = encoded.split(ENCODE_SEPARATOR); + if (parts.length != 2) { + throw new IllegalArgumentException("badly encoded module id: '" + encoded + "'"); + } + return new ModuleId(parts[0], parts[1]); + } +} diff --git a/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java b/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java index 41b3e2bc..f42581c4 100644 --- a/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java +++ b/src/java/org/apache/ivy/core/module/id/ModuleRevisionId.java @@ -1,205 +1,205 @@ -/* - * 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.core.module.id; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; - -/** - * - */ -public class ModuleRevisionId extends UnmodifiableExtendableItem { - private static final String ENCODE_SEPARATOR = ModuleId.ENCODE_SEPARATOR; - - private static final String ENCODE_PREFIX = "+"; - - private static final String NULL_ENCODE = "@#:NULL:#@"; - - public static ModuleRevisionId newInstance(String organisation, String name, String revision) { - return new ModuleRevisionId(new ModuleId(organisation, name), revision); - } - - public static ModuleRevisionId newInstance(String organisation, String name, String revision, - Map extraAttributes) { - return new ModuleRevisionId(new ModuleId(organisation, name), revision, extraAttributes); - } - - public static ModuleRevisionId newInstance(String organisation, String name, String branch, - String revision) { - return new ModuleRevisionId(new ModuleId(organisation, name), branch, revision); - } - - public static ModuleRevisionId newInstance(String organisation, String name, String branch, - String revision, Map extraAttributes) { - return new ModuleRevisionId(new ModuleId(organisation, name), branch, revision, - extraAttributes); - } - - public static ModuleRevisionId newInstance(ModuleRevisionId mrid, String rev) { - return new ModuleRevisionId(mrid.getModuleId(), mrid.getBranch(), rev, mrid - .getExtraAttributes()); - } - - private ModuleId moduleId; - - private String branch; - - private String revision; - - private int hash; - - public ModuleRevisionId(ModuleId moduleId, String revision) { - this(moduleId, null, revision, null); - } - - public ModuleRevisionId(ModuleId moduleId, String branch, String revision) { - this(moduleId, branch, revision, null); - } - - public ModuleRevisionId(ModuleId moduleId, String revision, Map extraAttributes) { - this(moduleId, null, revision, extraAttributes); - } - - public ModuleRevisionId(ModuleId moduleId, String branch, String revision, Map extraAttributes) { - super(null, extraAttributes); - this.moduleId = moduleId; - this.branch = branch == null ? IvyContext.getContext().getSettings().getDefaultBranch( - moduleId) : branch; - this.revision = revision == null ? Ivy.getWorkingRevision() : revision; - hash = _hashCode(); // stored for performance reasons, hashCode is very used in many maps - setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, this.moduleId.getOrganisation()); - setStandardAttribute(IvyPatternHelper.MODULE_KEY, this.moduleId.getName()); - setStandardAttribute(IvyPatternHelper.BRANCH_KEY, this.branch); - setStandardAttribute(IvyPatternHelper.REVISION_KEY, this.revision); - } - - public ModuleId getModuleId() { - return moduleId; - } - - public String getName() { - return getModuleId().getName(); - } - - public String getOrganisation() { - return getModuleId().getOrganisation(); - } - - public String getRevision() { - return revision; - } - - public boolean equals(Object obj) { - if (!(obj instanceof ModuleRevisionId)) { - return false; - } - ModuleRevisionId other = (ModuleRevisionId) obj; - return other.getRevision().equals(getRevision()) - && (other.getBranch() == null ? getBranch() == null : other.getBranch().equals( - getBranch())) && other.getModuleId().equals(getModuleId()) - && other.getExtraAttributes().equals(getExtraAttributes()); - } - - public int hashCode() { - return hash; - } - - public int _hashCode() { - int hash = 31; - hash = hash * 13 + (getBranch() == null ? 0 : getBranch().hashCode()); - hash = hash * 13 + getRevision().hashCode(); - hash = hash * 13 + getModuleId().hashCode(); - hash = hash * 13 + getAttributes().hashCode(); - return hash; - } - - public String toString() { - return "[ " + moduleId.getOrganisation() + " | " + moduleId.getName() - + (branch == null || branch.length() == 0 ? "" : " | " + branch) + " | " - + (revision == null ? "NONE" : revision) + " ]"; - } - - public String encodeToString() { - StringBuffer buf = new StringBuffer(); - Map attributes = getAttributes(); - for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { - String attName = (String) iter.next(); - String value = (String) attributes.get(attName); - value = value == null ? NULL_ENCODE : value; - buf.append(ENCODE_PREFIX).append(attName).append(ENCODE_SEPARATOR) - .append(ENCODE_PREFIX).append(value).append(ENCODE_SEPARATOR); - } - return buf.toString(); - } - - public static ModuleRevisionId decode(String encoded) { - String[] parts = encoded.split(ENCODE_SEPARATOR); - if (parts.length % 2 != 0) { - throw new IllegalArgumentException("badly encoded module revision id: '" + encoded - + "'"); - } - Map attributes = new HashMap(); - for (int i = 0; i < parts.length; i += 2) { - String attName = parts[i]; - if (!attName.startsWith(ENCODE_PREFIX)) { - throw new IllegalArgumentException("badly encoded module revision id: '" + encoded - + "': " + attName + " doesn't start with " + ENCODE_PREFIX); - } else { - attName = attName.substring(1); - } - String attValue = parts[i + 1]; - if (!attValue.startsWith(ENCODE_PREFIX)) { - throw new IllegalArgumentException("badly encoded module revision id: '" + encoded - + "': " + attValue + " doesn't start with " + ENCODE_PREFIX); - } else { - attValue = attValue.substring(1); - } - if (NULL_ENCODE.equals(attValue)) { - attValue = null; - } - attributes.put(attName, attValue); - } - String org = (String) attributes.remove(IvyPatternHelper.ORGANISATION_KEY); - String mod = (String) attributes.remove(IvyPatternHelper.MODULE_KEY); - String rev = (String) attributes.remove(IvyPatternHelper.REVISION_KEY); - String branch = (String) attributes.remove(IvyPatternHelper.BRANCH_KEY); - if (org == null) { - throw new IllegalArgumentException("badly encoded module revision id: '" + encoded - + "': no organisation"); - } - if (mod == null) { - throw new IllegalArgumentException("badly encoded module revision id: '" + encoded - + "': no module name"); - } - if (rev == null) { - throw new IllegalArgumentException("badly encoded module revision id: '" + encoded - + "': no revision"); - } - return newInstance(org, mod, branch, rev, attributes); - } - - public String getBranch() { - return branch; - } -} +/* + * 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.core.module.id; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.util.extendable.UnmodifiableExtendableItem; + +/** + * + */ +public class ModuleRevisionId extends UnmodifiableExtendableItem { + private static final String ENCODE_SEPARATOR = ModuleId.ENCODE_SEPARATOR; + + private static final String ENCODE_PREFIX = "+"; + + private static final String NULL_ENCODE = "@#:NULL:#@"; + + public static ModuleRevisionId newInstance(String organisation, String name, String revision) { + return new ModuleRevisionId(new ModuleId(organisation, name), revision); + } + + public static ModuleRevisionId newInstance(String organisation, String name, String revision, + Map extraAttributes) { + return new ModuleRevisionId(new ModuleId(organisation, name), revision, extraAttributes); + } + + public static ModuleRevisionId newInstance(String organisation, String name, String branch, + String revision) { + return new ModuleRevisionId(new ModuleId(organisation, name), branch, revision); + } + + public static ModuleRevisionId newInstance(String organisation, String name, String branch, + String revision, Map extraAttributes) { + return new ModuleRevisionId(new ModuleId(organisation, name), branch, revision, + extraAttributes); + } + + public static ModuleRevisionId newInstance(ModuleRevisionId mrid, String rev) { + return new ModuleRevisionId(mrid.getModuleId(), mrid.getBranch(), rev, mrid + .getExtraAttributes()); + } + + private ModuleId moduleId; + + private String branch; + + private String revision; + + private int hash; + + public ModuleRevisionId(ModuleId moduleId, String revision) { + this(moduleId, null, revision, null); + } + + public ModuleRevisionId(ModuleId moduleId, String branch, String revision) { + this(moduleId, branch, revision, null); + } + + public ModuleRevisionId(ModuleId moduleId, String revision, Map extraAttributes) { + this(moduleId, null, revision, extraAttributes); + } + + public ModuleRevisionId(ModuleId moduleId, String branch, String revision, Map extraAttributes) { + super(null, extraAttributes); + this.moduleId = moduleId; + this.branch = branch == null ? IvyContext.getContext().getSettings().getDefaultBranch( + moduleId) : branch; + this.revision = revision == null ? Ivy.getWorkingRevision() : revision; + hash = _hashCode(); // stored for performance reasons, hashCode is very used in many maps + setStandardAttribute(IvyPatternHelper.ORGANISATION_KEY, this.moduleId.getOrganisation()); + setStandardAttribute(IvyPatternHelper.MODULE_KEY, this.moduleId.getName()); + setStandardAttribute(IvyPatternHelper.BRANCH_KEY, this.branch); + setStandardAttribute(IvyPatternHelper.REVISION_KEY, this.revision); + } + + public ModuleId getModuleId() { + return moduleId; + } + + public String getName() { + return getModuleId().getName(); + } + + public String getOrganisation() { + return getModuleId().getOrganisation(); + } + + public String getRevision() { + return revision; + } + + public boolean equals(Object obj) { + if (!(obj instanceof ModuleRevisionId)) { + return false; + } + ModuleRevisionId other = (ModuleRevisionId) obj; + return other.getRevision().equals(getRevision()) + && (other.getBranch() == null ? getBranch() == null : other.getBranch().equals( + getBranch())) && other.getModuleId().equals(getModuleId()) + && other.getExtraAttributes().equals(getExtraAttributes()); + } + + public int hashCode() { + return hash; + } + + public int _hashCode() { + int hash = 31; + hash = hash * 13 + (getBranch() == null ? 0 : getBranch().hashCode()); + hash = hash * 13 + getRevision().hashCode(); + hash = hash * 13 + getModuleId().hashCode(); + hash = hash * 13 + getAttributes().hashCode(); + return hash; + } + + public String toString() { + return "[ " + moduleId.getOrganisation() + " | " + moduleId.getName() + + (branch == null || branch.length() == 0 ? "" : " | " + branch) + " | " + + (revision == null ? "NONE" : revision) + " ]"; + } + + public String encodeToString() { + StringBuffer buf = new StringBuffer(); + Map attributes = getAttributes(); + for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { + String attName = (String) iter.next(); + String value = (String) attributes.get(attName); + value = value == null ? NULL_ENCODE : value; + buf.append(ENCODE_PREFIX).append(attName).append(ENCODE_SEPARATOR) + .append(ENCODE_PREFIX).append(value).append(ENCODE_SEPARATOR); + } + return buf.toString(); + } + + public static ModuleRevisionId decode(String encoded) { + String[] parts = encoded.split(ENCODE_SEPARATOR); + if (parts.length % 2 != 0) { + throw new IllegalArgumentException("badly encoded module revision id: '" + encoded + + "'"); + } + Map attributes = new HashMap(); + for (int i = 0; i < parts.length; i += 2) { + String attName = parts[i]; + if (!attName.startsWith(ENCODE_PREFIX)) { + throw new IllegalArgumentException("badly encoded module revision id: '" + encoded + + "': " + attName + " doesn't start with " + ENCODE_PREFIX); + } else { + attName = attName.substring(1); + } + String attValue = parts[i + 1]; + if (!attValue.startsWith(ENCODE_PREFIX)) { + throw new IllegalArgumentException("badly encoded module revision id: '" + encoded + + "': " + attValue + " doesn't start with " + ENCODE_PREFIX); + } else { + attValue = attValue.substring(1); + } + if (NULL_ENCODE.equals(attValue)) { + attValue = null; + } + attributes.put(attName, attValue); + } + String org = (String) attributes.remove(IvyPatternHelper.ORGANISATION_KEY); + String mod = (String) attributes.remove(IvyPatternHelper.MODULE_KEY); + String rev = (String) attributes.remove(IvyPatternHelper.REVISION_KEY); + String branch = (String) attributes.remove(IvyPatternHelper.BRANCH_KEY); + if (org == null) { + throw new IllegalArgumentException("badly encoded module revision id: '" + encoded + + "': no organisation"); + } + if (mod == null) { + throw new IllegalArgumentException("badly encoded module revision id: '" + encoded + + "': no module name"); + } + if (rev == null) { + throw new IllegalArgumentException("badly encoded module revision id: '" + encoded + + "': no revision"); + } + return newInstance(org, mod, branch, rev, attributes); + } + + public String getBranch() { + return branch; + } +} diff --git a/src/java/org/apache/ivy/core/module/status/Status.java b/src/java/org/apache/ivy/core/module/status/Status.java index a4e0dbe6..d94d94a7 100644 --- a/src/java/org/apache/ivy/core/module/status/Status.java +++ b/src/java/org/apache/ivy/core/module/status/Status.java @@ -1,48 +1,48 @@ -/* - * 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.core.module.status; - -public class Status { - private String name; - - private boolean integration; - - public Status() { - } - - public Status(String name, boolean integration) { - this.name = name; - this.integration = integration; - } - - public boolean isIntegration() { - return integration; - } - - public void setIntegration(boolean integration) { - this.integration = integration; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} +/* + * 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.core.module.status; + +public class Status { + private String name; + + private boolean integration; + + public Status() { + } + + public Status(String name, boolean integration) { + this.name = name; + this.integration = integration; + } + + public boolean isIntegration() { + return integration; + } + + public void setIntegration(boolean integration) { + this.integration = integration; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/java/org/apache/ivy/core/module/status/StatusManager.java b/src/java/org/apache/ivy/core/module/status/StatusManager.java index c51b3cd0..cb45b7f5 100644 --- a/src/java/org/apache/ivy/core/module/status/StatusManager.java +++ b/src/java/org/apache/ivy/core/module/status/StatusManager.java @@ -1,151 +1,151 @@ -/* - * 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.core.module.status; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.util.Message; - -/** - * Note: update methods (such as addStatus) should only be called BEFORE any call to accessor - * methods - */ -public class StatusManager { - public static StatusManager newDefaultInstance() { - return new StatusManager(new Status[] {new Status("release", false), - new Status("milestone", false), new Status("integration", true)}, "integration"); - } - - public static StatusManager getCurrent() { - return IvyContext.getContext().getSettings().getStatusManager(); - } - - private List status = new ArrayList(); - - private String defaultStatus; - - // for easier querying only - private Map statusPriorityMap; - - private Map statusIntegrationMap; - - private String deliveryStatusListString; - - public StatusManager(Status[] status, String defaultStatus) { - this.status.addAll(Arrays.asList(status)); - this.defaultStatus = defaultStatus; - - computeMaps(); - } - - public StatusManager() { - } - - public void addStatus(Status status) { - this.status.add(status); - } - - public void setDefaultStatus(String defaultStatus) { - this.defaultStatus = defaultStatus; - } - - public List getStatuses() { - return status; - } - - private void computeMaps() { - if (status.isEmpty()) { - throw new IllegalStateException("badly configured statuses: no status found"); - } - statusPriorityMap = new HashMap(); - for (ListIterator iter = status.listIterator(); iter.hasNext();) { - Status status = (Status) iter.next(); - statusPriorityMap.put(status.getName(), new Integer(iter.previousIndex())); - } - statusIntegrationMap = new HashMap(); - for (Iterator iter = status.iterator(); iter.hasNext();) { - Status status = (Status) iter.next(); - statusIntegrationMap.put(status.getName(), Boolean.valueOf(status.isIntegration())); - } - } - - public boolean isStatus(String status) { - if (statusPriorityMap == null) { - computeMaps(); - } - return statusPriorityMap.containsKey(status); - } - - public int getPriority(String status) { - if (statusPriorityMap == null) { - computeMaps(); - } - Integer priority = (Integer) statusPriorityMap.get(status); - if (priority == null) { - Message.debug("unknown status " + status + ": assuming lowest priority"); - return Integer.MAX_VALUE; - } - return priority.intValue(); - } - - public boolean isIntegration(String status) { - if (statusIntegrationMap == null) { - computeMaps(); - } - Boolean isIntegration = (Boolean) statusIntegrationMap.get(status); - if (isIntegration == null) { - Message.debug("unknown status " + status + ": assuming integration"); - return true; - } - return isIntegration.booleanValue(); - } - - public String getDeliveryStatusListString() { - if (deliveryStatusListString == null) { - StringBuffer ret = new StringBuffer(); - for (Iterator iter = status.iterator(); iter.hasNext();) { - Status status = (Status) iter.next(); - if (!status.isIntegration()) { - ret.append(status.getName()).append(","); - } - } - if (ret.length() > 0) { - ret.deleteCharAt(ret.length() - 1); - } - deliveryStatusListString = ret.toString(); - } - return deliveryStatusListString; - } - - public String getDefaultStatus() { - if (defaultStatus == null) { - if (status.isEmpty()) { - throw new IllegalStateException("badly configured statuses: no status found"); - } - defaultStatus = ((Status) status.get(status.size() - 1)).getName(); - } - return defaultStatus; - } -} +/* + * 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.core.module.status; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.util.Message; + +/** + * Note: update methods (such as addStatus) should only be called BEFORE any call to accessor + * methods + */ +public class StatusManager { + public static StatusManager newDefaultInstance() { + return new StatusManager(new Status[] {new Status("release", false), + new Status("milestone", false), new Status("integration", true)}, "integration"); + } + + public static StatusManager getCurrent() { + return IvyContext.getContext().getSettings().getStatusManager(); + } + + private List status = new ArrayList(); + + private String defaultStatus; + + // for easier querying only + private Map statusPriorityMap; + + private Map statusIntegrationMap; + + private String deliveryStatusListString; + + public StatusManager(Status[] status, String defaultStatus) { + this.status.addAll(Arrays.asList(status)); + this.defaultStatus = defaultStatus; + + computeMaps(); + } + + public StatusManager() { + } + + public void addStatus(Status status) { + this.status.add(status); + } + + public void setDefaultStatus(String defaultStatus) { + this.defaultStatus = defaultStatus; + } + + public List getStatuses() { + return status; + } + + private void computeMaps() { + if (status.isEmpty()) { + throw new IllegalStateException("badly configured statuses: no status found"); + } + statusPriorityMap = new HashMap(); + for (ListIterator iter = status.listIterator(); iter.hasNext();) { + Status status = (Status) iter.next(); + statusPriorityMap.put(status.getName(), new Integer(iter.previousIndex())); + } + statusIntegrationMap = new HashMap(); + for (Iterator iter = status.iterator(); iter.hasNext();) { + Status status = (Status) iter.next(); + statusIntegrationMap.put(status.getName(), Boolean.valueOf(status.isIntegration())); + } + } + + public boolean isStatus(String status) { + if (statusPriorityMap == null) { + computeMaps(); + } + return statusPriorityMap.containsKey(status); + } + + public int getPriority(String status) { + if (statusPriorityMap == null) { + computeMaps(); + } + Integer priority = (Integer) statusPriorityMap.get(status); + if (priority == null) { + Message.debug("unknown status " + status + ": assuming lowest priority"); + return Integer.MAX_VALUE; + } + return priority.intValue(); + } + + public boolean isIntegration(String status) { + if (statusIntegrationMap == null) { + computeMaps(); + } + Boolean isIntegration = (Boolean) statusIntegrationMap.get(status); + if (isIntegration == null) { + Message.debug("unknown status " + status + ": assuming integration"); + return true; + } + return isIntegration.booleanValue(); + } + + public String getDeliveryStatusListString() { + if (deliveryStatusListString == null) { + StringBuffer ret = new StringBuffer(); + for (Iterator iter = status.iterator(); iter.hasNext();) { + Status status = (Status) iter.next(); + if (!status.isIntegration()) { + ret.append(status.getName()).append(","); + } + } + if (ret.length() > 0) { + ret.deleteCharAt(ret.length() - 1); + } + deliveryStatusListString = ret.toString(); + } + return deliveryStatusListString; + } + + public String getDefaultStatus() { + if (defaultStatus == null) { + if (status.isEmpty()) { + throw new IllegalStateException("badly configured statuses: no status found"); + } + defaultStatus = ((Status) status.get(status.size() - 1)).getName(); + } + return defaultStatus; + } +} diff --git a/src/java/org/apache/ivy/core/publish/PublishEngine.java b/src/java/org/apache/ivy/core/publish/PublishEngine.java index dd62ffb6..412ca924 100644 --- a/src/java/org/apache/ivy/core/publish/PublishEngine.java +++ b/src/java/org/apache/ivy/core/publish/PublishEngine.java @@ -1,237 +1,237 @@ -/* - * 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.core.publish; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.MDArtifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.ConfigurationUtils; -import org.apache.ivy.util.Message; -import org.xml.sax.SAXException; - -public class PublishEngine { - private IvySettings settings; - - public PublishEngine(IvySettings settings) { - this.settings = settings; - } - - /** - * Publishes a module to the repository. The publish can update the ivy file to publish if - * update is set to true. In this case it will use the given pubrevision, pubdate and status. If - * pubdate is null it will default to the current date. If status is null it will default to the - * current ivy file status (which itself defaults to integration if none is found). If update is - * false, then if the revision is not the same in the ivy file than the one expected (given as - * parameter), this method will fail with an IllegalArgumentException. pubdate and status are - * not used if update is false. extra artifacts can be used to publish more artifacts than - * actually declared in the ivy file. This can be useful to publish additional metadata or - * reports. The extra artifacts array can be null (= no extra artifacts), and if non null only - * the name, type, ext url and extra attributes of the artifacts are really used. Other methods - * can return null safely. - */ - public Collection publish(ModuleRevisionId mrid, Collection srcArtifactPattern, - String resolverName, PublishOptions options) throws IOException { - Message.info(":: publishing :: " + mrid.getModuleId()); - Message.verbose("\tvalidate = " + options.isValidate()); - long start = System.currentTimeMillis(); - - options.setSrcIvyPattern(settings.substitute(options.getSrcIvyPattern())); - if (options.getPubrevision() == null) { - options.setPubrevision(mrid.getRevision()); - } - ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, options.getPubrevision()); - File ivyFile; - if (options.getSrcIvyPattern() != null) { - ivyFile = new File(IvyPatternHelper.substitute(options.getSrcIvyPattern(), - DefaultArtifact.newIvyArtifact(pubmrid, new Date()))); - if (!ivyFile.exists()) { - throw new IllegalArgumentException("ivy file to publish not found for " + mrid - + ": call deliver before (" + ivyFile + ")"); - } - } else { - CacheManager cacheManager = getCacheManager(options); - ivyFile = cacheManager.getResolvedIvyFileInCache(mrid); - if (!ivyFile.exists()) { - throw new IllegalStateException("ivy file not found in cache for " + mrid - + ": please resolve dependencies before publishing (" + ivyFile + ")"); - } - } - - // let's find the resolved module descriptor - ModuleDescriptor md = null; - URL ivyFileURL = null; - try { - ivyFileURL = ivyFile.toURL(); - md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, - false); - if (options.getSrcIvyPattern() != null) { - if (options.isUpdate()) { - File tmp = File.createTempFile("ivy", ".xml"); - tmp.deleteOnExit(); - - String[] confs = ConfigurationUtils.replaceWildcards(options.getConfs(), md); - Set confsToRemove = new HashSet(Arrays.asList(md.getConfigurationsNames())); - confsToRemove.removeAll(Arrays.asList(confs)); - - try { - XmlModuleDescriptorUpdater.update(settings, ivyFileURL, tmp, new HashMap(), - options.getStatus() == null ? md.getStatus() : options.getStatus(), - options.getPubrevision(), options.getPubdate() == null ? new Date() - : options.getPubdate(), null, true, (String[]) confsToRemove - .toArray(new String[confsToRemove.size()])); - ivyFile = tmp; - // we parse the new file to get updated module descriptor - md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, - ivyFile.toURL(), false); - options.setSrcIvyPattern(ivyFile.getAbsolutePath()); - } catch (SAXException e) { - throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile - + ": " + e); - } - } else if (!options.getPubrevision().equals(md.getModuleRevisionId().getRevision())) { - throw new IllegalArgumentException("cannot publish " + ivyFile + " as " - + options.getPubrevision() - + ": bad revision found in ivy file (Revision: " - + md.getModuleRevisionId().getRevision() - + "). Use forcedeliver or update."); - } - } else { - md.setResolvedModuleRevisionId(pubmrid); - } - } catch (MalformedURLException e) { - throw new RuntimeException("malformed url obtained for file " + ivyFile); - } catch (ParseException e) { - throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e); - } - - DependencyResolver resolver = settings.getResolver(resolverName); - if (resolver == null) { - throw new IllegalArgumentException("unknown resolver " + resolverName); - } - - // collect all declared artifacts of this module - Collection missing = publish(md, srcArtifactPattern, resolver, options); - Message.verbose("\tpublish done (" + (System.currentTimeMillis() - start) + "ms)"); - return missing; - } - - public Collection publish(ModuleDescriptor md, Collection srcArtifactPattern, - DependencyResolver resolver, PublishOptions options) throws IOException { - Collection missing = new ArrayList(); - Set artifactsSet = new HashSet(); - String[] confs = options.getConfs(); - if (confs == null || (confs.length == 1 && "*".equals(confs[0]))) { - confs = md.getConfigurationsNames(); - } - - for (int i = 0; i < confs.length; i++) { - Artifact[] artifacts = md.getArtifacts(confs[i]); - for (int j = 0; j < artifacts.length; j++) { - artifactsSet.add(artifacts[j]); - } - } - Artifact[] extraArtifacts = options.getExtraArtifacts(); - if (extraArtifacts != null) { - for (int i = 0; i < extraArtifacts.length; i++) { - artifactsSet.add(new MDArtifact(md, extraArtifacts[i].getName(), extraArtifacts[i] - .getType(), extraArtifacts[i].getExt(), extraArtifacts[i].getUrl(), - extraArtifacts[i].getExtraAttributes())); - } - } - // for each declared published artifact in this descriptor, do: - for (Iterator iter = artifactsSet.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - // 1) copy the artifact using src patterns and resolver - boolean published = false; - for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext() - && !published;) { - String pattern = (String) iterator.next(); - published = publish(artifact, settings.substitute(pattern), resolver, options - .isOverwrite()); - } - if (!published) { - Message.info("missing artifact " + artifact + ":"); - for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext();) { - String pattern = (String) iterator.next(); - Message.info("\t" + new File(IvyPatternHelper.substitute(pattern, artifact)) - + " file does not exist"); - } - missing.add(artifact); - } - } - if (options.getSrcIvyPattern() != null) { - Artifact artifact = MDArtifact.newIvyArtifact(md); - if (!publish(artifact, options.getSrcIvyPattern(), resolver, options.isOverwrite())) { - Message.info("missing ivy file for " - + md.getModuleRevisionId() - + ": " - + new File(IvyPatternHelper - .substitute(options.getSrcIvyPattern(), artifact)) - + " file does not exist"); - missing.add(artifact); - } - } - return missing; - } - - private boolean publish(Artifact artifact, String srcArtifactPattern, - DependencyResolver resolver, boolean overwrite) throws IOException { - IvyContext.getContext().checkInterrupted(); - File src = new File(IvyPatternHelper.substitute(srcArtifactPattern, artifact)); - if (src.exists()) { - resolver.publish(artifact, src, overwrite); - return true; - } else { - return false; - } - } - - private CacheManager getCacheManager(PublishOptions options) { - CacheManager cacheManager = options.getCache(); - if (cacheManager == null) { // ensure that a cache is configured - cacheManager = IvyContext.getContext().getCacheManager(); - options.setCache(cacheManager); - } else { - IvyContext.getContext().setCache(cacheManager.getCache()); - } - return cacheManager; - } -} +/* + * 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.core.publish; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.MDArtifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.ConfigurationUtils; +import org.apache.ivy.util.Message; +import org.xml.sax.SAXException; + +public class PublishEngine { + private IvySettings settings; + + public PublishEngine(IvySettings settings) { + this.settings = settings; + } + + /** + * Publishes a module to the repository. The publish can update the ivy file to publish if + * update is set to true. In this case it will use the given pubrevision, pubdate and status. If + * pubdate is null it will default to the current date. If status is null it will default to the + * current ivy file status (which itself defaults to integration if none is found). If update is + * false, then if the revision is not the same in the ivy file than the one expected (given as + * parameter), this method will fail with an IllegalArgumentException. pubdate and status are + * not used if update is false. extra artifacts can be used to publish more artifacts than + * actually declared in the ivy file. This can be useful to publish additional metadata or + * reports. The extra artifacts array can be null (= no extra artifacts), and if non null only + * the name, type, ext url and extra attributes of the artifacts are really used. Other methods + * can return null safely. + */ + public Collection publish(ModuleRevisionId mrid, Collection srcArtifactPattern, + String resolverName, PublishOptions options) throws IOException { + Message.info(":: publishing :: " + mrid.getModuleId()); + Message.verbose("\tvalidate = " + options.isValidate()); + long start = System.currentTimeMillis(); + + options.setSrcIvyPattern(settings.substitute(options.getSrcIvyPattern())); + if (options.getPubrevision() == null) { + options.setPubrevision(mrid.getRevision()); + } + ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, options.getPubrevision()); + File ivyFile; + if (options.getSrcIvyPattern() != null) { + ivyFile = new File(IvyPatternHelper.substitute(options.getSrcIvyPattern(), + DefaultArtifact.newIvyArtifact(pubmrid, new Date()))); + if (!ivyFile.exists()) { + throw new IllegalArgumentException("ivy file to publish not found for " + mrid + + ": call deliver before (" + ivyFile + ")"); + } + } else { + CacheManager cacheManager = getCacheManager(options); + ivyFile = cacheManager.getResolvedIvyFileInCache(mrid); + if (!ivyFile.exists()) { + throw new IllegalStateException("ivy file not found in cache for " + mrid + + ": please resolve dependencies before publishing (" + ivyFile + ")"); + } + } + + // let's find the resolved module descriptor + ModuleDescriptor md = null; + URL ivyFileURL = null; + try { + ivyFileURL = ivyFile.toURL(); + md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, + false); + if (options.getSrcIvyPattern() != null) { + if (options.isUpdate()) { + File tmp = File.createTempFile("ivy", ".xml"); + tmp.deleteOnExit(); + + String[] confs = ConfigurationUtils.replaceWildcards(options.getConfs(), md); + Set confsToRemove = new HashSet(Arrays.asList(md.getConfigurationsNames())); + confsToRemove.removeAll(Arrays.asList(confs)); + + try { + XmlModuleDescriptorUpdater.update(settings, ivyFileURL, tmp, new HashMap(), + options.getStatus() == null ? md.getStatus() : options.getStatus(), + options.getPubrevision(), options.getPubdate() == null ? new Date() + : options.getPubdate(), null, true, (String[]) confsToRemove + .toArray(new String[confsToRemove.size()])); + ivyFile = tmp; + // we parse the new file to get updated module descriptor + md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, + ivyFile.toURL(), false); + options.setSrcIvyPattern(ivyFile.getAbsolutePath()); + } catch (SAXException e) { + throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + + ": " + e); + } + } else if (!options.getPubrevision().equals(md.getModuleRevisionId().getRevision())) { + throw new IllegalArgumentException("cannot publish " + ivyFile + " as " + + options.getPubrevision() + + ": bad revision found in ivy file (Revision: " + + md.getModuleRevisionId().getRevision() + + "). Use forcedeliver or update."); + } + } else { + md.setResolvedModuleRevisionId(pubmrid); + } + } catch (MalformedURLException e) { + throw new RuntimeException("malformed url obtained for file " + ivyFile); + } catch (ParseException e) { + throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e); + } + + DependencyResolver resolver = settings.getResolver(resolverName); + if (resolver == null) { + throw new IllegalArgumentException("unknown resolver " + resolverName); + } + + // collect all declared artifacts of this module + Collection missing = publish(md, srcArtifactPattern, resolver, options); + Message.verbose("\tpublish done (" + (System.currentTimeMillis() - start) + "ms)"); + return missing; + } + + public Collection publish(ModuleDescriptor md, Collection srcArtifactPattern, + DependencyResolver resolver, PublishOptions options) throws IOException { + Collection missing = new ArrayList(); + Set artifactsSet = new HashSet(); + String[] confs = options.getConfs(); + if (confs == null || (confs.length == 1 && "*".equals(confs[0]))) { + confs = md.getConfigurationsNames(); + } + + for (int i = 0; i < confs.length; i++) { + Artifact[] artifacts = md.getArtifacts(confs[i]); + for (int j = 0; j < artifacts.length; j++) { + artifactsSet.add(artifacts[j]); + } + } + Artifact[] extraArtifacts = options.getExtraArtifacts(); + if (extraArtifacts != null) { + for (int i = 0; i < extraArtifacts.length; i++) { + artifactsSet.add(new MDArtifact(md, extraArtifacts[i].getName(), extraArtifacts[i] + .getType(), extraArtifacts[i].getExt(), extraArtifacts[i].getUrl(), + extraArtifacts[i].getExtraAttributes())); + } + } + // for each declared published artifact in this descriptor, do: + for (Iterator iter = artifactsSet.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + // 1) copy the artifact using src patterns and resolver + boolean published = false; + for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext() + && !published;) { + String pattern = (String) iterator.next(); + published = publish(artifact, settings.substitute(pattern), resolver, options + .isOverwrite()); + } + if (!published) { + Message.info("missing artifact " + artifact + ":"); + for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext();) { + String pattern = (String) iterator.next(); + Message.info("\t" + new File(IvyPatternHelper.substitute(pattern, artifact)) + + " file does not exist"); + } + missing.add(artifact); + } + } + if (options.getSrcIvyPattern() != null) { + Artifact artifact = MDArtifact.newIvyArtifact(md); + if (!publish(artifact, options.getSrcIvyPattern(), resolver, options.isOverwrite())) { + Message.info("missing ivy file for " + + md.getModuleRevisionId() + + ": " + + new File(IvyPatternHelper + .substitute(options.getSrcIvyPattern(), artifact)) + + " file does not exist"); + missing.add(artifact); + } + } + return missing; + } + + private boolean publish(Artifact artifact, String srcArtifactPattern, + DependencyResolver resolver, boolean overwrite) throws IOException { + IvyContext.getContext().checkInterrupted(); + File src = new File(IvyPatternHelper.substitute(srcArtifactPattern, artifact)); + if (src.exists()) { + resolver.publish(artifact, src, overwrite); + return true; + } else { + return false; + } + } + + private CacheManager getCacheManager(PublishOptions options) { + CacheManager cacheManager = options.getCache(); + if (cacheManager == null) { // ensure that a cache is configured + cacheManager = IvyContext.getContext().getCacheManager(); + options.setCache(cacheManager); + } else { + IvyContext.getContext().setCache(cacheManager.getCache()); + } + return cacheManager; + } +} diff --git a/src/java/org/apache/ivy/core/publish/PublishOptions.java b/src/java/org/apache/ivy/core/publish/PublishOptions.java index 8909fb82..4108a094 100644 --- a/src/java/org/apache/ivy/core/publish/PublishOptions.java +++ b/src/java/org/apache/ivy/core/publish/PublishOptions.java @@ -1,151 +1,151 @@ -/* - * 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.core.publish; - -import java.util.Date; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; - -/** - * A set of options used during publish related tasks The publish can update the ivy file to publish - * if update is set to true. In this case it will use the given pubrevision, pubdate and status. If - * pudate is null it will default to the current date. If status is null it will default to the - * current ivy file status (which itself defaults to integration if none is found). If update is - * false, then if the revision is not the same in the ivy file than the one expected (given as - * parameter), this method will fail with an IllegalArgumentException. pubdate and status are not - * used if update is false. extra artifacts can be used to publish more artifacts than actually - * declared in the ivy file. This can be useful to publish additional metadata or reports. The extra - * artifacts array can be null (= no extra artifacts), and if non null only the name, type, ext url - * and extra attributes of the artifacts are really used. Other methods (on the artifacts) can - * return null safely. - * - * @see PublishEngine - */ -public class PublishOptions { - private CacheManager cache; - - private String srcIvyPattern; - - private String pubrevision; - - private String status; - - private Date pubdate; - - private Artifact[] extraArtifacts; - - private boolean validate; - - private boolean overwrite; - - private boolean update; - - private String[] confs; - - public CacheManager getCache() { - return cache; - } - - public PublishOptions setCache(CacheManager cache) { - this.cache = cache; - return this; - } - - public String[] getConfs() { - return confs; - } - - public PublishOptions setConfs(String[] confs) { - this.confs = confs; - return this; - } - - public Artifact[] getExtraArtifacts() { - return extraArtifacts; - } - - public PublishOptions setExtraArtifacts(Artifact[] extraArtifacts) { - this.extraArtifacts = extraArtifacts; - return this; - } - - public boolean isOverwrite() { - return overwrite; - } - - public PublishOptions setOverwrite(boolean overwrite) { - this.overwrite = overwrite; - return this; - } - - public Date getPubdate() { - return pubdate; - } - - public PublishOptions setPubdate(Date pubdate) { - this.pubdate = pubdate; - return this; - } - - public String getPubrevision() { - return pubrevision; - } - - public PublishOptions setPubrevision(String pubrevision) { - this.pubrevision = pubrevision; - return this; - } - - public String getSrcIvyPattern() { - return srcIvyPattern; - } - - public PublishOptions setSrcIvyPattern(String srcIvyPattern) { - this.srcIvyPattern = srcIvyPattern; - return this; - } - - public String getStatus() { - return status; - } - - public PublishOptions setStatus(String status) { - this.status = status; - return this; - } - - public boolean isUpdate() { - return update; - } - - public PublishOptions setUpdate(boolean update) { - this.update = update; - return this; - } - - public boolean isValidate() { - return validate; - } - - public PublishOptions setValidate(boolean validate) { - this.validate = validate; - return this; - } - -} +/* + * 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.core.publish; + +import java.util.Date; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; + +/** + * A set of options used during publish related tasks The publish can update the ivy file to publish + * if update is set to true. In this case it will use the given pubrevision, pubdate and status. If + * pudate is null it will default to the current date. If status is null it will default to the + * current ivy file status (which itself defaults to integration if none is found). If update is + * false, then if the revision is not the same in the ivy file than the one expected (given as + * parameter), this method will fail with an IllegalArgumentException. pubdate and status are not + * used if update is false. extra artifacts can be used to publish more artifacts than actually + * declared in the ivy file. This can be useful to publish additional metadata or reports. The extra + * artifacts array can be null (= no extra artifacts), and if non null only the name, type, ext url + * and extra attributes of the artifacts are really used. Other methods (on the artifacts) can + * return null safely. + * + * @see PublishEngine + */ +public class PublishOptions { + private CacheManager cache; + + private String srcIvyPattern; + + private String pubrevision; + + private String status; + + private Date pubdate; + + private Artifact[] extraArtifacts; + + private boolean validate; + + private boolean overwrite; + + private boolean update; + + private String[] confs; + + public CacheManager getCache() { + return cache; + } + + public PublishOptions setCache(CacheManager cache) { + this.cache = cache; + return this; + } + + public String[] getConfs() { + return confs; + } + + public PublishOptions setConfs(String[] confs) { + this.confs = confs; + return this; + } + + public Artifact[] getExtraArtifacts() { + return extraArtifacts; + } + + public PublishOptions setExtraArtifacts(Artifact[] extraArtifacts) { + this.extraArtifacts = extraArtifacts; + return this; + } + + public boolean isOverwrite() { + return overwrite; + } + + public PublishOptions setOverwrite(boolean overwrite) { + this.overwrite = overwrite; + return this; + } + + public Date getPubdate() { + return pubdate; + } + + public PublishOptions setPubdate(Date pubdate) { + this.pubdate = pubdate; + return this; + } + + public String getPubrevision() { + return pubrevision; + } + + public PublishOptions setPubrevision(String pubrevision) { + this.pubrevision = pubrevision; + return this; + } + + public String getSrcIvyPattern() { + return srcIvyPattern; + } + + public PublishOptions setSrcIvyPattern(String srcIvyPattern) { + this.srcIvyPattern = srcIvyPattern; + return this; + } + + public String getStatus() { + return status; + } + + public PublishOptions setStatus(String status) { + this.status = status; + return this; + } + + public boolean isUpdate() { + return update; + } + + public PublishOptions setUpdate(boolean update) { + this.update = update; + return this; + } + + public boolean isValidate() { + return validate; + } + + public PublishOptions setValidate(boolean validate) { + this.validate = validate; + return this; + } + +} diff --git a/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java b/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java index b89e3dfe..0223b022 100644 --- a/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java +++ b/src/java/org/apache/ivy/core/report/ArtifactDownloadReport.java @@ -1,78 +1,78 @@ -/* - * 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.core.report; - -import org.apache.ivy.core.cache.ArtifactOrigin; -import org.apache.ivy.core.module.descriptor.Artifact; - -/** - * - */ -public class ArtifactDownloadReport { - private Artifact artifact; - - private ArtifactOrigin origin; - - private DownloadStatus downloadStatus; - - private long size; - - public ArtifactDownloadReport(Artifact artifact) { - this.artifact = artifact; - } - - public DownloadStatus getDownloadStatus() { - return downloadStatus; - } - - public void setDownloadStatus(DownloadStatus downloadStatus) { - this.downloadStatus = downloadStatus; - } - - public String getName() { - return artifact.getName(); - } - - public String getType() { - return artifact.getType(); - } - - public Artifact getArtifact() { - return artifact; - } - - public String getExt() { - return artifact.getExt(); - } - - public long getSize() { - return size; - } - - public void setSize(long size) { - this.size = size; - } - - public void setArtifactOrigin(ArtifactOrigin origin) { - this.origin = origin; - } - - public ArtifactOrigin getArtifactOrigin() { - return origin; - } -} +/* + * 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.core.report; + +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.module.descriptor.Artifact; + +/** + * + */ +public class ArtifactDownloadReport { + private Artifact artifact; + + private ArtifactOrigin origin; + + private DownloadStatus downloadStatus; + + private long size; + + public ArtifactDownloadReport(Artifact artifact) { + this.artifact = artifact; + } + + public DownloadStatus getDownloadStatus() { + return downloadStatus; + } + + public void setDownloadStatus(DownloadStatus downloadStatus) { + this.downloadStatus = downloadStatus; + } + + public String getName() { + return artifact.getName(); + } + + public String getType() { + return artifact.getType(); + } + + public Artifact getArtifact() { + return artifact; + } + + public String getExt() { + return artifact.getExt(); + } + + public long getSize() { + return size; + } + + public void setSize(long size) { + this.size = size; + } + + public void setArtifactOrigin(ArtifactOrigin origin) { + this.origin = origin; + } + + public ArtifactOrigin getArtifactOrigin() { + return origin; + } +} diff --git a/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java b/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java index 3954cbf0..d77736a7 100644 --- a/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java +++ b/src/java/org/apache/ivy/core/report/ConfigurationResolveReport.java @@ -1,294 +1,294 @@ -/* - * 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.core.report; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveEngine; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.plugins.report.XmlReportParser; -import org.apache.ivy.util.Message; - -/** - * - */ -public class ConfigurationResolveReport { - - private ModuleDescriptor md; - - private String conf; - - private Date date; - - private Map dependencyReports = new HashMap(); - - private Map dependencies = new LinkedHashMap(); - - private ResolveEngine resolveEngine; - - private Map modulesIdsMap = new LinkedHashMap(); - - private List modulesIds; - - private List previousDeps; - - public ConfigurationResolveReport(ResolveEngine resolveEngine, ModuleDescriptor md, - String conf, Date date, ResolveOptions options) { - this.resolveEngine = resolveEngine; - this.md = md; - this.conf = conf; - this.date = date; - - // parse previous deps from previous report file if any - CacheManager cache = options.getCache(); - String resolveId = options.getResolveId(); - File previousReportFile = cache.getConfigurationResolveReportInCache(resolveId, conf); - if (previousReportFile.exists()) { - try { - XmlReportParser parser = new XmlReportParser(); - parser.parse(previousReportFile); - previousDeps = Arrays.asList(parser.getDependencyRevisionIds()); - } catch (Exception e) { - Message.warn("Error while parsing configuration resolve report " - + previousReportFile.getAbsolutePath()); - e.printStackTrace(); - previousDeps = null; - } - } else { - previousDeps = null; - } - } - - public boolean hasChanged() { - if (previousDeps == null) { - return true; - } - return !new HashSet(previousDeps).equals(getModuleRevisionIds()); - } - - /** - * Returns all non evicted and non error dependency mrids The returned set is ordered so that a - * dependency will always be found before their own dependencies - * - * @return all non evicted and non error dependency mrids - */ - public Set getModuleRevisionIds() { - Set mrids = new LinkedHashSet(); - for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (!node.isEvicted(getConfiguration()) && !node.hasProblem()) { - mrids.add(node.getResolvedId()); - } - } - return mrids; - } - - public void addDependency(IvyNode node) { - dependencies.put(node.getId(), node); - dependencies.put(node.getResolvedId(), node); - dependencyReports.put(node, Collections.EMPTY_LIST); - } - - public void addDependency(IvyNode node, DownloadReport report) { - dependencies.put(node.getId(), node); - dependencies.put(node.getResolvedId(), node); - List adrs = new ArrayList(); - Artifact[] artifacts = node.getArtifacts(conf); - for (int i = 0; i < artifacts.length; i++) { - ArtifactDownloadReport artifactReport = report.getArtifactReport(artifacts[i]); - if (artifactReport != null) { - adrs.add(artifactReport); - } else { - Message.debug("no report found for " + artifacts[i]); - } - } - dependencyReports.put(node, adrs); - } - - public String getConfiguration() { - return conf; - } - - public Date getDate() { - return date; - } - - public ModuleDescriptor getModuleDescriptor() { - return md; - } - - public IvyNode[] getUnresolvedDependencies() { - List unresolved = new ArrayList(); - for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (node.hasProblem()) { - unresolved.add(node); - } - } - return (IvyNode[]) unresolved.toArray(new IvyNode[unresolved.size()]); - } - - private Collection getDependencies() { - return new LinkedHashSet(dependencies.values()); - } - - public IvyNode[] getEvictedNodes() { - List evicted = new ArrayList(); - for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (node.isEvicted(conf)) { - evicted.add(node); - } - } - return (IvyNode[]) evicted.toArray(new IvyNode[evicted.size()]); - } - - public IvyNode[] getDownloadedNodes() { - List downloaded = new ArrayList(); - for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (node.isDownloaded() && node.getRealNode() == node) { - downloaded.add(node); - } - } - return (IvyNode[]) downloaded.toArray(new IvyNode[downloaded.size()]); - } - - public IvyNode[] getSearchedNodes() { - List downloaded = new ArrayList(); - for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (node.isSearched() && node.getRealNode() == node) { - downloaded.add(node); - } - } - return (IvyNode[]) downloaded.toArray(new IvyNode[downloaded.size()]); - } - - public ArtifactDownloadReport[] getDownloadReports(ModuleRevisionId mrid) { - Collection col = (Collection) dependencyReports.get(getDependency(mrid)); - if (col == null) { - return new ArtifactDownloadReport[0]; - } - return (ArtifactDownloadReport[]) col.toArray(new ArtifactDownloadReport[col.size()]); - } - - public IvyNode getDependency(ModuleRevisionId mrid) { - return (IvyNode) dependencies.get(mrid); - } - - /** - * gives all the modules ids concerned by this report, from the most dependent to the least one - * - * @return a list of ModuleId - */ - public List getModuleIds() { - if (modulesIds == null) { - List sortedDependencies = resolveEngine.getSortEngine().sortNodes(getDependencies()); - Collections.reverse(sortedDependencies); - for (Iterator iter = sortedDependencies.iterator(); iter.hasNext();) { - IvyNode dependency = (IvyNode) iter.next(); - ModuleId mid = dependency.getResolvedId().getModuleId(); - Collection deps = (Collection) modulesIdsMap.get(mid); - if (deps == null) { - deps = new HashSet(); - modulesIdsMap.put(mid, deps); - } - deps.add(dependency); - } - modulesIds = new ArrayList(modulesIdsMap.keySet()); - } - return Collections.unmodifiableList(modulesIds); - } - - public Collection getNodes(ModuleId mid) { - if (modulesIds == null) { - getModuleIds(); - } - return (Collection) modulesIdsMap.get(mid); - } - - public ResolveEngine getResolveEngine() { - return resolveEngine; - } - - public int getArtifactsNumber() { - int total = 0; - for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { - Collection reports = (Collection) iter.next(); - total += reports == null ? 0 : reports.size(); - } - return total; - } - - public ArtifactDownloadReport[] getDownloadedArtifactsReports() { - List result = new ArrayList(); - for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { - Collection reports = (Collection) iter.next(); - for (Iterator iterator = reports.iterator(); iterator.hasNext();) { - ArtifactDownloadReport adr = (ArtifactDownloadReport) iterator.next(); - if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) { - result.add(adr); - } - } - } - return (ArtifactDownloadReport[]) result.toArray(new ArtifactDownloadReport[result.size()]); - } - - public ArtifactDownloadReport[] getFailedArtifactsReports() { - List result = new ArrayList(); - for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { - Collection reports = (Collection) iter.next(); - for (Iterator iterator = reports.iterator(); iterator.hasNext();) { - ArtifactDownloadReport adr = (ArtifactDownloadReport) iterator.next(); - if (adr.getDownloadStatus() == DownloadStatus.FAILED) { - result.add(adr); - } - } - } - return (ArtifactDownloadReport[]) result.toArray(new ArtifactDownloadReport[result.size()]); - } - - public boolean hasError() { - return getUnresolvedDependencies().length > 0 || getFailedArtifactsReports().length > 0; - } - - public int getNodesNumber() { - return getDependencies().size(); - } - -} +/* + * 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.core.report; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveEngine; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.plugins.report.XmlReportParser; +import org.apache.ivy.util.Message; + +/** + * + */ +public class ConfigurationResolveReport { + + private ModuleDescriptor md; + + private String conf; + + private Date date; + + private Map dependencyReports = new HashMap(); + + private Map dependencies = new LinkedHashMap(); + + private ResolveEngine resolveEngine; + + private Map modulesIdsMap = new LinkedHashMap(); + + private List modulesIds; + + private List previousDeps; + + public ConfigurationResolveReport(ResolveEngine resolveEngine, ModuleDescriptor md, + String conf, Date date, ResolveOptions options) { + this.resolveEngine = resolveEngine; + this.md = md; + this.conf = conf; + this.date = date; + + // parse previous deps from previous report file if any + CacheManager cache = options.getCache(); + String resolveId = options.getResolveId(); + File previousReportFile = cache.getConfigurationResolveReportInCache(resolveId, conf); + if (previousReportFile.exists()) { + try { + XmlReportParser parser = new XmlReportParser(); + parser.parse(previousReportFile); + previousDeps = Arrays.asList(parser.getDependencyRevisionIds()); + } catch (Exception e) { + Message.warn("Error while parsing configuration resolve report " + + previousReportFile.getAbsolutePath()); + e.printStackTrace(); + previousDeps = null; + } + } else { + previousDeps = null; + } + } + + public boolean hasChanged() { + if (previousDeps == null) { + return true; + } + return !new HashSet(previousDeps).equals(getModuleRevisionIds()); + } + + /** + * Returns all non evicted and non error dependency mrids The returned set is ordered so that a + * dependency will always be found before their own dependencies + * + * @return all non evicted and non error dependency mrids + */ + public Set getModuleRevisionIds() { + Set mrids = new LinkedHashSet(); + for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (!node.isEvicted(getConfiguration()) && !node.hasProblem()) { + mrids.add(node.getResolvedId()); + } + } + return mrids; + } + + public void addDependency(IvyNode node) { + dependencies.put(node.getId(), node); + dependencies.put(node.getResolvedId(), node); + dependencyReports.put(node, Collections.EMPTY_LIST); + } + + public void addDependency(IvyNode node, DownloadReport report) { + dependencies.put(node.getId(), node); + dependencies.put(node.getResolvedId(), node); + List adrs = new ArrayList(); + Artifact[] artifacts = node.getArtifacts(conf); + for (int i = 0; i < artifacts.length; i++) { + ArtifactDownloadReport artifactReport = report.getArtifactReport(artifacts[i]); + if (artifactReport != null) { + adrs.add(artifactReport); + } else { + Message.debug("no report found for " + artifacts[i]); + } + } + dependencyReports.put(node, adrs); + } + + public String getConfiguration() { + return conf; + } + + public Date getDate() { + return date; + } + + public ModuleDescriptor getModuleDescriptor() { + return md; + } + + public IvyNode[] getUnresolvedDependencies() { + List unresolved = new ArrayList(); + for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (node.hasProblem()) { + unresolved.add(node); + } + } + return (IvyNode[]) unresolved.toArray(new IvyNode[unresolved.size()]); + } + + private Collection getDependencies() { + return new LinkedHashSet(dependencies.values()); + } + + public IvyNode[] getEvictedNodes() { + List evicted = new ArrayList(); + for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (node.isEvicted(conf)) { + evicted.add(node); + } + } + return (IvyNode[]) evicted.toArray(new IvyNode[evicted.size()]); + } + + public IvyNode[] getDownloadedNodes() { + List downloaded = new ArrayList(); + for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (node.isDownloaded() && node.getRealNode() == node) { + downloaded.add(node); + } + } + return (IvyNode[]) downloaded.toArray(new IvyNode[downloaded.size()]); + } + + public IvyNode[] getSearchedNodes() { + List downloaded = new ArrayList(); + for (Iterator iter = getDependencies().iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (node.isSearched() && node.getRealNode() == node) { + downloaded.add(node); + } + } + return (IvyNode[]) downloaded.toArray(new IvyNode[downloaded.size()]); + } + + public ArtifactDownloadReport[] getDownloadReports(ModuleRevisionId mrid) { + Collection col = (Collection) dependencyReports.get(getDependency(mrid)); + if (col == null) { + return new ArtifactDownloadReport[0]; + } + return (ArtifactDownloadReport[]) col.toArray(new ArtifactDownloadReport[col.size()]); + } + + public IvyNode getDependency(ModuleRevisionId mrid) { + return (IvyNode) dependencies.get(mrid); + } + + /** + * gives all the modules ids concerned by this report, from the most dependent to the least one + * + * @return a list of ModuleId + */ + public List getModuleIds() { + if (modulesIds == null) { + List sortedDependencies = resolveEngine.getSortEngine().sortNodes(getDependencies()); + Collections.reverse(sortedDependencies); + for (Iterator iter = sortedDependencies.iterator(); iter.hasNext();) { + IvyNode dependency = (IvyNode) iter.next(); + ModuleId mid = dependency.getResolvedId().getModuleId(); + Collection deps = (Collection) modulesIdsMap.get(mid); + if (deps == null) { + deps = new HashSet(); + modulesIdsMap.put(mid, deps); + } + deps.add(dependency); + } + modulesIds = new ArrayList(modulesIdsMap.keySet()); + } + return Collections.unmodifiableList(modulesIds); + } + + public Collection getNodes(ModuleId mid) { + if (modulesIds == null) { + getModuleIds(); + } + return (Collection) modulesIdsMap.get(mid); + } + + public ResolveEngine getResolveEngine() { + return resolveEngine; + } + + public int getArtifactsNumber() { + int total = 0; + for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { + Collection reports = (Collection) iter.next(); + total += reports == null ? 0 : reports.size(); + } + return total; + } + + public ArtifactDownloadReport[] getDownloadedArtifactsReports() { + List result = new ArrayList(); + for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { + Collection reports = (Collection) iter.next(); + for (Iterator iterator = reports.iterator(); iterator.hasNext();) { + ArtifactDownloadReport adr = (ArtifactDownloadReport) iterator.next(); + if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) { + result.add(adr); + } + } + } + return (ArtifactDownloadReport[]) result.toArray(new ArtifactDownloadReport[result.size()]); + } + + public ArtifactDownloadReport[] getFailedArtifactsReports() { + List result = new ArrayList(); + for (Iterator iter = dependencyReports.values().iterator(); iter.hasNext();) { + Collection reports = (Collection) iter.next(); + for (Iterator iterator = reports.iterator(); iterator.hasNext();) { + ArtifactDownloadReport adr = (ArtifactDownloadReport) iterator.next(); + if (adr.getDownloadStatus() == DownloadStatus.FAILED) { + result.add(adr); + } + } + } + return (ArtifactDownloadReport[]) result.toArray(new ArtifactDownloadReport[result.size()]); + } + + public boolean hasError() { + return getUnresolvedDependencies().length > 0 || getFailedArtifactsReports().length > 0; + } + + public int getNodesNumber() { + return getDependencies().size(); + } + +} diff --git a/src/java/org/apache/ivy/core/report/DownloadReport.java b/src/java/org/apache/ivy/core/report/DownloadReport.java index 72f4f08c..f2dfcb64 100644 --- a/src/java/org/apache/ivy/core/report/DownloadReport.java +++ b/src/java/org/apache/ivy/core/report/DownloadReport.java @@ -1,57 +1,57 @@ -/* - * 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.core.report; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.module.descriptor.Artifact; - -/** - * - */ -public class DownloadReport { - private Map artifacts = new HashMap(); - - public void addArtifactReport(ArtifactDownloadReport adr) { - artifacts.put(adr.getArtifact(), adr); - } - - public ArtifactDownloadReport[] getArtifactsReports() { - return (ArtifactDownloadReport[]) artifacts.values().toArray( - new ArtifactDownloadReport[artifacts.size()]); - } - - public ArtifactDownloadReport[] getArtifactsReports(DownloadStatus status) { - List ret = new ArrayList(artifacts.size()); - for (Iterator iter = artifacts.values().iterator(); iter.hasNext();) { - ArtifactDownloadReport adr = (ArtifactDownloadReport) iter.next(); - if (adr.getDownloadStatus() == status) { - ret.add(adr); - } - } - return (ArtifactDownloadReport[]) ret.toArray(new ArtifactDownloadReport[ret.size()]); - } - - public ArtifactDownloadReport getArtifactReport(Artifact artifact) { - return (ArtifactDownloadReport) artifacts.get(artifact); - } -} +/* + * 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.core.report; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.module.descriptor.Artifact; + +/** + * + */ +public class DownloadReport { + private Map artifacts = new HashMap(); + + public void addArtifactReport(ArtifactDownloadReport adr) { + artifacts.put(adr.getArtifact(), adr); + } + + public ArtifactDownloadReport[] getArtifactsReports() { + return (ArtifactDownloadReport[]) artifacts.values().toArray( + new ArtifactDownloadReport[artifacts.size()]); + } + + public ArtifactDownloadReport[] getArtifactsReports(DownloadStatus status) { + List ret = new ArrayList(artifacts.size()); + for (Iterator iter = artifacts.values().iterator(); iter.hasNext();) { + ArtifactDownloadReport adr = (ArtifactDownloadReport) iter.next(); + if (adr.getDownloadStatus() == status) { + ret.add(adr); + } + } + return (ArtifactDownloadReport[]) ret.toArray(new ArtifactDownloadReport[ret.size()]); + } + + public ArtifactDownloadReport getArtifactReport(Artifact artifact) { + return (ArtifactDownloadReport) artifacts.get(artifact); + } +} diff --git a/src/java/org/apache/ivy/core/report/DownloadStatus.java b/src/java/org/apache/ivy/core/report/DownloadStatus.java index ed215bf0..88f63382 100644 --- a/src/java/org/apache/ivy/core/report/DownloadStatus.java +++ b/src/java/org/apache/ivy/core/report/DownloadStatus.java @@ -1,42 +1,42 @@ -/* - * 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.core.report; - -/** - * - */ -public class DownloadStatus { - private String name; - - private DownloadStatus(String name) { - this.name = name; - } - - /** - * means that download was not required - */ - public static final DownloadStatus NO = new DownloadStatus("no"); - - public static final DownloadStatus SUCCESSFUL = new DownloadStatus("successful"); - - public static final DownloadStatus FAILED = new DownloadStatus("failed"); - - public String toString() { - return name; - } -} +/* + * 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.core.report; + +/** + * + */ +public class DownloadStatus { + private String name; + + private DownloadStatus(String name) { + this.name = name; + } + + /** + * means that download was not required + */ + public static final DownloadStatus NO = new DownloadStatus("no"); + + public static final DownloadStatus SUCCESSFUL = new DownloadStatus("successful"); + + public static final DownloadStatus FAILED = new DownloadStatus("failed"); + + public String toString() { + return name; + } +} diff --git a/src/java/org/apache/ivy/core/report/ResolveReport.java b/src/java/org/apache/ivy/core/report/ResolveReport.java index 79d38dd2..7d115f10 100644 --- a/src/java/org/apache/ivy/core/report/ResolveReport.java +++ b/src/java/org/apache/ivy/core/report/ResolveReport.java @@ -1,243 +1,243 @@ -/* - * 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.core.report; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.plugins.report.ReportOutputter; -import org.apache.ivy.util.filter.Filter; - -/** - * Represents a whole resolution report for a module - */ -public class ResolveReport { - private ModuleDescriptor md; - - private Map confReports = new LinkedHashMap(); - - private List problemMessages; - - private List dependencies; // the list of all dependencies resolved, ordered from the more - - // dependent to the less dependent - - private List artifacts; - - private long resolveTime; - - private long downloadTime; - - private String resolveId; - - public ResolveReport(ModuleDescriptor md) { - this(md, ResolveOptions.getDefaultResolveId(md)); - } - - public ResolveReport(ModuleDescriptor md, String resolveId) { - this.md = md; - this.resolveId = resolveId; - } - - public void addReport(String conf, ConfigurationResolveReport report) { - confReports.put(conf, report); - } - - public ConfigurationResolveReport getConfigurationReport(String conf) { - return (ConfigurationResolveReport) confReports.get(conf); - } - - public String[] getConfigurations() { - return (String[]) confReports.keySet().toArray(new String[confReports.size()]); - } - - public boolean hasError() { - boolean hasError = false; - for (Iterator it = confReports.values().iterator(); it.hasNext() && !hasError;) { - ConfigurationResolveReport report = (ConfigurationResolveReport) it.next(); - hasError |= report.hasError(); - } - return hasError; - } - - public void output(ReportOutputter[] outputters, File cache) { - for (int i = 0; i < outputters.length; i++) { - outputters[i].output(this, cache); - } - } - - public ModuleDescriptor getModuleDescriptor() { - return md; - } - - public IvyNode[] getEvictedNodes() { - Collection all = new HashSet(); - for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { - ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); - all.addAll(Arrays.asList(report.getEvictedNodes())); - } - return (IvyNode[]) all.toArray(new IvyNode[all.size()]); - } - - public IvyNode[] getUnresolvedDependencies() { - Collection all = new HashSet(); - for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { - ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); - all.addAll(Arrays.asList(report.getUnresolvedDependencies())); - } - return (IvyNode[]) all.toArray(new IvyNode[all.size()]); - } - - public ArtifactDownloadReport[] getFailedArtifactsReports() { - Collection all = new HashSet(); - for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { - ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); - all.addAll(Arrays.asList(report.getFailedArtifactsReports())); - } - return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]); - } - - public boolean hasChanged() { - for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { - ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); - if (report.hasChanged()) { - return true; - } - } - return false; - } - - public void setProblemMessages(List problems) { - problemMessages = problems; - } - - public List getProblemMessages() { - return problemMessages; - } - - public List getAllProblemMessages() { - List ret = new ArrayList(problemMessages); - for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { - ConfigurationResolveReport r = (ConfigurationResolveReport) iter.next(); - IvyNode[] unresolved = r.getUnresolvedDependencies(); - for (int i = 0; i < unresolved.length; i++) { - String errMsg = unresolved[i].getProblemMessage(); - if (errMsg.length() > 0) { - ret.add("unresolved dependency: " + unresolved[i].getId() + ": " + errMsg); - } else { - ret.add("unresolved dependency: " + unresolved[i].getId()); - } - } - ArtifactDownloadReport[] adrs = r.getFailedArtifactsReports(); - for (int i = 0; i < adrs.length; i++) { - ret.add("download failed: " + adrs[i].getArtifact()); - } - } - return ret; - } - - public void setDependencies(List dependencies, Filter artifactFilter) { - this.dependencies = dependencies; - // collect list of artifacts - artifacts = new ArrayList(); - for (Iterator iter = dependencies.iterator(); iter.hasNext();) { - IvyNode dependency = (IvyNode) iter.next(); - if (!dependency.isCompletelyEvicted() && !dependency.hasProblem()) { - artifacts.addAll(Arrays.asList(dependency.getSelectedArtifacts(artifactFilter))); - } - // update the configurations reports with the dependencies - // these reports will be completed later with download information, if any - String[] dconfs = dependency.getRootModuleConfigurations(); - for (int j = 0; j < dconfs.length; j++) { - ConfigurationResolveReport configurationReport = getConfigurationReport(dconfs[j]); - if (configurationReport != null) { - configurationReport.addDependency(dependency); - } - } - } - } - - /** - * Returns the list of all dependencies concerned by this report as a List of IvyNode ordered - * from the more dependent to the least one - * - * @return - */ - public List getDependencies() { - return dependencies; - } - - /** - * Returns the list of all artifacts which should be downloaded per this resolve To know if the - * artifact have actually been downloaded use information found in ConfigurationResolveReport. - * - * @return - */ - public List getArtifacts() { - return artifacts; - } - - /** - * gives all the modules ids concerned by this report, from the most dependent to the least one - * - * @return a list of ModuleId - */ - public List getModuleIds() { - List ret = new ArrayList(); - List sortedDependencies = new ArrayList(dependencies); - for (Iterator iter = sortedDependencies.iterator(); iter.hasNext();) { - IvyNode dependency = (IvyNode) iter.next(); - ModuleId mid = dependency.getResolvedId().getModuleId(); - if (!ret.contains(mid)) { - ret.add(mid); - } - } - return ret; - } - - public void setResolveTime(long elapsedTime) { - resolveTime = elapsedTime; - } - - public long getResolveTime() { - return resolveTime; - } - - public void setDownloadTime(long elapsedTime) { - downloadTime = elapsedTime; - } - - public long getDownloadTime() { - return downloadTime; - } - - public String getResolveId() { - return resolveId; - } -} +/* + * 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.core.report; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.plugins.report.ReportOutputter; +import org.apache.ivy.util.filter.Filter; + +/** + * Represents a whole resolution report for a module + */ +public class ResolveReport { + private ModuleDescriptor md; + + private Map confReports = new LinkedHashMap(); + + private List problemMessages; + + private List dependencies; // the list of all dependencies resolved, ordered from the more + + // dependent to the less dependent + + private List artifacts; + + private long resolveTime; + + private long downloadTime; + + private String resolveId; + + public ResolveReport(ModuleDescriptor md) { + this(md, ResolveOptions.getDefaultResolveId(md)); + } + + public ResolveReport(ModuleDescriptor md, String resolveId) { + this.md = md; + this.resolveId = resolveId; + } + + public void addReport(String conf, ConfigurationResolveReport report) { + confReports.put(conf, report); + } + + public ConfigurationResolveReport getConfigurationReport(String conf) { + return (ConfigurationResolveReport) confReports.get(conf); + } + + public String[] getConfigurations() { + return (String[]) confReports.keySet().toArray(new String[confReports.size()]); + } + + public boolean hasError() { + boolean hasError = false; + for (Iterator it = confReports.values().iterator(); it.hasNext() && !hasError;) { + ConfigurationResolveReport report = (ConfigurationResolveReport) it.next(); + hasError |= report.hasError(); + } + return hasError; + } + + public void output(ReportOutputter[] outputters, File cache) { + for (int i = 0; i < outputters.length; i++) { + outputters[i].output(this, cache); + } + } + + public ModuleDescriptor getModuleDescriptor() { + return md; + } + + public IvyNode[] getEvictedNodes() { + Collection all = new HashSet(); + for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { + ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); + all.addAll(Arrays.asList(report.getEvictedNodes())); + } + return (IvyNode[]) all.toArray(new IvyNode[all.size()]); + } + + public IvyNode[] getUnresolvedDependencies() { + Collection all = new HashSet(); + for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { + ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); + all.addAll(Arrays.asList(report.getUnresolvedDependencies())); + } + return (IvyNode[]) all.toArray(new IvyNode[all.size()]); + } + + public ArtifactDownloadReport[] getFailedArtifactsReports() { + Collection all = new HashSet(); + for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { + ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); + all.addAll(Arrays.asList(report.getFailedArtifactsReports())); + } + return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]); + } + + public boolean hasChanged() { + for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { + ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next(); + if (report.hasChanged()) { + return true; + } + } + return false; + } + + public void setProblemMessages(List problems) { + problemMessages = problems; + } + + public List getProblemMessages() { + return problemMessages; + } + + public List getAllProblemMessages() { + List ret = new ArrayList(problemMessages); + for (Iterator iter = confReports.values().iterator(); iter.hasNext();) { + ConfigurationResolveReport r = (ConfigurationResolveReport) iter.next(); + IvyNode[] unresolved = r.getUnresolvedDependencies(); + for (int i = 0; i < unresolved.length; i++) { + String errMsg = unresolved[i].getProblemMessage(); + if (errMsg.length() > 0) { + ret.add("unresolved dependency: " + unresolved[i].getId() + ": " + errMsg); + } else { + ret.add("unresolved dependency: " + unresolved[i].getId()); + } + } + ArtifactDownloadReport[] adrs = r.getFailedArtifactsReports(); + for (int i = 0; i < adrs.length; i++) { + ret.add("download failed: " + adrs[i].getArtifact()); + } + } + return ret; + } + + public void setDependencies(List dependencies, Filter artifactFilter) { + this.dependencies = dependencies; + // collect list of artifacts + artifacts = new ArrayList(); + for (Iterator iter = dependencies.iterator(); iter.hasNext();) { + IvyNode dependency = (IvyNode) iter.next(); + if (!dependency.isCompletelyEvicted() && !dependency.hasProblem()) { + artifacts.addAll(Arrays.asList(dependency.getSelectedArtifacts(artifactFilter))); + } + // update the configurations reports with the dependencies + // these reports will be completed later with download information, if any + String[] dconfs = dependency.getRootModuleConfigurations(); + for (int j = 0; j < dconfs.length; j++) { + ConfigurationResolveReport configurationReport = getConfigurationReport(dconfs[j]); + if (configurationReport != null) { + configurationReport.addDependency(dependency); + } + } + } + } + + /** + * Returns the list of all dependencies concerned by this report as a List of IvyNode ordered + * from the more dependent to the least one + * + * @return + */ + public List getDependencies() { + return dependencies; + } + + /** + * Returns the list of all artifacts which should be downloaded per this resolve To know if the + * artifact have actually been downloaded use information found in ConfigurationResolveReport. + * + * @return + */ + public List getArtifacts() { + return artifacts; + } + + /** + * gives all the modules ids concerned by this report, from the most dependent to the least one + * + * @return a list of ModuleId + */ + public List getModuleIds() { + List ret = new ArrayList(); + List sortedDependencies = new ArrayList(dependencies); + for (Iterator iter = sortedDependencies.iterator(); iter.hasNext();) { + IvyNode dependency = (IvyNode) iter.next(); + ModuleId mid = dependency.getResolvedId().getModuleId(); + if (!ret.contains(mid)) { + ret.add(mid); + } + } + return ret; + } + + public void setResolveTime(long elapsedTime) { + resolveTime = elapsedTime; + } + + public long getResolveTime() { + return resolveTime; + } + + public void setDownloadTime(long elapsedTime) { + downloadTime = elapsedTime; + } + + public long getDownloadTime() { + return downloadTime; + } + + public String getResolveId() { + return resolveId; + } +} diff --git a/src/java/org/apache/ivy/core/resolve/DefaultModuleRevision.java b/src/java/org/apache/ivy/core/resolve/DefaultModuleRevision.java index 95d5a331..d1892a01 100644 --- a/src/java/org/apache/ivy/core/resolve/DefaultModuleRevision.java +++ b/src/java/org/apache/ivy/core/resolve/DefaultModuleRevision.java @@ -1,100 +1,100 @@ -/* - * 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.core.resolve; - -import java.net.URL; -import java.util.Date; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -/** - * - */ -public class DefaultModuleRevision implements ResolvedModuleRevision { - private DependencyResolver resolver; - - private DependencyResolver artifactResolver; - - private ModuleDescriptor descriptor; - - private boolean isDownloaded; - - private boolean isSearched; - - private URL localMDUrl; - - public DefaultModuleRevision(DependencyResolver resolver, DependencyResolver artifactResolver, - ModuleDescriptor descriptor, boolean searched, boolean downloaded, URL localMDUrl) { - this.resolver = resolver; - this.artifactResolver = artifactResolver; - this.descriptor = descriptor; - isSearched = searched; - isDownloaded = downloaded; - this.localMDUrl = localMDUrl; - } - - public DependencyResolver getResolver() { - return resolver; - } - - public DependencyResolver getArtifactResolver() { - return artifactResolver; - } - - public ModuleDescriptor getDescriptor() { - return descriptor; - } - - public ModuleRevisionId getId() { - return descriptor.getResolvedModuleRevisionId(); - } - - public Date getPublicationDate() { - return descriptor.getResolvedPublicationDate(); - } - - public boolean equals(Object obj) { - if (!(obj instanceof ResolvedModuleRevision)) { - return false; - } - return ((ResolvedModuleRevision) obj).getId().equals(getId()); - } - - public int hashCode() { - return getId().hashCode(); - } - - public String toString() { - return getId().toString(); - } - - public boolean isDownloaded() { - return isDownloaded; - } - - public boolean isSearched() { - return isSearched; - } - - public URL getLocalMDUrl() { - return localMDUrl; - } - -} +/* + * 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.core.resolve; + +import java.net.URL; +import java.util.Date; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +/** + * + */ +public class DefaultModuleRevision implements ResolvedModuleRevision { + private DependencyResolver resolver; + + private DependencyResolver artifactResolver; + + private ModuleDescriptor descriptor; + + private boolean isDownloaded; + + private boolean isSearched; + + private URL localMDUrl; + + public DefaultModuleRevision(DependencyResolver resolver, DependencyResolver artifactResolver, + ModuleDescriptor descriptor, boolean searched, boolean downloaded, URL localMDUrl) { + this.resolver = resolver; + this.artifactResolver = artifactResolver; + this.descriptor = descriptor; + isSearched = searched; + isDownloaded = downloaded; + this.localMDUrl = localMDUrl; + } + + public DependencyResolver getResolver() { + return resolver; + } + + public DependencyResolver getArtifactResolver() { + return artifactResolver; + } + + public ModuleDescriptor getDescriptor() { + return descriptor; + } + + public ModuleRevisionId getId() { + return descriptor.getResolvedModuleRevisionId(); + } + + public Date getPublicationDate() { + return descriptor.getResolvedPublicationDate(); + } + + public boolean equals(Object obj) { + if (!(obj instanceof ResolvedModuleRevision)) { + return false; + } + return ((ResolvedModuleRevision) obj).getId().equals(getId()); + } + + public int hashCode() { + return getId().hashCode(); + } + + public String toString() { + return getId().toString(); + } + + public boolean isDownloaded() { + return isDownloaded; + } + + public boolean isSearched() { + return isSearched; + } + + public URL getLocalMDUrl() { + return localMDUrl; + } + +} diff --git a/src/java/org/apache/ivy/core/resolve/DownloadOptions.java b/src/java/org/apache/ivy/core/resolve/DownloadOptions.java index 25489c30..3fee4d5b 100644 --- a/src/java/org/apache/ivy/core/resolve/DownloadOptions.java +++ b/src/java/org/apache/ivy/core/resolve/DownloadOptions.java @@ -1,67 +1,67 @@ -/* - * 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.core.resolve; - -import java.io.File; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.settings.IvySettings; - -public class DownloadOptions { - private IvySettings settings; - - private CacheManager cacheManager; - - private EventManager eventManager = null; // can be null - - private boolean useOrigin = false; - - public DownloadOptions(IvySettings settings, File cache) { - this(settings, new CacheManager(settings, cache)); - } - - public DownloadOptions(IvySettings settings, CacheManager cacheManager) { - this(settings, cacheManager, null, false); - } - - public DownloadOptions(IvySettings settings, CacheManager cacheManager, - EventManager eventManager, boolean useOrigin) { - this.settings = settings; - this.cacheManager = cacheManager; - this.eventManager = eventManager; - this.useOrigin = useOrigin; - } - - public IvySettings getSettings() { - return settings; - } - - public boolean isUseOrigin() { - return useOrigin; - } - - public CacheManager getCacheManager() { - return cacheManager; - } - - public EventManager getEventManager() { - return eventManager; - } - -} +/* + * 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.core.resolve; + +import java.io.File; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.settings.IvySettings; + +public class DownloadOptions { + private IvySettings settings; + + private CacheManager cacheManager; + + private EventManager eventManager = null; // can be null + + private boolean useOrigin = false; + + public DownloadOptions(IvySettings settings, File cache) { + this(settings, new CacheManager(settings, cache)); + } + + public DownloadOptions(IvySettings settings, CacheManager cacheManager) { + this(settings, cacheManager, null, false); + } + + public DownloadOptions(IvySettings settings, CacheManager cacheManager, + EventManager eventManager, boolean useOrigin) { + this.settings = settings; + this.cacheManager = cacheManager; + this.eventManager = eventManager; + this.useOrigin = useOrigin; + } + + public IvySettings getSettings() { + return settings; + } + + public boolean isUseOrigin() { + return useOrigin; + } + + public CacheManager getCacheManager() { + return cacheManager; + } + + public EventManager getEventManager() { + return eventManager; + } + +} diff --git a/src/java/org/apache/ivy/core/resolve/IvyNode.java b/src/java/org/apache/ivy/core/resolve/IvyNode.java index 76b9732f..29311774 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNode.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNode.java @@ -1,1149 +1,1149 @@ -/* - * 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.core.resolve; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Stack; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.event.resolve.EndResolveDependencyEvent; -import org.apache.ivy.core.event.resolve.StartResolveDependencyEvent; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.IncludeRule; -import org.apache.ivy.core.module.descriptor.MDArtifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.IvyNodeCallers.Caller; -import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.matcher.MatcherHelper; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.filter.Filter; -import org.apache.ivy.util.filter.FilterHelper; - -public class IvyNode implements Comparable { - private static final Pattern FALLBACK_CONF_PATTERN = Pattern.compile("(.+)\\((.*)\\)"); - - private static final class NodeConf { - private IvyNode node; - - private String conf; - - public NodeConf(IvyNode node, String conf) { - if (node == null) { - throw new NullPointerException("node must not null"); - } - if (conf == null) { - throw new NullPointerException("conf must not null"); - } - this.node = node; - this.conf = conf; - } - - public final String getConf() { - return conf; - } - - public final IvyNode getNode() { - return node; - } - - public boolean equals(Object obj) { - if (!(obj instanceof NodeConf)) { - return false; - } - return getNode().equals(((NodeConf) obj).getNode()) - && getConf().equals(((NodeConf) obj).getConf()); - } - - public int hashCode() { - int hash = 33; - hash += getNode().hashCode() * 17; - hash += getConf().hashCode() * 17; - return hash; - } - } - - // //////// CONTEXT - private ResolveData data; - - private IvySettings settings; - - // //////// DELEGATES - private IvyNodeCallers callers; - - private IvyNodeEviction eviction; - - // //////// MAIN DATA - - private IvyNode root; - - // id as requested, i.e. may be with latest rev - private ModuleRevisionId id; - - // set only when node has been built or updated from a DependencyDescriptor - // Map(IvyNode parent -> DependencyDescriptor) - private Map dds = new HashMap(); - - // Set when data has been loaded only, or when constructed from a module descriptor - private ModuleDescriptor md; - - private ResolvedModuleRevision module; - - // //////// LOADING METADATA - private Exception problem = null; - - private boolean downloaded = false; - - private boolean searched = false; - - private Collection confsToFetch = new HashSet(); - - private Collection fetchedConfigurations = new HashSet(); - - private Collection loadedRootModuleConfs = new HashSet(); - - // //////// USAGE DATA - - // Map (String rootConfName -> Set(String confName)) - // used to know which configurations of the dependency are required - // for each root module configuration - private Map rootModuleConfs = new HashMap(); - - // Map (NodeConf in -> Set(String conf)) - private Map requiredConfs = new HashMap(); - - // Map (String rootModuleConf -> Set(DependencyArtifactDescriptor)) - private Map dependencyArtifacts = new HashMap(); - - // Map (String rootModuleConf -> Set(IncludeRule)) - private Map dependencyIncludes = new HashMap(); - - public IvyNode(ResolveData data, IvyNode parent, DependencyDescriptor dd) { - id = dd.getDependencyRevisionId(); - dds.put(parent, dd); - root = parent.getRoot(); - init(data); - } - - public IvyNode(ResolveData data, ModuleDescriptor md) { - id = md.getModuleRevisionId(); - this.md = md; - root = this; - init(data); - } - - private void init(ResolveData data) { - this.data = data; - settings = data.getSettings(); - eviction = new IvyNodeEviction(this); - callers = new IvyNodeCallers(this); - } - - /** - * After the call node may be discarded. To avoid using discarded node, make sure to get the - * real node after the call IvyNode node = ... node.loadData(); node = node.getRealNode(); ... - */ - public boolean loadData(String rootModuleConf, IvyNode parent, String parentConf, String conf, - boolean shouldBePublic) { - boolean loaded = false; - if (!isEvicted(rootModuleConf) - && (hasConfigurationsToLoad() || !isRootModuleConfLoaded(rootModuleConf)) - && !hasProblem()) { - markRootModuleConfLoaded(rootModuleConf); - if (md == null) { - DependencyResolver resolver = data.getSettings().getResolver(getModuleId()); - if (resolver == null) { - Message.error("no resolver found for " + getModuleId() - + ": check your configuration"); - problem = new RuntimeException("no resolver found for " + getModuleId() - + ": check your configuration"); - data.getReport().addDependency(this); - return false; - } - try { - Message.debug("\tusing " + resolver + " to resolve " + getId()); - DependencyDescriptor dependencyDescriptor = getDependencyDescriptor(parent); - data.getEventManager().fireIvyEvent( - new StartResolveDependencyEvent(resolver, dependencyDescriptor)); - module = resolver.getDependency(dependencyDescriptor, data); - data.getEventManager().fireIvyEvent( - new EndResolveDependencyEvent(resolver, dependencyDescriptor, module)); - if (module != null) { - data.getCacheManager().saveResolver(module.getDescriptor(), - module.getResolver().getName()); - data.getCacheManager().saveArtResolver(module.getDescriptor(), - module.getArtifactResolver().getName()); - if (settings.logModuleWhenFound()) { - Message.info("\tfound " + module.getId() + " in " - + module.getResolver().getName()); - } else { - Message.verbose("\tfound " + module.getId() + " in " - + module.getResolver().getName()); - } - - if (data.getSettings().getVersionMatcher().isDynamic(getId())) { - // IVY-56: check if revision has actually been resolved - if (data.getSettings().getVersionMatcher().isDynamic(module.getId())) { - Message - .error("impossible to resolve dynamic revision for " - + getId() - + ": check your configuration and make sure revision is part of your pattern"); - problem = new RuntimeException( - "impossible to resolve dynamic revision"); - data.getReport().addDependency(this); - return false; - } - IvyNode resolved = data.getNode(module.getId()); - if (resolved != null) { - // exact revision has already been resolved - // => update it and discard this node - md = module.getDescriptor(); // needed for handleConfiguration - if (!handleConfiguration(loaded, rootModuleConf, parent, - parentConf, conf, shouldBePublic)) { - return false; - } - - if (resolved.md == null) { - resolved.md = md; - } - if (resolved.module == null) { - resolved.module = module; - } - resolved.downloaded |= module.isDownloaded(); - resolved.searched |= module.isSearched(); - resolved.dds.putAll(dds); - resolved.updateDataFrom(this, rootModuleConf); - resolved.loadData(rootModuleConf, parent, parentConf, conf, - shouldBePublic); - DependencyDescriptor dd = dependencyDescriptor; - if (dd != null) { - resolved.addDependencyArtifacts(rootModuleConf, dd - .getDependencyArtifacts(parentConf)); - resolved.addDependencyIncludes(rootModuleConf, dd - .getIncludeRules(parentConf)); - } - data.replaceNode(getId(), resolved, rootModuleConf); // this - // actually - // discards - // the node - - if (settings.logResolvedRevision()) { - Message.info("\t[" + module.getId().getRevision() + "] " - + getId()); - } else { - Message.verbose("\t[" + module.getId().getRevision() + "] " - + getId()); - } - - return true; - } - } - downloaded = module.isDownloaded(); - searched = module.isSearched(); - } else { - Message.warn("\tmodule not found: " + getId()); - resolver.reportFailure(); - problem = new RuntimeException("not found"); - } - } catch (Exception e) { - problem = e; - } - - // still not resolved, report error - if (module == null) { - data.getReport().addDependency(this); - return false; - } else { - loaded = true; - if (settings.getVersionMatcher().isDynamic(getId())) { - if (settings.logResolvedRevision()) { - Message.info("\t[" + module.getId().getRevision() + "] " + getId()); - } else { - Message.verbose("\t[" + module.getId().getRevision() + "] " + getId()); - } - } - md = module.getDescriptor(); - confsToFetch.remove("*"); - updateConfsToFetch(Arrays.asList(resolveSpecialConfigurations( - getRequiredConfigurations(parent, parentConf), this))); - } - } else { - loaded = true; - } - } - if (hasProblem()) { - data.getReport().addDependency(this); - return handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, - shouldBePublic) - && loaded; - } - if (!handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, shouldBePublic)) { - return false; - } - DependencyDescriptor dd = getDependencyDescriptor(parent); - if (dd != null) { - addDependencyArtifacts(rootModuleConf, dd.getDependencyArtifacts(parentConf)); - addDependencyIncludes(rootModuleConf, dd.getIncludeRules(parentConf)); - } - return loaded; - - } - - public Collection getDependencies(String rootModuleConf, String[] confs) { - if (md == null) { - throw new IllegalStateException( - "impossible to get dependencies when data has not been loaded"); - } - if (Arrays.asList(confs).contains("*")) { - confs = md.getConfigurationsNames(); - } - Collection deps = new HashSet(); - for (int i = 0; i < confs.length; i++) { - deps.addAll(getDependencies(rootModuleConf, confs[i], confs[i])); - } - return deps; - } - - public Collection getDependencies(String rootModuleConf, String conf, String requestedConf) { - if (md == null) { - throw new IllegalStateException( - "impossible to get dependencies when data has not been loaded"); - } - DependencyDescriptor[] dds = md.getDependencies(); - Collection dependencies = new LinkedHashSet(); // it's important to respect dependencies - // order - for (int i = 0; i < dds.length; i++) { - DependencyDescriptor dd = dds[i]; - String[] dependencyConfigurations = dd.getDependencyConfigurations(conf, requestedConf); - if (dependencyConfigurations.length == 0) { - // no configuration of the dependency is required for current confs : - // it is exactly the same as if there was no dependency at all on it - continue; - } - if (isDependencyModuleExcluded(rootModuleConf, dd.getDependencyRevisionId(), conf)) { - // the whole module is excluded, it is considered as not being part of dependencies - // at all - Message.verbose("excluding " + dd.getDependencyRevisionId() + " in " + conf); - continue; - } - IvyNode depNode = data.getNode(dd.getDependencyRevisionId()); - if (depNode == null) { - depNode = new IvyNode(data, this, dd); - } else { - depNode.addDependencyDescriptor(this, dd); - if (depNode.hasProblem()) { - // dependency already tried to be resolved, but unsuccessfully - // nothing special to do - } - - } - Collection confs = Arrays.asList(resolveSpecialConfigurations(dependencyConfigurations, - depNode)); - depNode.updateConfsToFetch(confs); - depNode.setRequiredConfs(this, conf, confs); - - depNode.addCaller(rootModuleConf, this, conf, dependencyConfigurations, dd); - dependencies.add(depNode); - } - return dependencies; - } - - private void addDependencyDescriptor(IvyNode parent, DependencyDescriptor dd) { - dds.put(parent, dd); - } - - public DependencyDescriptor getDependencyDescriptor(IvyNode parent) { - return (DependencyDescriptor) dds.get(parent); - } - - private boolean isDependencyModuleExcluded(String rootModuleConf, - ModuleRevisionId dependencyRevisionId, String conf) { - return callers.doesCallersExclude(rootModuleConf, DefaultArtifact.newIvyArtifact( - dependencyRevisionId, null)); - } - - public boolean hasConfigurationsToLoad() { - return !confsToFetch.isEmpty(); - } - - private boolean markRootModuleConfLoaded(String rootModuleConf) { - return loadedRootModuleConfs.add(rootModuleConf); - } - - private boolean isRootModuleConfLoaded(String rootModuleConf) { - return loadedRootModuleConfs.contains(rootModuleConf); - } - - private boolean handleConfiguration(boolean loaded, String rootModuleConf, IvyNode parent, - String parentConf, String conf, boolean shouldBePublic) { - if (md != null) { - String[] confs = getRealConfs(conf); - for (int i = 0; i < confs.length; i++) { - Configuration c = md.getConfiguration(confs[i]); - if (c == null) { - confsToFetch.remove(conf); - if (!conf.equals(confs[i])) { - problem = new RuntimeException("configuration(s) not found in " + this - + ": " + conf + ". Missing configuration: " + confs[i] - + ". It was required from " + parent + " " + parentConf); - } else { - problem = new RuntimeException("configuration(s) not found in " + this - + ": " + confs[i] + ". It was required from " + parent + " " - + parentConf); - } - data.getReport().addDependency(this); - return false; - } else if (shouldBePublic && !isRoot() - && c.getVisibility() != Configuration.Visibility.PUBLIC) { - confsToFetch.remove(conf); - problem = new RuntimeException("configuration not public in " + this + ": " + c - + ". It was required from " + parent + " " + parentConf); - data.getReport().addDependency(this); - return false; - } - if (loaded) { - fetchedConfigurations.add(conf); - confsToFetch.removeAll(Arrays.asList(confs)); - confsToFetch.remove(conf); - } - addRootModuleConfigurations(rootModuleConf, confs); - } - } - return true; - } - - private String getDefaultConf(String conf) { - Matcher m = FALLBACK_CONF_PATTERN.matcher(conf); - if (m.matches()) { - return m.group(2); - } else { - return conf; - } - } - - private String getMainConf(String conf) { - Matcher m = FALLBACK_CONF_PATTERN.matcher(conf); - if (m.matches()) { - return m.group(1); - } else { - return null; - } - } - - public void updateConfsToFetch(Collection confs) { - confsToFetch.addAll(confs); - confsToFetch.removeAll(fetchedConfigurations); - } - - /** - * resolve the '*' special configurations if necessary and possible - */ - private String[] resolveSpecialConfigurations(String[] dependencyConfigurations, IvyNode node) { - if (dependencyConfigurations.length == 1 && dependencyConfigurations[0].startsWith("*") - && node != null && node.isLoaded()) { - String conf = dependencyConfigurations[0]; - if ("*".equals(conf)) { - return node.getDescriptor().getPublicConfigurationsNames(); - } - // there are exclusions in the configuration - List exclusions = Arrays.asList(conf.substring(2).split("\\!")); - - List ret = new ArrayList(Arrays.asList(node.getDescriptor() - .getPublicConfigurationsNames())); - ret.removeAll(exclusions); - - return (String[]) ret.toArray(new String[ret.size()]); - } - return dependencyConfigurations; - } - - /** - * returns the required configurations from the given node - * - * @param in - * @return - */ - public String[] getRequiredConfigurations(IvyNode in, String inConf) { - Collection req = (Collection) requiredConfs.get(new NodeConf(in, inConf)); - return req == null ? new String[0] : (String[]) req.toArray(new String[req.size()]); - } - - /** - * returns all the current required configurations of the node - * - * @return - */ - public String[] getRequiredConfigurations() { - Collection required = new ArrayList(confsToFetch.size() + fetchedConfigurations.size()); - required.addAll(fetchedConfigurations); - required.addAll(confsToFetch); - return (String[]) required.toArray(new String[required.size()]); - } - - private void setRequiredConfs(IvyNode parent, String parentConf, Collection confs) { - requiredConfs.put(new NodeConf(parent, parentConf), new HashSet(confs)); - } - - public Configuration getConfiguration(String conf) { - if (md == null) { - throw new IllegalStateException( - "impossible to get configuration when data has not been loaded"); - } - String defaultConf = getDefaultConf(conf); - conf = getMainConf(conf); - Configuration configuration = md.getConfiguration(conf); - if (configuration == null) { - configuration = md.getConfiguration(defaultConf); - } - return configuration; - } - - /** - * Returns the configurations of the dependency required in a given root module configuration. - * - * @param rootModuleConf - * @return - */ - public String[] getConfigurations(String rootModuleConf) { - Set depConfs = (Set) rootModuleConfs.get(rootModuleConf); - if (depConfs == null) { - return new String[0]; - } - return (String[]) depConfs.toArray(new String[depConfs.size()]); - } - - public void discardConf(String rootModuleConf, String conf) { - Set depConfs = (Set) rootModuleConfs.get(rootModuleConf); - if (depConfs == null) { - depConfs = new HashSet(); - rootModuleConfs.put(rootModuleConf, depConfs); - } - if (md != null) { - // remove all given dependency configurations to the set + extended ones - Configuration c = md.getConfiguration(conf); - if (conf != null) { - String[] exts = c.getExtends(); - for (int i = 0; i < exts.length; i++) { - discardConf(rootModuleConf, exts[i]); // recursive remove of extended - // configurations - } - depConfs.remove(c.getName()); - } else { - Message.warn("unknown configuration in " + getId() + ": " + conf); - } - } else { - depConfs.remove(conf); - } - } - - private void addRootModuleConfigurations(String rootModuleConf, String[] dependencyConfs) { - Set depConfs = (Set) rootModuleConfs.get(rootModuleConf); - if (depConfs == null) { - depConfs = new HashSet(); - rootModuleConfs.put(rootModuleConf, depConfs); - } - if (md != null) { - // add all given dependency configurations to the set + extended ones - for (int i = 0; i < dependencyConfs.length; i++) { - Configuration conf = md.getConfiguration(dependencyConfs[i]); - if (conf != null) { - String[] exts = conf.getExtends(); - addRootModuleConfigurations(rootModuleConf, exts); // recursive add of extended - // configurations - depConfs.add(conf.getName()); - } else { - Message.warn("unknown configuration in " + getId() + ": " + dependencyConfs[i]); - } - } - } else { - for (int i = 0; i < dependencyConfs.length; i++) { - depConfs.add(dependencyConfs[i]); - } - } - } - - /** - * Returns the root module configurations in which this dependency is required - * - * @return - */ - public String[] getRootModuleConfigurations() { - return (String[]) rootModuleConfs.keySet().toArray(new String[rootModuleConfs.size()]); - } - - public String[] getConfsToFetch() { - return (String[]) confsToFetch.toArray(new String[confsToFetch.size()]); - } - - public String[] getRealConfs(String conf) { - if (md == null) { - return new String[] {conf}; - } - String defaultConf = getDefaultConf(conf); - conf = getMainConf(conf); - if (md.getConfiguration(conf) == null) { - if ("".equals(defaultConf)) { - return new String[0]; - } - conf = defaultConf; - } - if (conf.startsWith("*")) { - return resolveSpecialConfigurations(new String[] {conf}, this); - } else if (conf.indexOf(',') != -1) { - String[] confs = conf.split(","); - for (int i = 0; i < confs.length; i++) { - confs[i] = confs[i].trim(); - } - } - return new String[] {conf}; - - } - - /** - * Finds and returns a path in callers from the given module id to the current node - * - * @param from - * the module id to start the path from - * @return a collection representing the path, starting with the from node, followed by the list - * of nodes being one path to the current node, excluded - */ - private Collection findPath(ModuleId from) { - return findPath(from, this, new LinkedList()); - } - - private Collection findPath(ModuleId from, IvyNode node, List path) { - IvyNode parent = (IvyNode) node.getDirectCallerFor(from); - if (parent == null) { - throw new IllegalArgumentException("no path from " + from + " to " + getId() + " found"); - } - if (path.contains(parent)) { - path.add(0, parent); - Message - .verbose("circular dependency found while looking for the path for another one: was looking for " - + from + " as a caller of " + path.get(path.size() - 1)); - return path; - } - path.add(0, parent); - if (parent.getId().getModuleId().equals(from)) { - return path; - } - return findPath(from, parent, path); - } - - private void updateDataFrom(IvyNode node, String rootModuleConf) { - // update callers - callers.updateFrom(node.callers, rootModuleConf); - - // update requiredConfs - updateMapOfSet(node.requiredConfs, requiredConfs); - - // update rootModuleConfs - updateMapOfSetForKey(node.rootModuleConfs, rootModuleConfs, rootModuleConf); - - // update dependencyArtifactsIncludes - updateMapOfSetForKey(node.dependencyArtifacts, dependencyArtifacts, rootModuleConf); - - // update confsToFetch - updateConfsToFetch(node.fetchedConfigurations); - updateConfsToFetch(node.confsToFetch); - } - - private void updateMapOfSet(Map from, Map to) { - for (Iterator iter = from.keySet().iterator(); iter.hasNext();) { - Object key = iter.next(); - updateMapOfSetForKey(from, to, key); - } - } - - private void updateMapOfSetForKey(Map from, Map to, Object key) { - Set set = (Set) from.get(key); - if (set != null) { - Set toupdate = (Set) to.get(key); - if (toupdate != null) { - toupdate.addAll(set); - } else { - to.put(key, new HashSet(set)); - } - } - } - - /** - * Returns all the artifacts of this dependency required in all the root module configurations - * - * @return - */ - public Artifact[] getAllArtifacts() { - Set ret = new HashSet(); - for (Iterator it = rootModuleConfs.keySet().iterator(); it.hasNext();) { - String rootModuleConf = (String) it.next(); - ret.addAll(Arrays.asList(getArtifacts(rootModuleConf))); - } - return (Artifact[]) ret.toArray(new Artifact[ret.size()]); - } - - /** - * Returns all the artifacts of this dependency required in the root module configurations in - * which the node is not evicted - * - * @param artifactFilter - * @return - */ - public Artifact[] getSelectedArtifacts(Filter artifactFilter) { - Collection ret = new HashSet(); - for (Iterator it = rootModuleConfs.keySet().iterator(); it.hasNext();) { - String rootModuleConf = (String) it.next(); - if (!isEvicted(rootModuleConf)) { - ret.addAll(Arrays.asList(getArtifacts(rootModuleConf))); - } - } - ret = FilterHelper.filter(ret, artifactFilter); - return (Artifact[]) ret.toArray(new Artifact[ret.size()]); - } - - /** - * Returns the artifacts of this dependency required in the configurations themselves required - * in the given root module configuration - * - * @param rootModuleConf - * @return - */ - public Artifact[] getArtifacts(String rootModuleConf) { - // first we look for the dependency configurations required - // in the given root module configuration - Set confs = (Set) rootModuleConfs.get(rootModuleConf); - if (confs == null) { - // no configuration required => no artifact required - return new Artifact[0]; - } - - Set artifacts = new HashSet(); // the set we fill before returning - - // we check if we have dependencyArtifacts includes description for this rootModuleConf - Set dependencyArtifacts = (Set) this.dependencyArtifacts.get(rootModuleConf); - - if (md.isDefault() && dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) { - // the descriptor is a default one: it has been generated from nothing - // moreover, we have dependency artifacts description - // these descritions are thus used as if they were declared in the module - // descriptor. If one is not really present, the error will be raised - // at download time - for (Iterator it = dependencyArtifacts.iterator(); it.hasNext();) { - DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor) it.next(); - artifacts.add(new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), dad - .getUrl(), dad.getExtraAttributes())); - } - } else { - Set includes = (Set) dependencyIncludes.get(rootModuleConf); - - if ((dependencyArtifacts == null || dependencyArtifacts.isEmpty()) - && (includes == null || includes.isEmpty())) { - // no artifacts / includes: we get all artifacts as defined by the descriptor - for (Iterator iter = confs.iterator(); iter.hasNext();) { - String conf = (String) iter.next(); - artifacts.addAll(Arrays.asList(md.getArtifacts(conf))); - } - } else { - // we have to get only artifacts listed as "includes" - - // first we get all artifacts as defined by the module descriptor - // and classify them by artifact id - Map allArtifacts = new HashMap(); - for (Iterator iter = confs.iterator(); iter.hasNext();) { - String conf = (String) iter.next(); - Artifact[] arts = md.getArtifacts(conf); - for (int i = 0; i < arts.length; i++) { - allArtifacts.put(arts[i].getId().getArtifactId(), arts[i]); - } - } - - // now we add caller defined ones - for (Iterator it = dependencyArtifacts.iterator(); it.hasNext();) { - DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor) it.next(); - artifacts.add(new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), - dad.getUrl(), dad.getExtraAttributes())); - } - - // and now we filter according to include rules - for (Iterator it = includes.iterator(); it.hasNext();) { - IncludeRule dad = (IncludeRule) it.next(); - Collection arts = findArtifactsMatching(dad, allArtifacts); - if (arts.isEmpty()) { - Message.error("a required artifact is not listed by module descriptor: " - + dad.getId()); - // we remove it from required list to prevent message to be displayed more - // than once - it.remove(); - } else { - Message.debug(this + " in " + rootModuleConf + ": including " + arts); - artifacts.addAll(arts); - } - } - } - } - - // now excludes artifacts that aren't accepted by any caller - for (Iterator iter = artifacts.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - boolean excluded = callers.doesCallersExclude(rootModuleConf, artifact); - if (excluded) { - Message.debug(this + " in " + rootModuleConf + ": excluding " + artifact); - iter.remove(); - } - } - return (Artifact[]) artifacts.toArray(new Artifact[artifacts.size()]); - } - - private static Collection findArtifactsMatching(IncludeRule rule, Map allArtifacts) { - Collection ret = new ArrayList(); - for (Iterator iter = allArtifacts.keySet().iterator(); iter.hasNext();) { - ArtifactId aid = (ArtifactId) iter.next(); - if (MatcherHelper.matches(rule.getMatcher(), rule.getId(), aid)) { - ret.add(allArtifacts.get(aid)); - } - } - return ret; - } - - private void addDependencyArtifacts(String rootModuleConf, - DependencyArtifactDescriptor[] dependencyArtifacts) { - addObjectsForConf(rootModuleConf, Arrays.asList(dependencyArtifacts), - this.dependencyArtifacts); - } - - private void addDependencyIncludes(String rootModuleConf, IncludeRule[] rules) { - addObjectsForConf(rootModuleConf, Arrays.asList(rules), dependencyIncludes); - } - - private void addObjectsForConf(String rootModuleConf, Collection objectsToAdd, Map map) { - Set set = (Set) map.get(rootModuleConf); - if (set == null) { - set = new HashSet(); - map.put(rootModuleConf, set); - } - set.addAll(objectsToAdd); - } - - public boolean hasProblem() { - return problem != null; - } - - public Exception getProblem() { - return problem; - } - - public String getProblemMessage() { - Exception e = problem; - if (e == null) { - return ""; - } - String errMsg = e instanceof RuntimeException ? e.getMessage() : e.toString(); - if (errMsg == null || errMsg.length() == 0 || "null".equals(errMsg)) { - errMsg = e.getClass().getName() + " at " + e.getStackTrace()[0].toString(); - } - return errMsg; - } - - public boolean isDownloaded() { - return downloaded; - } - - public boolean isSearched() { - return searched; - } - - public boolean isLoaded() { - return md != null; - } - - public boolean isFetched(String conf) { - return fetchedConfigurations.contains(conf); - } - - public IvyNode findNode(ModuleRevisionId mrid) { - return data.getNode(mrid); - } - - boolean isRoot() { - return root == this; - } - - public IvyNode getRoot() { - return root; - } - - public ConflictManager getConflictManager(ModuleId mid) { - if (md == null) { - throw new IllegalStateException( - "impossible to get conflict manager when data has not been loaded"); - } - ConflictManager cm = md.getConflictManager(mid); - return cm == null ? settings.getConflictManager(mid) : cm; - } - - public IvyNode getRealNode() { - IvyNode real = data.getNode(getId()); - return real != null ? real : this; - } - - public ModuleRevisionId getId() { - return id; - } - - public ModuleId getModuleId() { - return id.getModuleId(); - } - - public ModuleDescriptor getDescriptor() { - return md; - } - - public ResolveData getData() { - return data; - } - - public ResolvedModuleRevision getModuleRevision() { - return module; - } - - public long getPublication() { - if (module != null) { - return module.getPublicationDate().getTime(); - } - return 0; - } - - /** - * Returns the last modified timestamp of the module represented by this Node, or 0 if the last - * modified timestamp is currently unkwown (module not loaded) - * - * @return the last modified timestamp of the module represented by this Node - */ - public long getLastModified() { - if (md != null) { - return md.getLastModified(); - } - return 0; - } - - public ModuleRevisionId getResolvedId() { - if (md != null && md.getResolvedModuleRevisionId().getRevision() != null) { - return md.getResolvedModuleRevisionId(); - } else if (module != null) { - return module.getId(); - } else { - return getId(); - } - } - - /** - * Clean data related to one root module configuration only - */ - public void clean() { - confsToFetch.clear(); - } - - // ///////////////////////////////////////////////////////////////////////////// - // CALLERS MANAGEMENT - // ///////////////////////////////////////////////////////////////////////////// - - boolean canExclude(String rootModuleConf) { - Caller[] callers = getCallers(rootModuleConf); - for (int i = 0; i < callers.length; i++) { - if (callers[i].canExclude()) { - return true; - } - } - return false; - } - - private IvyNode getDirectCallerFor(ModuleId from) { - return callers.getDirectCallerFor(from); - } - - public Caller[] getCallers(String rootModuleConf) { - return callers.getCallers(rootModuleConf); - } - - public Collection getAllCallersModuleIds() { - return callers.getAllCallersModuleIds(); - } - - public Caller[] getAllCallers() { - return callers.getAllCallers(); - } - - public void addCaller(String rootModuleConf, IvyNode callerNode, String callerConf, - String[] dependencyConfs, DependencyDescriptor dd) { - callers.addCaller(rootModuleConf, callerNode, callerConf, dependencyConfs, dd); - boolean isCircular = callers.getAllCallersModuleIds().contains(getId().getModuleId()); - if (isCircular) { - IvyContext.getContext().getCircularDependencyStrategy().handleCircularDependency( - toMrids(findPath(getId().getModuleId()), this)); - } - } - - public boolean doesCallersExclude(String rootModuleConf, Artifact artifact, Stack callersStack) { - return callers.doesCallersExclude(rootModuleConf, artifact, callersStack); - } - - private ModuleRevisionId[] toMrids(Collection path, IvyNode depNode) { - ModuleRevisionId[] ret = new ModuleRevisionId[path.size() + 1]; - int i = 0; - for (Iterator iter = path.iterator(); iter.hasNext(); i++) { - IvyNode node = (IvyNode) iter.next(); - ret[i] = node.getId(); - } - ret[ret.length - 1] = depNode.getId(); - return ret; - } - - // ///////////////////////////////////////////////////////////////////////////// - // EVICTION MANAGEMENT - // ///////////////////////////////////////////////////////////////////////////// - - public Collection getResolvedNodes(ModuleId moduleId, String rootModuleConf) { - return eviction.getResolvedNodes(moduleId, rootModuleConf); - } - - public Collection getResolvedRevisions(ModuleId moduleId, String rootModuleConf) { - return eviction.getResolvedRevisions(moduleId, rootModuleConf); - } - - public void markEvicted(EvictionData evictionData) { - eviction.markEvicted(evictionData); - if (!rootModuleConfs.keySet().contains(evictionData.getRootModuleConf())) { - rootModuleConfs.put(evictionData.getRootModuleConf(), null); - } - - // bug 105: update selected data with evicted one - if (evictionData.getSelected() != null) { - for (Iterator iter = evictionData.getSelected().iterator(); iter.hasNext();) { - IvyNode selected = (IvyNode) iter.next(); - selected.updateDataFrom(this, evictionData.getRootModuleConf()); - } - } - } - - public Collection getAllEvictingConflictManagers() { - return eviction.getAllEvictingConflictManagers(); - } - - public Collection getAllEvictingNodes() { - return eviction.getAllEvictingNodes(); - } - - public String[] getEvictedConfs() { - return eviction.getEvictedConfs(); - } - - public EvictionData getEvictedData(String rootModuleConf) { - return eviction.getEvictedData(rootModuleConf); - } - - public Collection getEvictedNodes(ModuleId mid, String rootModuleConf) { - return eviction.getEvictedNodes(mid, rootModuleConf); - } - - public Collection getEvictedRevisions(ModuleId mid, String rootModuleConf) { - return eviction.getEvictedRevisions(mid, rootModuleConf); - } - - public EvictionData getEvictionDataInRoot(String rootModuleConf, IvyNode ancestor) { - return eviction.getEvictionDataInRoot(rootModuleConf, ancestor); - } - - public boolean isCompletelyEvicted() { - return eviction.isCompletelyEvicted(); - } - - public boolean isEvicted(String rootModuleConf) { - return eviction.isEvicted(rootModuleConf); - } - - public void markEvicted(String rootModuleConf, IvyNode node, ConflictManager conflictManager, - Collection resolved) { - eviction.markEvicted(rootModuleConf, node, conflictManager, resolved); - } - - public void setEvictedNodes(ModuleId moduleId, String rootModuleConf, Collection evicted) { - eviction.setEvictedNodes(moduleId, rootModuleConf, evicted); - } - - public void setResolvedNodes(ModuleId moduleId, String rootModuleConf, Collection resolved) { - eviction.setResolvedNodes(moduleId, rootModuleConf, resolved); - } - - public String toString() { - return getResolvedId().toString(); - } - - public boolean equals(Object obj) { - if (!(obj instanceof IvyNode)) { - return false; - } - IvyNode node = (IvyNode) obj; - return node.getId().equals(getId()); - } - - public int compareTo(Object obj) { - IvyNode that = (IvyNode) obj; - return this.getModuleId().compareTo(that.getModuleId()); - } - - public int hashCode() { - return getId().hashCode(); - } - - /** - * Returns a collection of Nodes in conflict for which conflict has been detected but conflict - * resolution hasn't been done yet - * - * @param rootModuleConf - * @param mid - * the module id for which pending conflicts should be found - * @return a Collection of IvyNode in pending conflict - */ - public Collection getPendingConflicts(String rootModuleConf, ModuleId mid) { - return eviction.getPendingConflicts(rootModuleConf, mid); - } - - public void setPendingConflicts(ModuleId moduleId, String rootModuleConf, Collection conflicts) { - eviction.setPendingConflicts(moduleId, rootModuleConf, conflicts); - } -} +/* + * 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.core.resolve; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Stack; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.event.resolve.EndResolveDependencyEvent; +import org.apache.ivy.core.event.resolve.StartResolveDependencyEvent; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.IncludeRule; +import org.apache.ivy.core.module.descriptor.MDArtifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.IvyNodeCallers.Caller; +import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.matcher.MatcherHelper; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.filter.Filter; +import org.apache.ivy.util.filter.FilterHelper; + +public class IvyNode implements Comparable { + private static final Pattern FALLBACK_CONF_PATTERN = Pattern.compile("(.+)\\((.*)\\)"); + + private static final class NodeConf { + private IvyNode node; + + private String conf; + + public NodeConf(IvyNode node, String conf) { + if (node == null) { + throw new NullPointerException("node must not null"); + } + if (conf == null) { + throw new NullPointerException("conf must not null"); + } + this.node = node; + this.conf = conf; + } + + public final String getConf() { + return conf; + } + + public final IvyNode getNode() { + return node; + } + + public boolean equals(Object obj) { + if (!(obj instanceof NodeConf)) { + return false; + } + return getNode().equals(((NodeConf) obj).getNode()) + && getConf().equals(((NodeConf) obj).getConf()); + } + + public int hashCode() { + int hash = 33; + hash += getNode().hashCode() * 17; + hash += getConf().hashCode() * 17; + return hash; + } + } + + // //////// CONTEXT + private ResolveData data; + + private IvySettings settings; + + // //////// DELEGATES + private IvyNodeCallers callers; + + private IvyNodeEviction eviction; + + // //////// MAIN DATA + + private IvyNode root; + + // id as requested, i.e. may be with latest rev + private ModuleRevisionId id; + + // set only when node has been built or updated from a DependencyDescriptor + // Map(IvyNode parent -> DependencyDescriptor) + private Map dds = new HashMap(); + + // Set when data has been loaded only, or when constructed from a module descriptor + private ModuleDescriptor md; + + private ResolvedModuleRevision module; + + // //////// LOADING METADATA + private Exception problem = null; + + private boolean downloaded = false; + + private boolean searched = false; + + private Collection confsToFetch = new HashSet(); + + private Collection fetchedConfigurations = new HashSet(); + + private Collection loadedRootModuleConfs = new HashSet(); + + // //////// USAGE DATA + + // Map (String rootConfName -> Set(String confName)) + // used to know which configurations of the dependency are required + // for each root module configuration + private Map rootModuleConfs = new HashMap(); + + // Map (NodeConf in -> Set(String conf)) + private Map requiredConfs = new HashMap(); + + // Map (String rootModuleConf -> Set(DependencyArtifactDescriptor)) + private Map dependencyArtifacts = new HashMap(); + + // Map (String rootModuleConf -> Set(IncludeRule)) + private Map dependencyIncludes = new HashMap(); + + public IvyNode(ResolveData data, IvyNode parent, DependencyDescriptor dd) { + id = dd.getDependencyRevisionId(); + dds.put(parent, dd); + root = parent.getRoot(); + init(data); + } + + public IvyNode(ResolveData data, ModuleDescriptor md) { + id = md.getModuleRevisionId(); + this.md = md; + root = this; + init(data); + } + + private void init(ResolveData data) { + this.data = data; + settings = data.getSettings(); + eviction = new IvyNodeEviction(this); + callers = new IvyNodeCallers(this); + } + + /** + * After the call node may be discarded. To avoid using discarded node, make sure to get the + * real node after the call IvyNode node = ... node.loadData(); node = node.getRealNode(); ... + */ + public boolean loadData(String rootModuleConf, IvyNode parent, String parentConf, String conf, + boolean shouldBePublic) { + boolean loaded = false; + if (!isEvicted(rootModuleConf) + && (hasConfigurationsToLoad() || !isRootModuleConfLoaded(rootModuleConf)) + && !hasProblem()) { + markRootModuleConfLoaded(rootModuleConf); + if (md == null) { + DependencyResolver resolver = data.getSettings().getResolver(getModuleId()); + if (resolver == null) { + Message.error("no resolver found for " + getModuleId() + + ": check your configuration"); + problem = new RuntimeException("no resolver found for " + getModuleId() + + ": check your configuration"); + data.getReport().addDependency(this); + return false; + } + try { + Message.debug("\tusing " + resolver + " to resolve " + getId()); + DependencyDescriptor dependencyDescriptor = getDependencyDescriptor(parent); + data.getEventManager().fireIvyEvent( + new StartResolveDependencyEvent(resolver, dependencyDescriptor)); + module = resolver.getDependency(dependencyDescriptor, data); + data.getEventManager().fireIvyEvent( + new EndResolveDependencyEvent(resolver, dependencyDescriptor, module)); + if (module != null) { + data.getCacheManager().saveResolver(module.getDescriptor(), + module.getResolver().getName()); + data.getCacheManager().saveArtResolver(module.getDescriptor(), + module.getArtifactResolver().getName()); + if (settings.logModuleWhenFound()) { + Message.info("\tfound " + module.getId() + " in " + + module.getResolver().getName()); + } else { + Message.verbose("\tfound " + module.getId() + " in " + + module.getResolver().getName()); + } + + if (data.getSettings().getVersionMatcher().isDynamic(getId())) { + // IVY-56: check if revision has actually been resolved + if (data.getSettings().getVersionMatcher().isDynamic(module.getId())) { + Message + .error("impossible to resolve dynamic revision for " + + getId() + + ": check your configuration and make sure revision is part of your pattern"); + problem = new RuntimeException( + "impossible to resolve dynamic revision"); + data.getReport().addDependency(this); + return false; + } + IvyNode resolved = data.getNode(module.getId()); + if (resolved != null) { + // exact revision has already been resolved + // => update it and discard this node + md = module.getDescriptor(); // needed for handleConfiguration + if (!handleConfiguration(loaded, rootModuleConf, parent, + parentConf, conf, shouldBePublic)) { + return false; + } + + if (resolved.md == null) { + resolved.md = md; + } + if (resolved.module == null) { + resolved.module = module; + } + resolved.downloaded |= module.isDownloaded(); + resolved.searched |= module.isSearched(); + resolved.dds.putAll(dds); + resolved.updateDataFrom(this, rootModuleConf); + resolved.loadData(rootModuleConf, parent, parentConf, conf, + shouldBePublic); + DependencyDescriptor dd = dependencyDescriptor; + if (dd != null) { + resolved.addDependencyArtifacts(rootModuleConf, dd + .getDependencyArtifacts(parentConf)); + resolved.addDependencyIncludes(rootModuleConf, dd + .getIncludeRules(parentConf)); + } + data.replaceNode(getId(), resolved, rootModuleConf); // this + // actually + // discards + // the node + + if (settings.logResolvedRevision()) { + Message.info("\t[" + module.getId().getRevision() + "] " + + getId()); + } else { + Message.verbose("\t[" + module.getId().getRevision() + "] " + + getId()); + } + + return true; + } + } + downloaded = module.isDownloaded(); + searched = module.isSearched(); + } else { + Message.warn("\tmodule not found: " + getId()); + resolver.reportFailure(); + problem = new RuntimeException("not found"); + } + } catch (Exception e) { + problem = e; + } + + // still not resolved, report error + if (module == null) { + data.getReport().addDependency(this); + return false; + } else { + loaded = true; + if (settings.getVersionMatcher().isDynamic(getId())) { + if (settings.logResolvedRevision()) { + Message.info("\t[" + module.getId().getRevision() + "] " + getId()); + } else { + Message.verbose("\t[" + module.getId().getRevision() + "] " + getId()); + } + } + md = module.getDescriptor(); + confsToFetch.remove("*"); + updateConfsToFetch(Arrays.asList(resolveSpecialConfigurations( + getRequiredConfigurations(parent, parentConf), this))); + } + } else { + loaded = true; + } + } + if (hasProblem()) { + data.getReport().addDependency(this); + return handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, + shouldBePublic) + && loaded; + } + if (!handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, shouldBePublic)) { + return false; + } + DependencyDescriptor dd = getDependencyDescriptor(parent); + if (dd != null) { + addDependencyArtifacts(rootModuleConf, dd.getDependencyArtifacts(parentConf)); + addDependencyIncludes(rootModuleConf, dd.getIncludeRules(parentConf)); + } + return loaded; + + } + + public Collection getDependencies(String rootModuleConf, String[] confs) { + if (md == null) { + throw new IllegalStateException( + "impossible to get dependencies when data has not been loaded"); + } + if (Arrays.asList(confs).contains("*")) { + confs = md.getConfigurationsNames(); + } + Collection deps = new HashSet(); + for (int i = 0; i < confs.length; i++) { + deps.addAll(getDependencies(rootModuleConf, confs[i], confs[i])); + } + return deps; + } + + public Collection getDependencies(String rootModuleConf, String conf, String requestedConf) { + if (md == null) { + throw new IllegalStateException( + "impossible to get dependencies when data has not been loaded"); + } + DependencyDescriptor[] dds = md.getDependencies(); + Collection dependencies = new LinkedHashSet(); // it's important to respect dependencies + // order + for (int i = 0; i < dds.length; i++) { + DependencyDescriptor dd = dds[i]; + String[] dependencyConfigurations = dd.getDependencyConfigurations(conf, requestedConf); + if (dependencyConfigurations.length == 0) { + // no configuration of the dependency is required for current confs : + // it is exactly the same as if there was no dependency at all on it + continue; + } + if (isDependencyModuleExcluded(rootModuleConf, dd.getDependencyRevisionId(), conf)) { + // the whole module is excluded, it is considered as not being part of dependencies + // at all + Message.verbose("excluding " + dd.getDependencyRevisionId() + " in " + conf); + continue; + } + IvyNode depNode = data.getNode(dd.getDependencyRevisionId()); + if (depNode == null) { + depNode = new IvyNode(data, this, dd); + } else { + depNode.addDependencyDescriptor(this, dd); + if (depNode.hasProblem()) { + // dependency already tried to be resolved, but unsuccessfully + // nothing special to do + } + + } + Collection confs = Arrays.asList(resolveSpecialConfigurations(dependencyConfigurations, + depNode)); + depNode.updateConfsToFetch(confs); + depNode.setRequiredConfs(this, conf, confs); + + depNode.addCaller(rootModuleConf, this, conf, dependencyConfigurations, dd); + dependencies.add(depNode); + } + return dependencies; + } + + private void addDependencyDescriptor(IvyNode parent, DependencyDescriptor dd) { + dds.put(parent, dd); + } + + public DependencyDescriptor getDependencyDescriptor(IvyNode parent) { + return (DependencyDescriptor) dds.get(parent); + } + + private boolean isDependencyModuleExcluded(String rootModuleConf, + ModuleRevisionId dependencyRevisionId, String conf) { + return callers.doesCallersExclude(rootModuleConf, DefaultArtifact.newIvyArtifact( + dependencyRevisionId, null)); + } + + public boolean hasConfigurationsToLoad() { + return !confsToFetch.isEmpty(); + } + + private boolean markRootModuleConfLoaded(String rootModuleConf) { + return loadedRootModuleConfs.add(rootModuleConf); + } + + private boolean isRootModuleConfLoaded(String rootModuleConf) { + return loadedRootModuleConfs.contains(rootModuleConf); + } + + private boolean handleConfiguration(boolean loaded, String rootModuleConf, IvyNode parent, + String parentConf, String conf, boolean shouldBePublic) { + if (md != null) { + String[] confs = getRealConfs(conf); + for (int i = 0; i < confs.length; i++) { + Configuration c = md.getConfiguration(confs[i]); + if (c == null) { + confsToFetch.remove(conf); + if (!conf.equals(confs[i])) { + problem = new RuntimeException("configuration(s) not found in " + this + + ": " + conf + ". Missing configuration: " + confs[i] + + ". It was required from " + parent + " " + parentConf); + } else { + problem = new RuntimeException("configuration(s) not found in " + this + + ": " + confs[i] + ". It was required from " + parent + " " + + parentConf); + } + data.getReport().addDependency(this); + return false; + } else if (shouldBePublic && !isRoot() + && c.getVisibility() != Configuration.Visibility.PUBLIC) { + confsToFetch.remove(conf); + problem = new RuntimeException("configuration not public in " + this + ": " + c + + ". It was required from " + parent + " " + parentConf); + data.getReport().addDependency(this); + return false; + } + if (loaded) { + fetchedConfigurations.add(conf); + confsToFetch.removeAll(Arrays.asList(confs)); + confsToFetch.remove(conf); + } + addRootModuleConfigurations(rootModuleConf, confs); + } + } + return true; + } + + private String getDefaultConf(String conf) { + Matcher m = FALLBACK_CONF_PATTERN.matcher(conf); + if (m.matches()) { + return m.group(2); + } else { + return conf; + } + } + + private String getMainConf(String conf) { + Matcher m = FALLBACK_CONF_PATTERN.matcher(conf); + if (m.matches()) { + return m.group(1); + } else { + return null; + } + } + + public void updateConfsToFetch(Collection confs) { + confsToFetch.addAll(confs); + confsToFetch.removeAll(fetchedConfigurations); + } + + /** + * resolve the '*' special configurations if necessary and possible + */ + private String[] resolveSpecialConfigurations(String[] dependencyConfigurations, IvyNode node) { + if (dependencyConfigurations.length == 1 && dependencyConfigurations[0].startsWith("*") + && node != null && node.isLoaded()) { + String conf = dependencyConfigurations[0]; + if ("*".equals(conf)) { + return node.getDescriptor().getPublicConfigurationsNames(); + } + // there are exclusions in the configuration + List exclusions = Arrays.asList(conf.substring(2).split("\\!")); + + List ret = new ArrayList(Arrays.asList(node.getDescriptor() + .getPublicConfigurationsNames())); + ret.removeAll(exclusions); + + return (String[]) ret.toArray(new String[ret.size()]); + } + return dependencyConfigurations; + } + + /** + * returns the required configurations from the given node + * + * @param in + * @return + */ + public String[] getRequiredConfigurations(IvyNode in, String inConf) { + Collection req = (Collection) requiredConfs.get(new NodeConf(in, inConf)); + return req == null ? new String[0] : (String[]) req.toArray(new String[req.size()]); + } + + /** + * returns all the current required configurations of the node + * + * @return + */ + public String[] getRequiredConfigurations() { + Collection required = new ArrayList(confsToFetch.size() + fetchedConfigurations.size()); + required.addAll(fetchedConfigurations); + required.addAll(confsToFetch); + return (String[]) required.toArray(new String[required.size()]); + } + + private void setRequiredConfs(IvyNode parent, String parentConf, Collection confs) { + requiredConfs.put(new NodeConf(parent, parentConf), new HashSet(confs)); + } + + public Configuration getConfiguration(String conf) { + if (md == null) { + throw new IllegalStateException( + "impossible to get configuration when data has not been loaded"); + } + String defaultConf = getDefaultConf(conf); + conf = getMainConf(conf); + Configuration configuration = md.getConfiguration(conf); + if (configuration == null) { + configuration = md.getConfiguration(defaultConf); + } + return configuration; + } + + /** + * Returns the configurations of the dependency required in a given root module configuration. + * + * @param rootModuleConf + * @return + */ + public String[] getConfigurations(String rootModuleConf) { + Set depConfs = (Set) rootModuleConfs.get(rootModuleConf); + if (depConfs == null) { + return new String[0]; + } + return (String[]) depConfs.toArray(new String[depConfs.size()]); + } + + public void discardConf(String rootModuleConf, String conf) { + Set depConfs = (Set) rootModuleConfs.get(rootModuleConf); + if (depConfs == null) { + depConfs = new HashSet(); + rootModuleConfs.put(rootModuleConf, depConfs); + } + if (md != null) { + // remove all given dependency configurations to the set + extended ones + Configuration c = md.getConfiguration(conf); + if (conf != null) { + String[] exts = c.getExtends(); + for (int i = 0; i < exts.length; i++) { + discardConf(rootModuleConf, exts[i]); // recursive remove of extended + // configurations + } + depConfs.remove(c.getName()); + } else { + Message.warn("unknown configuration in " + getId() + ": " + conf); + } + } else { + depConfs.remove(conf); + } + } + + private void addRootModuleConfigurations(String rootModuleConf, String[] dependencyConfs) { + Set depConfs = (Set) rootModuleConfs.get(rootModuleConf); + if (depConfs == null) { + depConfs = new HashSet(); + rootModuleConfs.put(rootModuleConf, depConfs); + } + if (md != null) { + // add all given dependency configurations to the set + extended ones + for (int i = 0; i < dependencyConfs.length; i++) { + Configuration conf = md.getConfiguration(dependencyConfs[i]); + if (conf != null) { + String[] exts = conf.getExtends(); + addRootModuleConfigurations(rootModuleConf, exts); // recursive add of extended + // configurations + depConfs.add(conf.getName()); + } else { + Message.warn("unknown configuration in " + getId() + ": " + dependencyConfs[i]); + } + } + } else { + for (int i = 0; i < dependencyConfs.length; i++) { + depConfs.add(dependencyConfs[i]); + } + } + } + + /** + * Returns the root module configurations in which this dependency is required + * + * @return + */ + public String[] getRootModuleConfigurations() { + return (String[]) rootModuleConfs.keySet().toArray(new String[rootModuleConfs.size()]); + } + + public String[] getConfsToFetch() { + return (String[]) confsToFetch.toArray(new String[confsToFetch.size()]); + } + + public String[] getRealConfs(String conf) { + if (md == null) { + return new String[] {conf}; + } + String defaultConf = getDefaultConf(conf); + conf = getMainConf(conf); + if (md.getConfiguration(conf) == null) { + if ("".equals(defaultConf)) { + return new String[0]; + } + conf = defaultConf; + } + if (conf.startsWith("*")) { + return resolveSpecialConfigurations(new String[] {conf}, this); + } else if (conf.indexOf(',') != -1) { + String[] confs = conf.split(","); + for (int i = 0; i < confs.length; i++) { + confs[i] = confs[i].trim(); + } + } + return new String[] {conf}; + + } + + /** + * Finds and returns a path in callers from the given module id to the current node + * + * @param from + * the module id to start the path from + * @return a collection representing the path, starting with the from node, followed by the list + * of nodes being one path to the current node, excluded + */ + private Collection findPath(ModuleId from) { + return findPath(from, this, new LinkedList()); + } + + private Collection findPath(ModuleId from, IvyNode node, List path) { + IvyNode parent = (IvyNode) node.getDirectCallerFor(from); + if (parent == null) { + throw new IllegalArgumentException("no path from " + from + " to " + getId() + " found"); + } + if (path.contains(parent)) { + path.add(0, parent); + Message + .verbose("circular dependency found while looking for the path for another one: was looking for " + + from + " as a caller of " + path.get(path.size() - 1)); + return path; + } + path.add(0, parent); + if (parent.getId().getModuleId().equals(from)) { + return path; + } + return findPath(from, parent, path); + } + + private void updateDataFrom(IvyNode node, String rootModuleConf) { + // update callers + callers.updateFrom(node.callers, rootModuleConf); + + // update requiredConfs + updateMapOfSet(node.requiredConfs, requiredConfs); + + // update rootModuleConfs + updateMapOfSetForKey(node.rootModuleConfs, rootModuleConfs, rootModuleConf); + + // update dependencyArtifactsIncludes + updateMapOfSetForKey(node.dependencyArtifacts, dependencyArtifacts, rootModuleConf); + + // update confsToFetch + updateConfsToFetch(node.fetchedConfigurations); + updateConfsToFetch(node.confsToFetch); + } + + private void updateMapOfSet(Map from, Map to) { + for (Iterator iter = from.keySet().iterator(); iter.hasNext();) { + Object key = iter.next(); + updateMapOfSetForKey(from, to, key); + } + } + + private void updateMapOfSetForKey(Map from, Map to, Object key) { + Set set = (Set) from.get(key); + if (set != null) { + Set toupdate = (Set) to.get(key); + if (toupdate != null) { + toupdate.addAll(set); + } else { + to.put(key, new HashSet(set)); + } + } + } + + /** + * Returns all the artifacts of this dependency required in all the root module configurations + * + * @return + */ + public Artifact[] getAllArtifacts() { + Set ret = new HashSet(); + for (Iterator it = rootModuleConfs.keySet().iterator(); it.hasNext();) { + String rootModuleConf = (String) it.next(); + ret.addAll(Arrays.asList(getArtifacts(rootModuleConf))); + } + return (Artifact[]) ret.toArray(new Artifact[ret.size()]); + } + + /** + * Returns all the artifacts of this dependency required in the root module configurations in + * which the node is not evicted + * + * @param artifactFilter + * @return + */ + public Artifact[] getSelectedArtifacts(Filter artifactFilter) { + Collection ret = new HashSet(); + for (Iterator it = rootModuleConfs.keySet().iterator(); it.hasNext();) { + String rootModuleConf = (String) it.next(); + if (!isEvicted(rootModuleConf)) { + ret.addAll(Arrays.asList(getArtifacts(rootModuleConf))); + } + } + ret = FilterHelper.filter(ret, artifactFilter); + return (Artifact[]) ret.toArray(new Artifact[ret.size()]); + } + + /** + * Returns the artifacts of this dependency required in the configurations themselves required + * in the given root module configuration + * + * @param rootModuleConf + * @return + */ + public Artifact[] getArtifacts(String rootModuleConf) { + // first we look for the dependency configurations required + // in the given root module configuration + Set confs = (Set) rootModuleConfs.get(rootModuleConf); + if (confs == null) { + // no configuration required => no artifact required + return new Artifact[0]; + } + + Set artifacts = new HashSet(); // the set we fill before returning + + // we check if we have dependencyArtifacts includes description for this rootModuleConf + Set dependencyArtifacts = (Set) this.dependencyArtifacts.get(rootModuleConf); + + if (md.isDefault() && dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) { + // the descriptor is a default one: it has been generated from nothing + // moreover, we have dependency artifacts description + // these descritions are thus used as if they were declared in the module + // descriptor. If one is not really present, the error will be raised + // at download time + for (Iterator it = dependencyArtifacts.iterator(); it.hasNext();) { + DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor) it.next(); + artifacts.add(new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), dad + .getUrl(), dad.getExtraAttributes())); + } + } else { + Set includes = (Set) dependencyIncludes.get(rootModuleConf); + + if ((dependencyArtifacts == null || dependencyArtifacts.isEmpty()) + && (includes == null || includes.isEmpty())) { + // no artifacts / includes: we get all artifacts as defined by the descriptor + for (Iterator iter = confs.iterator(); iter.hasNext();) { + String conf = (String) iter.next(); + artifacts.addAll(Arrays.asList(md.getArtifacts(conf))); + } + } else { + // we have to get only artifacts listed as "includes" + + // first we get all artifacts as defined by the module descriptor + // and classify them by artifact id + Map allArtifacts = new HashMap(); + for (Iterator iter = confs.iterator(); iter.hasNext();) { + String conf = (String) iter.next(); + Artifact[] arts = md.getArtifacts(conf); + for (int i = 0; i < arts.length; i++) { + allArtifacts.put(arts[i].getId().getArtifactId(), arts[i]); + } + } + + // now we add caller defined ones + for (Iterator it = dependencyArtifacts.iterator(); it.hasNext();) { + DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor) it.next(); + artifacts.add(new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), + dad.getUrl(), dad.getExtraAttributes())); + } + + // and now we filter according to include rules + for (Iterator it = includes.iterator(); it.hasNext();) { + IncludeRule dad = (IncludeRule) it.next(); + Collection arts = findArtifactsMatching(dad, allArtifacts); + if (arts.isEmpty()) { + Message.error("a required artifact is not listed by module descriptor: " + + dad.getId()); + // we remove it from required list to prevent message to be displayed more + // than once + it.remove(); + } else { + Message.debug(this + " in " + rootModuleConf + ": including " + arts); + artifacts.addAll(arts); + } + } + } + } + + // now excludes artifacts that aren't accepted by any caller + for (Iterator iter = artifacts.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + boolean excluded = callers.doesCallersExclude(rootModuleConf, artifact); + if (excluded) { + Message.debug(this + " in " + rootModuleConf + ": excluding " + artifact); + iter.remove(); + } + } + return (Artifact[]) artifacts.toArray(new Artifact[artifacts.size()]); + } + + private static Collection findArtifactsMatching(IncludeRule rule, Map allArtifacts) { + Collection ret = new ArrayList(); + for (Iterator iter = allArtifacts.keySet().iterator(); iter.hasNext();) { + ArtifactId aid = (ArtifactId) iter.next(); + if (MatcherHelper.matches(rule.getMatcher(), rule.getId(), aid)) { + ret.add(allArtifacts.get(aid)); + } + } + return ret; + } + + private void addDependencyArtifacts(String rootModuleConf, + DependencyArtifactDescriptor[] dependencyArtifacts) { + addObjectsForConf(rootModuleConf, Arrays.asList(dependencyArtifacts), + this.dependencyArtifacts); + } + + private void addDependencyIncludes(String rootModuleConf, IncludeRule[] rules) { + addObjectsForConf(rootModuleConf, Arrays.asList(rules), dependencyIncludes); + } + + private void addObjectsForConf(String rootModuleConf, Collection objectsToAdd, Map map) { + Set set = (Set) map.get(rootModuleConf); + if (set == null) { + set = new HashSet(); + map.put(rootModuleConf, set); + } + set.addAll(objectsToAdd); + } + + public boolean hasProblem() { + return problem != null; + } + + public Exception getProblem() { + return problem; + } + + public String getProblemMessage() { + Exception e = problem; + if (e == null) { + return ""; + } + String errMsg = e instanceof RuntimeException ? e.getMessage() : e.toString(); + if (errMsg == null || errMsg.length() == 0 || "null".equals(errMsg)) { + errMsg = e.getClass().getName() + " at " + e.getStackTrace()[0].toString(); + } + return errMsg; + } + + public boolean isDownloaded() { + return downloaded; + } + + public boolean isSearched() { + return searched; + } + + public boolean isLoaded() { + return md != null; + } + + public boolean isFetched(String conf) { + return fetchedConfigurations.contains(conf); + } + + public IvyNode findNode(ModuleRevisionId mrid) { + return data.getNode(mrid); + } + + boolean isRoot() { + return root == this; + } + + public IvyNode getRoot() { + return root; + } + + public ConflictManager getConflictManager(ModuleId mid) { + if (md == null) { + throw new IllegalStateException( + "impossible to get conflict manager when data has not been loaded"); + } + ConflictManager cm = md.getConflictManager(mid); + return cm == null ? settings.getConflictManager(mid) : cm; + } + + public IvyNode getRealNode() { + IvyNode real = data.getNode(getId()); + return real != null ? real : this; + } + + public ModuleRevisionId getId() { + return id; + } + + public ModuleId getModuleId() { + return id.getModuleId(); + } + + public ModuleDescriptor getDescriptor() { + return md; + } + + public ResolveData getData() { + return data; + } + + public ResolvedModuleRevision getModuleRevision() { + return module; + } + + public long getPublication() { + if (module != null) { + return module.getPublicationDate().getTime(); + } + return 0; + } + + /** + * Returns the last modified timestamp of the module represented by this Node, or 0 if the last + * modified timestamp is currently unkwown (module not loaded) + * + * @return the last modified timestamp of the module represented by this Node + */ + public long getLastModified() { + if (md != null) { + return md.getLastModified(); + } + return 0; + } + + public ModuleRevisionId getResolvedId() { + if (md != null && md.getResolvedModuleRevisionId().getRevision() != null) { + return md.getResolvedModuleRevisionId(); + } else if (module != null) { + return module.getId(); + } else { + return getId(); + } + } + + /** + * Clean data related to one root module configuration only + */ + public void clean() { + confsToFetch.clear(); + } + + // ///////////////////////////////////////////////////////////////////////////// + // CALLERS MANAGEMENT + // ///////////////////////////////////////////////////////////////////////////// + + boolean canExclude(String rootModuleConf) { + Caller[] callers = getCallers(rootModuleConf); + for (int i = 0; i < callers.length; i++) { + if (callers[i].canExclude()) { + return true; + } + } + return false; + } + + private IvyNode getDirectCallerFor(ModuleId from) { + return callers.getDirectCallerFor(from); + } + + public Caller[] getCallers(String rootModuleConf) { + return callers.getCallers(rootModuleConf); + } + + public Collection getAllCallersModuleIds() { + return callers.getAllCallersModuleIds(); + } + + public Caller[] getAllCallers() { + return callers.getAllCallers(); + } + + public void addCaller(String rootModuleConf, IvyNode callerNode, String callerConf, + String[] dependencyConfs, DependencyDescriptor dd) { + callers.addCaller(rootModuleConf, callerNode, callerConf, dependencyConfs, dd); + boolean isCircular = callers.getAllCallersModuleIds().contains(getId().getModuleId()); + if (isCircular) { + IvyContext.getContext().getCircularDependencyStrategy().handleCircularDependency( + toMrids(findPath(getId().getModuleId()), this)); + } + } + + public boolean doesCallersExclude(String rootModuleConf, Artifact artifact, Stack callersStack) { + return callers.doesCallersExclude(rootModuleConf, artifact, callersStack); + } + + private ModuleRevisionId[] toMrids(Collection path, IvyNode depNode) { + ModuleRevisionId[] ret = new ModuleRevisionId[path.size() + 1]; + int i = 0; + for (Iterator iter = path.iterator(); iter.hasNext(); i++) { + IvyNode node = (IvyNode) iter.next(); + ret[i] = node.getId(); + } + ret[ret.length - 1] = depNode.getId(); + return ret; + } + + // ///////////////////////////////////////////////////////////////////////////// + // EVICTION MANAGEMENT + // ///////////////////////////////////////////////////////////////////////////// + + public Collection getResolvedNodes(ModuleId moduleId, String rootModuleConf) { + return eviction.getResolvedNodes(moduleId, rootModuleConf); + } + + public Collection getResolvedRevisions(ModuleId moduleId, String rootModuleConf) { + return eviction.getResolvedRevisions(moduleId, rootModuleConf); + } + + public void markEvicted(EvictionData evictionData) { + eviction.markEvicted(evictionData); + if (!rootModuleConfs.keySet().contains(evictionData.getRootModuleConf())) { + rootModuleConfs.put(evictionData.getRootModuleConf(), null); + } + + // bug 105: update selected data with evicted one + if (evictionData.getSelected() != null) { + for (Iterator iter = evictionData.getSelected().iterator(); iter.hasNext();) { + IvyNode selected = (IvyNode) iter.next(); + selected.updateDataFrom(this, evictionData.getRootModuleConf()); + } + } + } + + public Collection getAllEvictingConflictManagers() { + return eviction.getAllEvictingConflictManagers(); + } + + public Collection getAllEvictingNodes() { + return eviction.getAllEvictingNodes(); + } + + public String[] getEvictedConfs() { + return eviction.getEvictedConfs(); + } + + public EvictionData getEvictedData(String rootModuleConf) { + return eviction.getEvictedData(rootModuleConf); + } + + public Collection getEvictedNodes(ModuleId mid, String rootModuleConf) { + return eviction.getEvictedNodes(mid, rootModuleConf); + } + + public Collection getEvictedRevisions(ModuleId mid, String rootModuleConf) { + return eviction.getEvictedRevisions(mid, rootModuleConf); + } + + public EvictionData getEvictionDataInRoot(String rootModuleConf, IvyNode ancestor) { + return eviction.getEvictionDataInRoot(rootModuleConf, ancestor); + } + + public boolean isCompletelyEvicted() { + return eviction.isCompletelyEvicted(); + } + + public boolean isEvicted(String rootModuleConf) { + return eviction.isEvicted(rootModuleConf); + } + + public void markEvicted(String rootModuleConf, IvyNode node, ConflictManager conflictManager, + Collection resolved) { + eviction.markEvicted(rootModuleConf, node, conflictManager, resolved); + } + + public void setEvictedNodes(ModuleId moduleId, String rootModuleConf, Collection evicted) { + eviction.setEvictedNodes(moduleId, rootModuleConf, evicted); + } + + public void setResolvedNodes(ModuleId moduleId, String rootModuleConf, Collection resolved) { + eviction.setResolvedNodes(moduleId, rootModuleConf, resolved); + } + + public String toString() { + return getResolvedId().toString(); + } + + public boolean equals(Object obj) { + if (!(obj instanceof IvyNode)) { + return false; + } + IvyNode node = (IvyNode) obj; + return node.getId().equals(getId()); + } + + public int compareTo(Object obj) { + IvyNode that = (IvyNode) obj; + return this.getModuleId().compareTo(that.getModuleId()); + } + + public int hashCode() { + return getId().hashCode(); + } + + /** + * Returns a collection of Nodes in conflict for which conflict has been detected but conflict + * resolution hasn't been done yet + * + * @param rootModuleConf + * @param mid + * the module id for which pending conflicts should be found + * @return a Collection of IvyNode in pending conflict + */ + public Collection getPendingConflicts(String rootModuleConf, ModuleId mid) { + return eviction.getPendingConflicts(rootModuleConf, mid); + } + + public void setPendingConflicts(ModuleId moduleId, String rootModuleConf, Collection conflicts) { + eviction.setPendingConflicts(moduleId, rootModuleConf, conflicts); + } +} diff --git a/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java b/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java index c7e50475..7e663f16 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java @@ -1,263 +1,263 @@ -/* - * 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.core.resolve; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Stack; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class IvyNodeCallers { - public static class Caller { - private ModuleDescriptor md; - - private ModuleRevisionId mrid; - - private Map confs = new HashMap(); // Map (String callerConf -> String[] dependencyConfs) - - private DependencyDescriptor dd; - - private boolean callerCanExclude; - - public Caller(ModuleDescriptor md, ModuleRevisionId mrid, DependencyDescriptor dd, - boolean callerCanExclude) { - this.md = md; - this.mrid = mrid; - this.dd = dd; - this.callerCanExclude = callerCanExclude; - } - - public void addConfiguration(String callerConf, String[] dependencyConfs) { - String[] prevDepConfs = (String[]) confs.get(callerConf); - if (prevDepConfs != null) { - Set newDepConfs = new HashSet(Arrays.asList(prevDepConfs)); - newDepConfs.addAll(Arrays.asList(dependencyConfs)); - confs.put(callerConf, (String[]) newDepConfs - .toArray(new String[newDepConfs.size()])); - } else { - confs.put(callerConf, dependencyConfs); - } - } - - public String[] getCallerConfigurations() { - return (String[]) confs.keySet().toArray(new String[confs.keySet().size()]); - } - - public ModuleRevisionId getModuleRevisionId() { - return mrid; - } - - public boolean equals(Object obj) { - if (!(obj instanceof Caller)) { - return false; - } - Caller other = (Caller) obj; - return other.confs.equals(confs) && mrid.equals(other.mrid); - } - - public int hashCode() { - int hash = 31; - hash = hash * 13 + confs.hashCode(); - hash = hash * 13 + mrid.hashCode(); - return hash; - } - - public String toString() { - return mrid.toString(); - } - - public ModuleRevisionId getAskedDependencyId() { - return dd.getDependencyRevisionId(); - } - - public ModuleDescriptor getModuleDescriptor() { - return md; - } - - public boolean canExclude() { - return callerCanExclude || md.canExclude() || dd.canExclude(); - } - - public DependencyDescriptor getDependencyDescriptor() { - return dd; - } - } - - // Map (String rootModuleConf -> Map (ModuleRevisionId -> Caller)): key in second map is used to - // easily get a caller by its mrid - private Map callersByRootConf = new HashMap(); - - // this map contains all the module ids calling this one (including transitively) as keys - // the mapped nodes (values) correspond to a direct caller from which the transitive caller - // comes - - private Map allCallers = new HashMap(); // Map (ModuleId -> IvyNode) - - private IvyNode node; - - public IvyNodeCallers(IvyNode node) { - this.node = node; - } - - /** - * @param rootModuleConf - * @param mrid - * @param callerConf - * @param dependencyConfs - * '*' must have been resolved - * @param dd - * the dependency revision id asked by the caller - */ - public void addCaller(String rootModuleConf, IvyNode callerNode, String callerConf, - String[] dependencyConfs, DependencyDescriptor dd) { - ModuleDescriptor md = callerNode.getDescriptor(); - ModuleRevisionId mrid = callerNode.getId(); - if (mrid.getModuleId().equals(node.getId().getModuleId())) { - throw new IllegalArgumentException("a module is not authorized to depend on itself: " - + node.getId()); - } - Map callers = (Map) callersByRootConf.get(rootModuleConf); - if (callers == null) { - callers = new HashMap(); - callersByRootConf.put(rootModuleConf, callers); - } - Caller caller = (Caller) callers.get(mrid); - if (caller == null) { - caller = new Caller(md, mrid, dd, callerNode.canExclude(rootModuleConf)); - callers.put(mrid, caller); - } - caller.addConfiguration(callerConf, dependencyConfs); - - IvyNode parent = callerNode.getRealNode(); - for (Iterator iter = parent.getAllCallersModuleIds().iterator(); iter.hasNext();) { - ModuleId mid = (ModuleId) iter.next(); - allCallers.put(mid, parent); - } - allCallers.put(mrid.getModuleId(), callerNode); - } - - public Caller[] getCallers(String rootModuleConf) { - Map callers = (Map) callersByRootConf.get(rootModuleConf); - if (callers == null) { - return new Caller[0]; - } - return (Caller[]) callers.values().toArray(new Caller[callers.values().size()]); - } - - public Caller[] getAllCallers() { - Set all = new HashSet(); - for (Iterator iter = callersByRootConf.values().iterator(); iter.hasNext();) { - Map callers = (Map) iter.next(); - all.addAll(callers.values()); - } - return (Caller[]) all.toArray(new Caller[all.size()]); - } - - public Collection getAllCallersModuleIds() { - return allCallers.keySet(); - } - - public void updateFrom(IvyNodeCallers callers, String rootModuleConf) { - Map nodecallers = (Map) callers.callersByRootConf.get(rootModuleConf); - if (nodecallers != null) { - Map thiscallers = (Map) callersByRootConf.get(rootModuleConf); - if (thiscallers == null) { - thiscallers = new HashMap(); - callersByRootConf.put(rootModuleConf, thiscallers); - } - for (Iterator iter = nodecallers.values().iterator(); iter.hasNext();) { - Caller caller = (Caller) iter.next(); - if (!thiscallers.containsKey(caller.getModuleRevisionId())) { - thiscallers.put(caller.getModuleRevisionId(), caller); - } - } - } - } - - public IvyNode getDirectCallerFor(ModuleId from) { - return (IvyNode) allCallers.get(from); - } - - /** - * Returns true if ALL callers exclude the given artifact in the given root module conf - * - * @param rootModuleConf - * @param artifact - * @return - */ - boolean doesCallersExclude(String rootModuleConf, Artifact artifact) { - return doesCallersExclude(rootModuleConf, artifact, new Stack()); - } - - boolean doesCallersExclude(String rootModuleConf, Artifact artifact, Stack callersStack) { - if (callersStack.contains(node.getId())) { - return false; - } - callersStack.push(node.getId()); - try { - Caller[] callers = getCallers(rootModuleConf); - if (callers.length == 0) { - return false; - } - for (int i = 0; i < callers.length; i++) { - if (!callers[i].canExclude()) { - return false; - } - ModuleDescriptor md = callers[i].getModuleDescriptor(); - if (!doesExclude(md, rootModuleConf, callers[i].getCallerConfigurations(), - callers[i].getDependencyDescriptor(), artifact, callersStack)) { - return false; - } - } - return true; - } finally { - callersStack.pop(); - } - } - - private boolean doesExclude(ModuleDescriptor md, String rootModuleConf, String[] moduleConfs, - DependencyDescriptor dd, Artifact artifact, Stack callersStack) { - // artifact is excluded if it match any of the exclude pattern for this dependency... - if (dd != null) { - if (dd.doesExclude(moduleConfs, artifact.getId().getArtifactId())) { - return true; - } - } - if (md.doesExclude(moduleConfs, artifact.getId().getArtifactId())) { - return true; - } - // ... or if it is excluded by all its callers - IvyNode c = node.getData().getNode(md.getModuleRevisionId()); - if (c != null) { - return c.doesCallersExclude(rootModuleConf, artifact, callersStack); - } else { - return false; - } - } - -} +/* + * 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.core.resolve; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.Stack; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class IvyNodeCallers { + public static class Caller { + private ModuleDescriptor md; + + private ModuleRevisionId mrid; + + private Map confs = new HashMap(); // Map (String callerConf -> String[] dependencyConfs) + + private DependencyDescriptor dd; + + private boolean callerCanExclude; + + public Caller(ModuleDescriptor md, ModuleRevisionId mrid, DependencyDescriptor dd, + boolean callerCanExclude) { + this.md = md; + this.mrid = mrid; + this.dd = dd; + this.callerCanExclude = callerCanExclude; + } + + public void addConfiguration(String callerConf, String[] dependencyConfs) { + String[] prevDepConfs = (String[]) confs.get(callerConf); + if (prevDepConfs != null) { + Set newDepConfs = new HashSet(Arrays.asList(prevDepConfs)); + newDepConfs.addAll(Arrays.asList(dependencyConfs)); + confs.put(callerConf, (String[]) newDepConfs + .toArray(new String[newDepConfs.size()])); + } else { + confs.put(callerConf, dependencyConfs); + } + } + + public String[] getCallerConfigurations() { + return (String[]) confs.keySet().toArray(new String[confs.keySet().size()]); + } + + public ModuleRevisionId getModuleRevisionId() { + return mrid; + } + + public boolean equals(Object obj) { + if (!(obj instanceof Caller)) { + return false; + } + Caller other = (Caller) obj; + return other.confs.equals(confs) && mrid.equals(other.mrid); + } + + public int hashCode() { + int hash = 31; + hash = hash * 13 + confs.hashCode(); + hash = hash * 13 + mrid.hashCode(); + return hash; + } + + public String toString() { + return mrid.toString(); + } + + public ModuleRevisionId getAskedDependencyId() { + return dd.getDependencyRevisionId(); + } + + public ModuleDescriptor getModuleDescriptor() { + return md; + } + + public boolean canExclude() { + return callerCanExclude || md.canExclude() || dd.canExclude(); + } + + public DependencyDescriptor getDependencyDescriptor() { + return dd; + } + } + + // Map (String rootModuleConf -> Map (ModuleRevisionId -> Caller)): key in second map is used to + // easily get a caller by its mrid + private Map callersByRootConf = new HashMap(); + + // this map contains all the module ids calling this one (including transitively) as keys + // the mapped nodes (values) correspond to a direct caller from which the transitive caller + // comes + + private Map allCallers = new HashMap(); // Map (ModuleId -> IvyNode) + + private IvyNode node; + + public IvyNodeCallers(IvyNode node) { + this.node = node; + } + + /** + * @param rootModuleConf + * @param mrid + * @param callerConf + * @param dependencyConfs + * '*' must have been resolved + * @param dd + * the dependency revision id asked by the caller + */ + public void addCaller(String rootModuleConf, IvyNode callerNode, String callerConf, + String[] dependencyConfs, DependencyDescriptor dd) { + ModuleDescriptor md = callerNode.getDescriptor(); + ModuleRevisionId mrid = callerNode.getId(); + if (mrid.getModuleId().equals(node.getId().getModuleId())) { + throw new IllegalArgumentException("a module is not authorized to depend on itself: " + + node.getId()); + } + Map callers = (Map) callersByRootConf.get(rootModuleConf); + if (callers == null) { + callers = new HashMap(); + callersByRootConf.put(rootModuleConf, callers); + } + Caller caller = (Caller) callers.get(mrid); + if (caller == null) { + caller = new Caller(md, mrid, dd, callerNode.canExclude(rootModuleConf)); + callers.put(mrid, caller); + } + caller.addConfiguration(callerConf, dependencyConfs); + + IvyNode parent = callerNode.getRealNode(); + for (Iterator iter = parent.getAllCallersModuleIds().iterator(); iter.hasNext();) { + ModuleId mid = (ModuleId) iter.next(); + allCallers.put(mid, parent); + } + allCallers.put(mrid.getModuleId(), callerNode); + } + + public Caller[] getCallers(String rootModuleConf) { + Map callers = (Map) callersByRootConf.get(rootModuleConf); + if (callers == null) { + return new Caller[0]; + } + return (Caller[]) callers.values().toArray(new Caller[callers.values().size()]); + } + + public Caller[] getAllCallers() { + Set all = new HashSet(); + for (Iterator iter = callersByRootConf.values().iterator(); iter.hasNext();) { + Map callers = (Map) iter.next(); + all.addAll(callers.values()); + } + return (Caller[]) all.toArray(new Caller[all.size()]); + } + + public Collection getAllCallersModuleIds() { + return allCallers.keySet(); + } + + public void updateFrom(IvyNodeCallers callers, String rootModuleConf) { + Map nodecallers = (Map) callers.callersByRootConf.get(rootModuleConf); + if (nodecallers != null) { + Map thiscallers = (Map) callersByRootConf.get(rootModuleConf); + if (thiscallers == null) { + thiscallers = new HashMap(); + callersByRootConf.put(rootModuleConf, thiscallers); + } + for (Iterator iter = nodecallers.values().iterator(); iter.hasNext();) { + Caller caller = (Caller) iter.next(); + if (!thiscallers.containsKey(caller.getModuleRevisionId())) { + thiscallers.put(caller.getModuleRevisionId(), caller); + } + } + } + } + + public IvyNode getDirectCallerFor(ModuleId from) { + return (IvyNode) allCallers.get(from); + } + + /** + * Returns true if ALL callers exclude the given artifact in the given root module conf + * + * @param rootModuleConf + * @param artifact + * @return + */ + boolean doesCallersExclude(String rootModuleConf, Artifact artifact) { + return doesCallersExclude(rootModuleConf, artifact, new Stack()); + } + + boolean doesCallersExclude(String rootModuleConf, Artifact artifact, Stack callersStack) { + if (callersStack.contains(node.getId())) { + return false; + } + callersStack.push(node.getId()); + try { + Caller[] callers = getCallers(rootModuleConf); + if (callers.length == 0) { + return false; + } + for (int i = 0; i < callers.length; i++) { + if (!callers[i].canExclude()) { + return false; + } + ModuleDescriptor md = callers[i].getModuleDescriptor(); + if (!doesExclude(md, rootModuleConf, callers[i].getCallerConfigurations(), + callers[i].getDependencyDescriptor(), artifact, callersStack)) { + return false; + } + } + return true; + } finally { + callersStack.pop(); + } + } + + private boolean doesExclude(ModuleDescriptor md, String rootModuleConf, String[] moduleConfs, + DependencyDescriptor dd, Artifact artifact, Stack callersStack) { + // artifact is excluded if it match any of the exclude pattern for this dependency... + if (dd != null) { + if (dd.doesExclude(moduleConfs, artifact.getId().getArtifactId())) { + return true; + } + } + if (md.doesExclude(moduleConfs, artifact.getId().getArtifactId())) { + return true; + } + // ... or if it is excluded by all its callers + IvyNode c = node.getData().getNode(md.getModuleRevisionId()); + if (c != null) { + return c.doesCallersExclude(rootModuleConf, artifact, callersStack); + } else { + return false; + } + } + +} diff --git a/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java b/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java index 66010aea..ba9ef379 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java @@ -1,356 +1,356 @@ -/* - * 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.core.resolve; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.plugins.conflict.ConflictManager; - -public class IvyNodeEviction { - public static class EvictionData { - private IvyNode parent; // can be null in case of transitive eviction - - private ConflictManager conflictManager; // can be null in case of transitive eviction - - private Collection selected; // Collection(IvyNode); can be null in case of transitive - - // eviction - - private String rootModuleConf; - - public EvictionData(String rootModuleConf, IvyNode parent, ConflictManager conflictManager, - Collection selected) { - this.rootModuleConf = rootModuleConf; - this.parent = parent; - this.conflictManager = conflictManager; - this.selected = selected; - for (Iterator iter = selected.iterator(); iter.hasNext();) { - Object o = (Object) iter.next(); - if (!(o instanceof IvyNode)) { - throw new IllegalArgumentException( - "selected nodes must be instance of IvyNode. Found: " - + o.getClass().getName()); - } - } - } - - public String toString() { - if (selected != null) { - return selected + " in " + parent + " (" + conflictManager + ") [" + rootModuleConf - + "]"; - } else { - return "transitively [" + rootModuleConf + "]"; - } - } - - public ConflictManager getConflictManager() { - return conflictManager; - } - - public IvyNode getParent() { - return parent; - } - - public Collection getSelected() { - return selected; - } - - public String getRootModuleConf() { - return rootModuleConf; - } - } - - private static final class ModuleIdConf { - private ModuleId moduleId; - - private String conf; - - public ModuleIdConf(ModuleId mid, String conf) { - if (mid == null) { - throw new NullPointerException("mid cannot be null"); - } - if (conf == null) { - throw new NullPointerException("conf cannot be null"); - } - moduleId = mid; - this.conf = conf; - } - - public final String getConf() { - return conf; - } - - public final ModuleId getModuleId() { - return moduleId; - } - - public boolean equals(Object obj) { - if (!(obj instanceof ModuleIdConf)) { - return false; - } - return getModuleId().equals(((ModuleIdConf) obj).getModuleId()) - && getConf().equals(((ModuleIdConf) obj).getConf()); - } - - public int hashCode() { - int hash = 33; - hash += getModuleId().hashCode() * 17; - hash += getConf().hashCode() * 17; - return hash; - } - } - - private IvyNode node; - - private Map selectedDeps = new HashMap(); // Map (ModuleIdConf -> Set(Node)) // map indicating - - // for each dependency which node has been selected - - private Map pendingConflicts = new HashMap(); // Map (ModuleIdConf -> Set(Node)) // map - - // indicating for each dependency which nodes - // are in pending conflict (conflict detected - // but not yet resolved) - - private Map evictedDeps = new HashMap(); // Map (ModuleIdConf -> Set(Node)) // map indicating - - // for each dependency which node has been evicted - - private Map evictedRevs = new HashMap(); // Map (ModuleIdConf -> Set(ModuleRevisionId)) // - - // map indicating for each dependency which revision - // has been evicted - - private Map evicted = new HashMap(); // Map (root module conf -> EvictionData) // indicates - - // if the node is evicted in each root module conf - - public IvyNodeEviction(IvyNode node) { - if (node == null) { - throw new NullPointerException("node must not be null"); - } - this.node = node; - } - - public Collection getResolvedNodes(ModuleId mid, String rootModuleConf) { - Collection resolved = (Collection) selectedDeps.get(new ModuleIdConf(mid, rootModuleConf)); - Set ret = new HashSet(); - if (resolved != null) { - for (Iterator iter = resolved.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - ret.add(node.getRealNode()); - } - } - return ret; - } - - public Collection getResolvedRevisions(ModuleId mid, String rootModuleConf) { - Collection resolved = (Collection) selectedDeps.get(new ModuleIdConf(mid, rootModuleConf)); - if (resolved == null) { - return new HashSet(); - } else { - Collection resolvedRevs = new HashSet(); - for (Iterator iter = resolved.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - resolvedRevs.add(node.getId()); - resolvedRevs.add(node.getResolvedId()); - } - return resolvedRevs; - } - } - - public void setResolvedNodes(ModuleId moduleId, String rootModuleConf, Collection resolved) { - ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); - selectedDeps.put(moduleIdConf, new HashSet(resolved)); - } - - public Collection getEvictedNodes(ModuleId mid, String rootModuleConf) { - Collection resolved = (Collection) evictedDeps.get(new ModuleIdConf(mid, rootModuleConf)); - Set ret = new HashSet(); - if (resolved != null) { - for (Iterator iter = resolved.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - ret.add(node.getRealNode()); - } - } - return ret; - } - - public Collection getEvictedRevisions(ModuleId mid, String rootModuleConf) { - Collection evicted = (Collection) evictedRevs.get(new ModuleIdConf(mid, rootModuleConf)); - if (evicted == null) { - return new HashSet(); - } else { - return new HashSet(evicted); - } - } - - public void setEvictedNodes(ModuleId moduleId, String rootModuleConf, Collection evicted) { - ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); - evictedDeps.put(moduleIdConf, new HashSet(evicted)); - Collection evictedRevs = new HashSet(); - for (Iterator iter = evicted.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - evictedRevs.add(node.getId()); - evictedRevs.add(node.getResolvedId()); - } - this.evictedRevs.put(moduleIdConf, evictedRevs); - } - - public boolean isEvicted(String rootModuleConf) { - cleanEvicted(); - IvyNode root = node.getRoot(); - return root != node - && !root.getResolvedRevisions(node.getId().getModuleId(), rootModuleConf).contains( - node.getResolvedId()) && getEvictedData(rootModuleConf) != null; - } - - public boolean isCompletelyEvicted() { - cleanEvicted(); - if (node.isRoot()) { - return false; - } - String[] rootModuleConfigurations = node.getRootModuleConfigurations(); - for (int i = 0; i < rootModuleConfigurations.length; i++) { - if (!isEvicted(rootModuleConfigurations[i])) { - return false; - } - } - return true; - } - - private void cleanEvicted() { - // check if it was evicted by a node that we are now the real node for - for (Iterator iter = evicted.keySet().iterator(); iter.hasNext();) { - String rootModuleConf = (String) iter.next(); - EvictionData ed = (EvictionData) evicted.get(rootModuleConf); - Collection sel = ed.getSelected(); - if (sel != null) { - for (Iterator iterator = sel.iterator(); iterator.hasNext();) { - IvyNode n = (IvyNode) iterator.next(); - if (n.getRealNode().equals(this)) { - // yes, we are the real node for a selected one ! - // we are no more evicted in this conf ! - iter.remove(); - } - } - } - } - } - - public void markEvicted(String rootModuleConf, IvyNode node, ConflictManager conflictManager, - Collection resolved) { - EvictionData evictionData = new EvictionData(rootModuleConf, node, conflictManager, - resolved); - markEvicted(evictionData); - } - - public void markEvicted(EvictionData evictionData) { - evicted.put(evictionData.getRootModuleConf(), evictionData); - } - - public EvictionData getEvictedData(String rootModuleConf) { - cleanEvicted(); - return (EvictionData) evicted.get(rootModuleConf); - } - - public String[] getEvictedConfs() { - cleanEvicted(); - return (String[]) evicted.keySet().toArray(new String[evicted.keySet().size()]); - } - - /** - * Returns null if this node has only be evicted transitively, or the the colletion of selected - * nodes if it has been evicted by other selected nodes - * - * @return - */ - public Collection getAllEvictingNodes() { - Collection allEvictingNodes = null; - for (Iterator iter = evicted.values().iterator(); iter.hasNext();) { - EvictionData ed = (EvictionData) iter.next(); - Collection selected = ed.getSelected(); - if (selected != null) { - if (allEvictingNodes == null) { - allEvictingNodes = new HashSet(); - } - allEvictingNodes.addAll(selected); - } - } - return allEvictingNodes; - } - - public Collection getAllEvictingConflictManagers() { - Collection ret = new HashSet(); - for (Iterator iter = evicted.values().iterator(); iter.hasNext();) { - EvictionData ed = (EvictionData) iter.next(); - ret.add(ed.getConflictManager()); - } - return ret; - } - - /** - * Returns the eviction data for this node if it has been previously evicted in the root, null - * otherwise (if it hasn't been evicted in root) for the given rootModuleConf. Note that this - * method only works if conflict resolution has already be done in all the ancestors. - * - * @param rootModuleConf - * @param ancestor - * @return - */ - public EvictionData getEvictionDataInRoot(String rootModuleConf, IvyNode ancestor) { - Collection selectedNodes = node.getRoot().getResolvedNodes(node.getModuleId(), - rootModuleConf); - for (Iterator iter = selectedNodes.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (node.getResolvedId().equals(this.node.getResolvedId())) { - // the node is part of the selected ones for the root: no eviction data to return - return null; - } - } - // we didn't find this mrid in the selected ones for the root: it has been previously - // evicted - return new EvictionData(rootModuleConf, ancestor, node.getRoot().getConflictManager( - node.getModuleId()), selectedNodes); - } - - public Collection getPendingConflicts(String rootModuleConf, ModuleId mid) { - Collection resolved = (Collection) pendingConflicts.get(new ModuleIdConf(mid, - rootModuleConf)); - Set ret = new HashSet(); - if (resolved != null) { - for (Iterator iter = resolved.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - ret.add(node.getRealNode()); - } - } - return ret; - } - - public void setPendingConflicts(ModuleId moduleId, String rootModuleConf, Collection conflicts) { - ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); - pendingConflicts.put(moduleIdConf, new HashSet(conflicts)); - } - -} +/* + * 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.core.resolve; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.plugins.conflict.ConflictManager; + +public class IvyNodeEviction { + public static class EvictionData { + private IvyNode parent; // can be null in case of transitive eviction + + private ConflictManager conflictManager; // can be null in case of transitive eviction + + private Collection selected; // Collection(IvyNode); can be null in case of transitive + + // eviction + + private String rootModuleConf; + + public EvictionData(String rootModuleConf, IvyNode parent, ConflictManager conflictManager, + Collection selected) { + this.rootModuleConf = rootModuleConf; + this.parent = parent; + this.conflictManager = conflictManager; + this.selected = selected; + for (Iterator iter = selected.iterator(); iter.hasNext();) { + Object o = (Object) iter.next(); + if (!(o instanceof IvyNode)) { + throw new IllegalArgumentException( + "selected nodes must be instance of IvyNode. Found: " + + o.getClass().getName()); + } + } + } + + public String toString() { + if (selected != null) { + return selected + " in " + parent + " (" + conflictManager + ") [" + rootModuleConf + + "]"; + } else { + return "transitively [" + rootModuleConf + "]"; + } + } + + public ConflictManager getConflictManager() { + return conflictManager; + } + + public IvyNode getParent() { + return parent; + } + + public Collection getSelected() { + return selected; + } + + public String getRootModuleConf() { + return rootModuleConf; + } + } + + private static final class ModuleIdConf { + private ModuleId moduleId; + + private String conf; + + public ModuleIdConf(ModuleId mid, String conf) { + if (mid == null) { + throw new NullPointerException("mid cannot be null"); + } + if (conf == null) { + throw new NullPointerException("conf cannot be null"); + } + moduleId = mid; + this.conf = conf; + } + + public final String getConf() { + return conf; + } + + public final ModuleId getModuleId() { + return moduleId; + } + + public boolean equals(Object obj) { + if (!(obj instanceof ModuleIdConf)) { + return false; + } + return getModuleId().equals(((ModuleIdConf) obj).getModuleId()) + && getConf().equals(((ModuleIdConf) obj).getConf()); + } + + public int hashCode() { + int hash = 33; + hash += getModuleId().hashCode() * 17; + hash += getConf().hashCode() * 17; + return hash; + } + } + + private IvyNode node; + + private Map selectedDeps = new HashMap(); // Map (ModuleIdConf -> Set(Node)) // map indicating + + // for each dependency which node has been selected + + private Map pendingConflicts = new HashMap(); // Map (ModuleIdConf -> Set(Node)) // map + + // indicating for each dependency which nodes + // are in pending conflict (conflict detected + // but not yet resolved) + + private Map evictedDeps = new HashMap(); // Map (ModuleIdConf -> Set(Node)) // map indicating + + // for each dependency which node has been evicted + + private Map evictedRevs = new HashMap(); // Map (ModuleIdConf -> Set(ModuleRevisionId)) // + + // map indicating for each dependency which revision + // has been evicted + + private Map evicted = new HashMap(); // Map (root module conf -> EvictionData) // indicates + + // if the node is evicted in each root module conf + + public IvyNodeEviction(IvyNode node) { + if (node == null) { + throw new NullPointerException("node must not be null"); + } + this.node = node; + } + + public Collection getResolvedNodes(ModuleId mid, String rootModuleConf) { + Collection resolved = (Collection) selectedDeps.get(new ModuleIdConf(mid, rootModuleConf)); + Set ret = new HashSet(); + if (resolved != null) { + for (Iterator iter = resolved.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + ret.add(node.getRealNode()); + } + } + return ret; + } + + public Collection getResolvedRevisions(ModuleId mid, String rootModuleConf) { + Collection resolved = (Collection) selectedDeps.get(new ModuleIdConf(mid, rootModuleConf)); + if (resolved == null) { + return new HashSet(); + } else { + Collection resolvedRevs = new HashSet(); + for (Iterator iter = resolved.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + resolvedRevs.add(node.getId()); + resolvedRevs.add(node.getResolvedId()); + } + return resolvedRevs; + } + } + + public void setResolvedNodes(ModuleId moduleId, String rootModuleConf, Collection resolved) { + ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); + selectedDeps.put(moduleIdConf, new HashSet(resolved)); + } + + public Collection getEvictedNodes(ModuleId mid, String rootModuleConf) { + Collection resolved = (Collection) evictedDeps.get(new ModuleIdConf(mid, rootModuleConf)); + Set ret = new HashSet(); + if (resolved != null) { + for (Iterator iter = resolved.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + ret.add(node.getRealNode()); + } + } + return ret; + } + + public Collection getEvictedRevisions(ModuleId mid, String rootModuleConf) { + Collection evicted = (Collection) evictedRevs.get(new ModuleIdConf(mid, rootModuleConf)); + if (evicted == null) { + return new HashSet(); + } else { + return new HashSet(evicted); + } + } + + public void setEvictedNodes(ModuleId moduleId, String rootModuleConf, Collection evicted) { + ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); + evictedDeps.put(moduleIdConf, new HashSet(evicted)); + Collection evictedRevs = new HashSet(); + for (Iterator iter = evicted.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + evictedRevs.add(node.getId()); + evictedRevs.add(node.getResolvedId()); + } + this.evictedRevs.put(moduleIdConf, evictedRevs); + } + + public boolean isEvicted(String rootModuleConf) { + cleanEvicted(); + IvyNode root = node.getRoot(); + return root != node + && !root.getResolvedRevisions(node.getId().getModuleId(), rootModuleConf).contains( + node.getResolvedId()) && getEvictedData(rootModuleConf) != null; + } + + public boolean isCompletelyEvicted() { + cleanEvicted(); + if (node.isRoot()) { + return false; + } + String[] rootModuleConfigurations = node.getRootModuleConfigurations(); + for (int i = 0; i < rootModuleConfigurations.length; i++) { + if (!isEvicted(rootModuleConfigurations[i])) { + return false; + } + } + return true; + } + + private void cleanEvicted() { + // check if it was evicted by a node that we are now the real node for + for (Iterator iter = evicted.keySet().iterator(); iter.hasNext();) { + String rootModuleConf = (String) iter.next(); + EvictionData ed = (EvictionData) evicted.get(rootModuleConf); + Collection sel = ed.getSelected(); + if (sel != null) { + for (Iterator iterator = sel.iterator(); iterator.hasNext();) { + IvyNode n = (IvyNode) iterator.next(); + if (n.getRealNode().equals(this)) { + // yes, we are the real node for a selected one ! + // we are no more evicted in this conf ! + iter.remove(); + } + } + } + } + } + + public void markEvicted(String rootModuleConf, IvyNode node, ConflictManager conflictManager, + Collection resolved) { + EvictionData evictionData = new EvictionData(rootModuleConf, node, conflictManager, + resolved); + markEvicted(evictionData); + } + + public void markEvicted(EvictionData evictionData) { + evicted.put(evictionData.getRootModuleConf(), evictionData); + } + + public EvictionData getEvictedData(String rootModuleConf) { + cleanEvicted(); + return (EvictionData) evicted.get(rootModuleConf); + } + + public String[] getEvictedConfs() { + cleanEvicted(); + return (String[]) evicted.keySet().toArray(new String[evicted.keySet().size()]); + } + + /** + * Returns null if this node has only be evicted transitively, or the the colletion of selected + * nodes if it has been evicted by other selected nodes + * + * @return + */ + public Collection getAllEvictingNodes() { + Collection allEvictingNodes = null; + for (Iterator iter = evicted.values().iterator(); iter.hasNext();) { + EvictionData ed = (EvictionData) iter.next(); + Collection selected = ed.getSelected(); + if (selected != null) { + if (allEvictingNodes == null) { + allEvictingNodes = new HashSet(); + } + allEvictingNodes.addAll(selected); + } + } + return allEvictingNodes; + } + + public Collection getAllEvictingConflictManagers() { + Collection ret = new HashSet(); + for (Iterator iter = evicted.values().iterator(); iter.hasNext();) { + EvictionData ed = (EvictionData) iter.next(); + ret.add(ed.getConflictManager()); + } + return ret; + } + + /** + * Returns the eviction data for this node if it has been previously evicted in the root, null + * otherwise (if it hasn't been evicted in root) for the given rootModuleConf. Note that this + * method only works if conflict resolution has already be done in all the ancestors. + * + * @param rootModuleConf + * @param ancestor + * @return + */ + public EvictionData getEvictionDataInRoot(String rootModuleConf, IvyNode ancestor) { + Collection selectedNodes = node.getRoot().getResolvedNodes(node.getModuleId(), + rootModuleConf); + for (Iterator iter = selectedNodes.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (node.getResolvedId().equals(this.node.getResolvedId())) { + // the node is part of the selected ones for the root: no eviction data to return + return null; + } + } + // we didn't find this mrid in the selected ones for the root: it has been previously + // evicted + return new EvictionData(rootModuleConf, ancestor, node.getRoot().getConflictManager( + node.getModuleId()), selectedNodes); + } + + public Collection getPendingConflicts(String rootModuleConf, ModuleId mid) { + Collection resolved = (Collection) pendingConflicts.get(new ModuleIdConf(mid, + rootModuleConf)); + Set ret = new HashSet(); + if (resolved != null) { + for (Iterator iter = resolved.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + ret.add(node.getRealNode()); + } + } + return ret; + } + + public void setPendingConflicts(ModuleId moduleId, String rootModuleConf, Collection conflicts) { + ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); + pendingConflicts.put(moduleIdConf, new HashSet(conflicts)); + } + +} diff --git a/src/java/org/apache/ivy/core/resolve/ResolveData.java b/src/java/org/apache/ivy/core/resolve/ResolveData.java index 035ec0ee..3b67dca9 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolveData.java +++ b/src/java/org/apache/ivy/core/resolve/ResolveData.java @@ -1,179 +1,179 @@ -/* - * 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.core.resolve; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ConfigurationResolveReport; -import org.apache.ivy.core.settings.IvySettings; - -public class ResolveData { - private ResolveEngine engine; - - private Map visitData; // shared map of all visit data: Map (ModuleRevisionId -> VisitData) - - private ConfigurationResolveReport report; - - private ResolveOptions options; - - public ResolveData(ResolveData data, boolean validate) { - this(data.engine, new ResolveOptions(data.options).setValidate(validate), data.report, - data.visitData); - } - - public ResolveData(ResolveEngine engine, ResolveOptions options) { - this(engine, options, null, new LinkedHashMap()); - } - - public ResolveData(ResolveEngine engine, ResolveOptions options, - ConfigurationResolveReport report) { - this(engine, options, report, new LinkedHashMap()); - } - - public ResolveData(ResolveEngine engine, ResolveOptions options, - ConfigurationResolveReport report, Map visitData) { - this.engine = engine; - this.report = report; - this.visitData = visitData; - this.options = options; - } - - /** - * Returns the Map of visit data. Map (ModuleRevisionId -> VisitData) - * - * @return - */ - public Map getVisitDataMap() { - return visitData; - } - - public ConfigurationResolveReport getReport() { - return report; - } - - public IvyNode getNode(ModuleRevisionId mrid) { - VisitData visitData = getVisitData(mrid); - return visitData == null ? null : visitData.getNode(); - } - - public Collection getNodes() { - Collection nodes = new ArrayList(); - for (Iterator iter = visitData.values().iterator(); iter.hasNext();) { - VisitData vdata = (VisitData) iter.next(); - nodes.add(vdata.getNode()); - } - return nodes; - } - - public Collection getNodeIds() { - return visitData.keySet(); - } - - public VisitData getVisitData(ModuleRevisionId mrid) { - return (VisitData) visitData.get(mrid); - } - - public void register(VisitNode node) { - register(node.getId(), node); - } - - public void register(ModuleRevisionId mrid, VisitNode node) { - VisitData visitData = getVisitData(mrid); - if (visitData == null) { - visitData = new VisitData(node.getNode()); - visitData.addVisitNode(node); - this.visitData.put(mrid, visitData); - } else { - visitData.setNode(node.getNode()); - visitData.addVisitNode(node); - } - } - - /** - * Updates the visit data currently associated with the given mrid with the given node and the - * visit nodes of the old visitData for the given rootModuleConf - * - * @param mrid - * the module revision id for which the update should be done - * @param node - * the IvyNode to associate with the visit data to update - * @param rootModuleConf - * the root module configuration in which the update is made - */ - void replaceNode(ModuleRevisionId mrid, IvyNode node, String rootModuleConf) { - VisitData visitData = getVisitData(mrid); - if (visitData == null) { - throw new IllegalArgumentException("impossible to replace node for id " + mrid - + ". No registered node found."); - } - VisitData keptVisitData = getVisitData(node.getId()); - if (keptVisitData == null) { - throw new IllegalArgumentException("impossible to replace node with " + node - + ". No registered node found for " + node.getId() + "."); - } - // replace visit data in Map (discards old one) - this.visitData.put(mrid, keptVisitData); - // update visit data with discarde visit nodes - keptVisitData.addVisitNodes(rootModuleConf, visitData.getVisitNodes(rootModuleConf)); - } - - public void setReport(ConfigurationResolveReport report) { - this.report = report; - } - - public Date getDate() { - return options.getDate(); - } - - public boolean isValidate() { - return options.isValidate(); - } - - public boolean isTransitive() { - return options.isTransitive(); - } - - public ResolveOptions getOptions() { - return options; - } - - public CacheManager getCacheManager() { - return options.getCache(); - } - - public IvySettings getSettings() { - return engine.getSettings(); - } - - public EventManager getEventManager() { - return engine.getEventManager(); - } - - public ResolveEngine getEngine() { - return engine; - } - -} +/* + * 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.core.resolve; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ConfigurationResolveReport; +import org.apache.ivy.core.settings.IvySettings; + +public class ResolveData { + private ResolveEngine engine; + + private Map visitData; // shared map of all visit data: Map (ModuleRevisionId -> VisitData) + + private ConfigurationResolveReport report; + + private ResolveOptions options; + + public ResolveData(ResolveData data, boolean validate) { + this(data.engine, new ResolveOptions(data.options).setValidate(validate), data.report, + data.visitData); + } + + public ResolveData(ResolveEngine engine, ResolveOptions options) { + this(engine, options, null, new LinkedHashMap()); + } + + public ResolveData(ResolveEngine engine, ResolveOptions options, + ConfigurationResolveReport report) { + this(engine, options, report, new LinkedHashMap()); + } + + public ResolveData(ResolveEngine engine, ResolveOptions options, + ConfigurationResolveReport report, Map visitData) { + this.engine = engine; + this.report = report; + this.visitData = visitData; + this.options = options; + } + + /** + * Returns the Map of visit data. Map (ModuleRevisionId -> VisitData) + * + * @return + */ + public Map getVisitDataMap() { + return visitData; + } + + public ConfigurationResolveReport getReport() { + return report; + } + + public IvyNode getNode(ModuleRevisionId mrid) { + VisitData visitData = getVisitData(mrid); + return visitData == null ? null : visitData.getNode(); + } + + public Collection getNodes() { + Collection nodes = new ArrayList(); + for (Iterator iter = visitData.values().iterator(); iter.hasNext();) { + VisitData vdata = (VisitData) iter.next(); + nodes.add(vdata.getNode()); + } + return nodes; + } + + public Collection getNodeIds() { + return visitData.keySet(); + } + + public VisitData getVisitData(ModuleRevisionId mrid) { + return (VisitData) visitData.get(mrid); + } + + public void register(VisitNode node) { + register(node.getId(), node); + } + + public void register(ModuleRevisionId mrid, VisitNode node) { + VisitData visitData = getVisitData(mrid); + if (visitData == null) { + visitData = new VisitData(node.getNode()); + visitData.addVisitNode(node); + this.visitData.put(mrid, visitData); + } else { + visitData.setNode(node.getNode()); + visitData.addVisitNode(node); + } + } + + /** + * Updates the visit data currently associated with the given mrid with the given node and the + * visit nodes of the old visitData for the given rootModuleConf + * + * @param mrid + * the module revision id for which the update should be done + * @param node + * the IvyNode to associate with the visit data to update + * @param rootModuleConf + * the root module configuration in which the update is made + */ + void replaceNode(ModuleRevisionId mrid, IvyNode node, String rootModuleConf) { + VisitData visitData = getVisitData(mrid); + if (visitData == null) { + throw new IllegalArgumentException("impossible to replace node for id " + mrid + + ". No registered node found."); + } + VisitData keptVisitData = getVisitData(node.getId()); + if (keptVisitData == null) { + throw new IllegalArgumentException("impossible to replace node with " + node + + ". No registered node found for " + node.getId() + "."); + } + // replace visit data in Map (discards old one) + this.visitData.put(mrid, keptVisitData); + // update visit data with discarde visit nodes + keptVisitData.addVisitNodes(rootModuleConf, visitData.getVisitNodes(rootModuleConf)); + } + + public void setReport(ConfigurationResolveReport report) { + this.report = report; + } + + public Date getDate() { + return options.getDate(); + } + + public boolean isValidate() { + return options.isValidate(); + } + + public boolean isTransitive() { + return options.isTransitive(); + } + + public ResolveOptions getOptions() { + return options; + } + + public CacheManager getCacheManager() { + return options.getCache(); + } + + public IvySettings getSettings() { + return engine.getSettings(); + } + + public EventManager getEventManager() { + return engine.getEventManager(); + } + + public ResolveEngine getEngine() { + return engine; + } + +} diff --git a/src/java/org/apache/ivy/core/resolve/ResolveEngine.java b/src/java/org/apache/ivy/core/resolve/ResolveEngine.java index 8e80d912..1f48062d 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolveEngine.java +++ b/src/java/org/apache/ivy/core/resolve/ResolveEngine.java @@ -1,928 +1,928 @@ -/* - * 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.core.resolve; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URL; -import java.text.ParseException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.ListIterator; -import java.util.Properties; -import java.util.Set; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.event.download.PrepareDownloadEvent; -import org.apache.ivy.core.event.resolve.EndResolveEvent; -import org.apache.ivy.core.event.resolve.StartResolveEvent; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.ConfigurationResolveReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.core.sort.SortEngine; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.ivy.plugins.repository.url.URLResource; -import org.apache.ivy.plugins.resolver.CacheResolver; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.filter.Filter; - -/** - * The resolve engine which is the core of the dependency resolution mechanism used in Ivy. It - * features several resolve methods, some very simple, like {@link #resolve(File)} and - * {@link #resolve(URL)} which allow to simply resolve dependencies of a single module descriptor, - * or more complete one, like the {@link #resolve(ModuleDescriptor, ResolveOptions)} which allows to - * provide options to the resolution engine. - * - * @see ResolveOptions - */ -public class ResolveEngine { - private IvySettings settings; - - private EventManager eventManager; - - private SortEngine sortEngine; - - private Set fetchedSet = new HashSet(); - - private DependencyResolver dictatorResolver; - - /** - * Constructs a ResolveEngine. - * - * @param settings - * the settings to use to configure the engine. Must not be null. - * @param eventManager - * the event manager to use to send events about the resolution process. Must not be - * null. - * @param sortEngine - * the sort engine to use to sort modules before producing the dependency resolution - * report. Must not be null. - */ - public ResolveEngine(IvySettings settings, EventManager eventManager, SortEngine sortEngine) { - this.settings = settings; - this.eventManager = eventManager; - this.sortEngine = sortEngine; - } - - /** - * Returns the currently configured dictator resolver, which when non null is used in place of - * any specified resolver in the {@link IvySettings} - * - * @return the currently configured dictator resolver, may be null. - */ - public DependencyResolver getDictatorResolver() { - return dictatorResolver; - } - - /** - * Sets a dictator resolver, which is used in place of regular dependency resolver for - * subsequent dependency resolution by this engine. - * - * @param dictatorResolver - * the dictator resolver to use in this engine, null if regular settings should used - */ - public void setDictatorResolver(DependencyResolver dictatorResolver) { - this.dictatorResolver = dictatorResolver; - settings.setDictatorResolver(dictatorResolver); - } - - public ResolveReport resolve(File ivySource) throws ParseException, IOException { - return resolve(ivySource.toURL()); - } - - public ResolveReport resolve(URL ivySource) throws ParseException, IOException { - return resolve(ivySource, new ResolveOptions()); - } - - /** - * Resolves the module identified by the given mrid with its dependencies if transitive is set - * to true. - */ - public ResolveReport resolve(final ModuleRevisionId mrid, ResolveOptions options, - boolean changing) throws ParseException, IOException { - DefaultModuleDescriptor md; - - String[] confs = options.getConfs(); - if (confs.length == 1 && confs[0].equals("*")) { - // create new resolve options because this is a different resolve than the real resolve - // (which will be a resolve of a newCallerInstance module) - ResolvedModuleRevision rmr = findModule(mrid, new ResolveOptions(options)); - if (rmr == null) { - md = DefaultModuleDescriptor.newCallerInstance(mrid, confs, options.isTransitive(), - changing); - return new ResolveReport(md, options.getResolveId()) { - public boolean hasError() { - return true; - } - - public List getProblemMessages() { - return Arrays.asList(new String[] {"module not found: " + mrid}); - } - }; - } else { - confs = rmr.getDescriptor().getConfigurationsNames(); - md = DefaultModuleDescriptor.newCallerInstance(ModuleRevisionId.newInstance(mrid, - rmr.getId().getRevision()), confs, options.isTransitive(), changing); - } - } else { - md = DefaultModuleDescriptor.newCallerInstance(mrid, confs, options.isTransitive(), - changing); - } - - return resolve(md, options); - } - - /** - * Resolve dependencies of a module described by an ivy file. Note: the method signature is way - * too long, we should use a class to store the settings of the resolve. - */ - public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException, - IOException { - URLResource res = new URLResource(ivySource); - ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res); - Message.verbose("using " + parser + " to parse " + ivySource); - ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, options.isValidate()); - String revision = options.getRevision(); - if (revision == null && md.getResolvedModuleRevisionId().getRevision() == null) { - revision = Ivy.getWorkingRevision(); - } - if (revision != null) { - md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(), - revision)); - } - - return resolve(md, options); - } - - /** - * Resolve dependencies of a module described by a module descriptor Note: the method signature - * is way too long, we should use a class to store the settings of the resolve. - */ - public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options) - throws ParseException, IOException, FileNotFoundException { - DependencyResolver oldDictator = getDictatorResolver(); - if (options.isUseCacheOnly()) { - setDictatorResolver(new CacheResolver(settings)); - } - try { - CacheManager cacheManager = options.getCache(); - if (cacheManager == null) { // ensure that a cache is configured - cacheManager = IvyContext.getContext().getCacheManager(); - options.setCache(cacheManager); - } else { - IvyContext.getContext().setCache(cacheManager.getCache()); - } - - String[] confs = options.getConfs(); - if (confs.length == 1 && confs[0].equals("*")) { - confs = md.getConfigurationsNames(); - } - options.setConfs(confs); - - if (options.getResolveId() == null) { - options.setResolveId(ResolveOptions.getDefaultResolveId(md)); - } - - eventManager.fireIvyEvent(new StartResolveEvent(md, confs)); - - long start = System.currentTimeMillis(); - Message.info(":: resolving dependencies :: " + md.getResolvedModuleRevisionId() - + (options.isTransitive() ? "" : " [not transitive]")); - Message.info("\tconfs: " + Arrays.asList(confs)); - Message.verbose("\tvalidate = " + options.isValidate()); - ResolveReport report = new ResolveReport(md, options.getResolveId()); - - // resolve dependencies - IvyNode[] dependencies = getDependencies(md, options, report); - report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter()); - - // produce resolved ivy file and ivy properties in cache - File ivyFileInCache = cacheManager.getResolvedIvyFileInCache(md - .getResolvedModuleRevisionId()); - md.toIvyFile(ivyFileInCache); - - // we store the resolved dependencies revisions and statuses per asked dependency - // revision id, - // for direct dependencies only. - // this is used by the deliver task to resolve dynamic revisions to static ones - File ivyPropertiesInCache = cacheManager.getResolvedIvyPropertiesInCache(md - .getResolvedModuleRevisionId()); - Properties props = new Properties(); - if (dependencies.length > 0) { - IvyNode root = dependencies[0].getRoot(); - for (int i = 0; i < dependencies.length; i++) { - if (!dependencies[i].isCompletelyEvicted() && !dependencies[i].hasProblem()) { - DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root); - if (dd != null) { - String rev = dependencies[i].getResolvedId().getRevision(); - String status = dependencies[i].getDescriptor().getStatus(); - props.put(dd.getDependencyRevisionId().encodeToString(), rev + " " - + status); - } - } - } - } - FileOutputStream out = new FileOutputStream(ivyPropertiesInCache); - props.store(out, md.getResolvedModuleRevisionId() + " resolved revisions"); - out.close(); - Message.verbose("\tresolved ivy file produced in " + ivyFileInCache); - - report.setResolveTime(System.currentTimeMillis() - start); - - if (options.isDownload()) { - Message.verbose(":: downloading artifacts ::"); - - downloadArtifacts(report, cacheManager, options.isUseOrigin(), options - .getArtifactFilter()); - } - - if (options.isOutputReport()) { - outputReport(report, cacheManager.getCache()); - } - - eventManager.fireIvyEvent(new EndResolveEvent(md, confs, report)); - return report; - } finally { - setDictatorResolver(oldDictator); - } - } - - public void outputReport(ResolveReport report, File cache) { - Message.info(":: resolution report ::"); - report.setProblemMessages(Message.getProblems()); - // output report - report.output(settings.getReportOutputters(), cache); - - Message.verbose("\tresolve done (" + report.getResolveTime() + "ms resolve - " - + report.getDownloadTime() + "ms download)"); - Message.sumupProblems(); - } - - public void downloadArtifacts(ResolveReport report, CacheManager cacheManager, - boolean useOrigin, Filter artifactFilter) { - long start = System.currentTimeMillis(); - IvyNode[] dependencies = (IvyNode[]) report.getDependencies().toArray( - new IvyNode[report.getDependencies().size()]); - - eventManager.fireIvyEvent(new PrepareDownloadEvent((Artifact[]) report.getArtifacts() - .toArray(new Artifact[report.getArtifacts().size()]))); - - for (int i = 0; i < dependencies.length; i++) { - checkInterrupted(); - // download artifacts required in all asked configurations - if (!dependencies[i].isCompletelyEvicted() && !dependencies[i].hasProblem()) { - DependencyResolver resolver = dependencies[i].getModuleRevision() - .getArtifactResolver(); - Artifact[] selectedArtifacts = dependencies[i].getSelectedArtifacts(artifactFilter); - DownloadReport dReport = resolver.download(selectedArtifacts, new DownloadOptions( - settings, cacheManager, eventManager, useOrigin)); - ArtifactDownloadReport[] adrs = dReport.getArtifactsReports(); - for (int j = 0; j < adrs.length; j++) { - if (adrs[j].getDownloadStatus() == DownloadStatus.FAILED) { - Message.warn("\t[NOT FOUND ] " + adrs[j].getArtifact()); - resolver.reportFailure(adrs[j].getArtifact()); - } - } - // update concerned reports - String[] dconfs = dependencies[i].getRootModuleConfigurations(); - for (int j = 0; j < dconfs.length; j++) { - // the report itself is responsible to take into account only - // artifacts required in its corresponding configuration - // (as described by the Dependency object) - if (dependencies[i].isEvicted(dconfs[j])) { - report.getConfigurationReport(dconfs[j]).addDependency(dependencies[i]); - } else { - report.getConfigurationReport(dconfs[j]).addDependency(dependencies[i], - dReport); - } - } - } - } - report.setDownloadTime(System.currentTimeMillis() - start); - } - - /** - * Download an artifact to the cache. Not used internally, useful especially for IDE plugins - * needing to download artifact one by one (for source or javadoc artifact, for instance). - * Downloaded artifact file can be accessed using getArchiveFileInCache method. It is possible - * to track the progression of the download using classical ivy progress monitoring feature (see - * addTransferListener). - * - * @param artifact - * the artifact to download - * @param cacheManager - * the cacheManager to use. - * @return a report concerning the download - */ - public ArtifactDownloadReport download(Artifact artifact, CacheManager cacheManager, - boolean useOrigin) { - DependencyResolver resolver = settings.getResolver(artifact.getModuleRevisionId() - .getModuleId()); - DownloadReport r = resolver.download(new Artifact[] {artifact}, new DownloadOptions( - settings, cacheManager, eventManager, useOrigin)); - return r.getArtifactReport(artifact); - } - - /** - * Resolve the dependencies of a module without downloading corresponding artifacts. The module - * to resolve is given by its ivy file URL. This method requires appropriate configuration of - * the ivy instance, especially resolvers. - * - * @param ivySource - * url of the ivy file to use for dependency resolving - * @param confs - * an array of configuration names to resolve - must not be null nor empty - * @param cache - * the cache to use - default cache is used if null - * @param date - * the date to which resolution must be done - may be null - * @return an array of the resolved dependencies - * @throws ParseException - * if a parsing problem occured in the ivy file - * @throws IOException - * if an IO problem was raised during ivy file parsing - */ - public IvyNode[] getDependencies(URL ivySource, ResolveOptions options) throws ParseException, - IOException { - return getDependencies(ModuleDescriptorParserRegistry.getInstance().parseDescriptor( - settings, ivySource, options.isValidate()), options, null); - } - - /** - * Resolve the dependencies of a module without downloading corresponding artifacts. The module - * to resolve is given by its module descriptor.This method requires appropriate configuration - * of the ivy instance, especially resolvers. - * - * @param md - * the descriptor of the module for which we want to get dependencies - must not be - * null - * @param options - * the resolve options to use to resolve the dependencies - * @param report - * a resolve report to fill during resolution - may be null - * @return an array of the resolved Dependencies - */ - public IvyNode[] getDependencies(ModuleDescriptor md, ResolveOptions options, - ResolveReport report) { - if (md == null) { - throw new NullPointerException("module descriptor must not be null"); - } - CacheManager cacheManager = options.getCache(); - if (cacheManager == null) { // ensure that a cache is configured - cacheManager = IvyContext.getContext().getCacheManager(); - options.setCache(cacheManager); - } else { - IvyContext.getContext().setCache(cacheManager.getCache()); - } - - String[] confs = options.getConfs(); - if (confs.length == 1 && confs[0].equals("*")) { - confs = md.getConfigurationsNames(); - } - options.setConfs(confs); - - Date reportDate = new Date(); - ResolveData data = new ResolveData(this, options); - IvyNode rootNode = new IvyNode(data, md); - - for (int i = 0; i < confs.length; i++) { - if (confs[i] == null) { - throw new NullPointerException("null conf not allowed: confs where: " - + Arrays.asList(confs)); - } - - Message.verbose("resolving dependencies for configuration '" + confs[i] + "'"); - // for each configuration we clear the cache of what's been fetched - fetchedSet.clear(); - - Configuration configuration = md.getConfiguration(confs[i]); - if (configuration == null) { - Message.error("asked configuration not found in " + md.getModuleRevisionId() + ": " - + confs[i]); - } else { - ConfigurationResolveReport confReport = null; - if (report != null) { - confReport = report.getConfigurationReport(confs[i]); - if (confReport == null) { - confReport = new ConfigurationResolveReport(this, md, confs[i], reportDate, - options); - report.addReport(confs[i], confReport); - } - } - // we reuse the same resolve data with a new report for each conf - data.setReport(confReport); - - // update the root module conf we are about to fetch - VisitNode root = new VisitNode(data, rootNode, null, confs[i], null); - root.setRequestedConf(confs[i]); - rootNode.updateConfsToFetch(Collections.singleton(confs[i])); - - // go fetch ! - fetchDependencies(root, confs[i], false); - - // clean data - for (Iterator iter = data.getNodes().iterator(); iter.hasNext();) { - IvyNode dep = (IvyNode) iter.next(); - dep.clean(); - } - } - } - - // prune and reverse sort fectched dependencies - Collection dependencies = new LinkedHashSet(data.getNodes().size()); // use a Set to - // avoids duplicates - for (Iterator iter = data.getNodes().iterator(); iter.hasNext();) { - IvyNode dep = (IvyNode) iter.next(); - if (dep != null) { - dependencies.add(dep); - } - } - List sortedDependencies = sortEngine.sortNodes(dependencies); - Collections.reverse(sortedDependencies); - - // handle transitive eviction now: - // if a module has been evicted then all its dependencies required - // only by it should be evicted too. Since nodes are now sorted from the more dependent to - // the less one, we can traverse the list and check only the direct parent and not all - // the ancestors - for (ListIterator iter = sortedDependencies.listIterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (!node.isCompletelyEvicted()) { - for (int i = 0; i < confs.length; i++) { - IvyNodeCallers.Caller[] callers = node.getCallers(confs[i]); - if (settings.debugConflictResolution()) { - Message.debug("checking if " + node.getId() - + " is transitively evicted in " + confs[i]); - } - boolean allEvicted = callers.length > 0; - for (int j = 0; j < callers.length; j++) { - if (callers[j].getModuleRevisionId().equals(md.getModuleRevisionId())) { - // the caller is the root module itself, it can't be evicted - allEvicted = false; - break; - } else { - IvyNode callerNode = data.getNode(callers[j].getModuleRevisionId()); - if (callerNode == null) { - Message.warn("ivy internal error: no node found for " - + callers[j].getModuleRevisionId() + ": looked in " - + data.getNodeIds() + " and root module id was " - + md.getModuleRevisionId()); - } else if (!callerNode.isEvicted(confs[i])) { - allEvicted = false; - break; - } else { - if (settings.debugConflictResolution()) { - Message.debug("caller " + callerNode.getId() + " of " - + node.getId() + " is evicted"); - } - } - } - } - if (allEvicted) { - Message.verbose("all callers are evicted for " + node + ": evicting too"); - node.markEvicted(confs[i], null, null, null); - } else { - if (settings.debugConflictResolution()) { - Message - .debug(node.getId() - + " isn't transitively evicted, at least one caller was not evicted"); - } - } - } - } - } - - return (IvyNode[]) dependencies.toArray(new IvyNode[dependencies.size()]); - } - - private void fetchDependencies(VisitNode node, String conf, boolean shouldBePublic) { - checkInterrupted(); - long start = System.currentTimeMillis(); - if (node.getParent() != null) { - Message.verbose("== resolving dependencies " + node.getParent().getId() + "->" - + node.getId() + " [" + node.getParentConf() + "->" + conf + "]"); - } else { - Message.verbose("== resolving dependencies for " + node.getId() + " [" + conf + "]"); - } - resolveConflict(node); - - if (node.loadData(conf, shouldBePublic)) { - resolveConflict(node); - if (!node.isEvicted()) { - String[] confs = node.getRealConfs(conf); - for (int i = 0; i < confs.length; i++) { - doFetchDependencies(node, confs[i]); - } - } - } else if (!node.hasProblem()) { - // the node has not been loaded but hasn't problem: it was already loaded - // => we just have to update its dependencies data - if (!node.isEvicted()) { - String[] confs = node.getRealConfs(conf); - for (int i = 0; i < confs.length; i++) { - doFetchDependencies(node, confs[i]); - } - } - } - if (node.isEvicted()) { - // update selected nodes with confs asked in evicted one - EvictionData ed = node.getEvictedData(); - if (ed.getSelected() != null) { - for (Iterator iter = ed.getSelected().iterator(); iter.hasNext();) { - IvyNode selected = (IvyNode) iter.next(); - if (!selected.isLoaded()) { - // the node is not yet loaded, we can simply update its set of - // configurations to fetch - selected.updateConfsToFetch(Collections.singleton(conf)); - } else { - // the node has already been loaded, we must fetch its dependencies in the - // required conf - fetchDependencies(node.gotoNode(selected), conf, true); - } - } - } - } - if (settings.debugConflictResolution()) { - Message.debug(node.getId() + " => dependencies resolved in " + conf + " (" - + (System.currentTimeMillis() - start) + "ms)"); - } - } - - private void doFetchDependencies(VisitNode node, String conf) { - Configuration c = node.getConfiguration(conf); - if (c == null) { - Message.warn("configuration not found '" + conf + "' in " + node.getResolvedId() - + ": ignoring"); - if (node.getParent() != null) { - Message.warn("it was required from " + node.getParent().getResolvedId()); - } - return; - } - // we handle the case where the asked configuration extends others: - // we have to first fetch the extended configurations - - // first we check if this is the actual requested conf (not an extended one) - boolean requestedConfSet = false; - if (node.getRequestedConf() == null) { - node.setRequestedConf(conf); - requestedConfSet = true; - } - // now let's recurse in extended confs - String[] extendedConfs = c.getExtends(); - if (extendedConfs.length > 0) { - node.updateConfsToFetch(Arrays.asList(extendedConfs)); - } - for (int i = 0; i < extendedConfs.length; i++) { - fetchDependencies(node, extendedConfs[i], false); - } - - // now we can actually resolve this configuration dependencies - DependencyDescriptor dd = node.getDependencyDescriptor(); - if (!isDependenciesFetched(node.getNode(), conf) && (dd == null || node.isTransitive())) { - Collection dependencies = node.getDependencies(conf); - for (Iterator iter = dependencies.iterator(); iter.hasNext();) { - VisitNode dep = (VisitNode) iter.next(); - dep.useRealNode(); // the node may have been resolved to another real one while - // resolving other deps - if (dep.isCircular()) { - continue; - } - String[] confs = dep.getRequiredConfigurations(node, conf); - for (int i = 0; i < confs.length; i++) { - fetchDependencies(dep, confs[i], true); - } - // if there are still confs to fetch (usually because they have - // been updated when evicting another module), we fetch them now - confs = dep.getConfsToFetch(); - for (int i = 0; i < confs.length; i++) { - fetchDependencies(dep, confs[i], true); - } - } - } - // we have finiched with this configuration, if it was the original requested conf - // we can clean it now - if (requestedConfSet) { - node.setRequestedConf(null); - } - - } - - /** - * Returns true if we've already fetched the dependencies for this node and configuration - * - * @param node - * node to check - * @param conf - * configuration to check - * @return true if we've already fetched this dependency - */ - private boolean isDependenciesFetched(IvyNode node, String conf) { - ModuleId moduleId = node.getModuleId(); - ModuleRevisionId moduleRevisionId = node.getResolvedId(); - String key = moduleId.getOrganisation() + "|" + moduleId.getName() + "|" - + moduleRevisionId.getRevision() + "|" + conf; - if (fetchedSet.contains(key)) { - return true; - } - fetchedSet.add(key); - return false; - } - - private void resolveConflict(VisitNode node) { - resolveConflict(node, node.getParent(), Collections.EMPTY_SET); - } - - /** - * Resolves conflict for the given node in the given ancestor. This method do conflict - * resolution in ancestor parents recursively, unless not necessary. - * - * @param node - * the node for which conflict resolution should be done - * @param ancestor - * the ancestor in which the conflict resolution should be done - * @param toevict - * a collection of IvyNode to evict (as computed by conflict resolution in - * descendants of ancestor) - * @return true if conflict resolution has been done, false it can't be done yet - */ - private boolean resolveConflict(VisitNode node, VisitNode ancestor, Collection toevict) { - if (ancestor == null || node == ancestor) { - return true; - } - // check if job is not already done - if (checkConflictSolvedEvicted(node, ancestor)) { - // job is done and node is evicted, nothing to do - return true; - } - if (checkConflictSolvedSelected(node, ancestor)) { - // job is done and node is selected, nothing to do for this ancestor, but we still have - // to check higher levels, for which conflict resolution might have been impossible - // before - if (resolveConflict(node, ancestor.getParent(), toevict)) { - // now that conflict resolution is ok in ancestors - // we just have to check if the node wasn't previously evicted in root ancestor - EvictionData evictionData = node.getEvictionDataInRoot(node.getRootModuleConf(), - ancestor); - if (evictionData != null) { - // node has been previously evicted in an ancestor: we mark it as evicted - if (settings.debugConflictResolution()) { - Message.debug(node + " was previously evicted in root module conf " - + node.getRootModuleConf()); - } - - node.markEvicted(evictionData); - if (settings.debugConflictResolution()) { - Message.debug("evicting " + node + " by " + evictionData); - } - } - return true; - } else { - return false; - } - } - - // compute conflicts - Collection resolvedNodes = new HashSet(ancestor.getNode().getResolvedNodes( - node.getModuleId(), node.getRootModuleConf())); - resolvedNodes.addAll(ancestor.getNode().getPendingConflicts(node.getRootModuleConf(), - node.getModuleId())); - Collection conflicts = computeConflicts(node, ancestor, toevict, resolvedNodes); - - if (settings.debugConflictResolution()) { - Message.debug("found conflicting revisions for " + node + " in " + ancestor + ": " - + conflicts); - } - - ConflictManager conflictManager = ancestor.getNode().getConflictManager(node.getModuleId()); - Collection resolved = conflictManager.resolveConflicts(ancestor.getNode(), conflicts); - - if (resolved == null) { - if (settings.debugConflictResolution()) { - Message.debug("impossible to resolve conflicts for " + node + " in " + ancestor - + " yet"); - Message - .debug("setting all nodes as pending conflicts for later conflict resolution: " - + conflicts); - } - ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), - conflicts); - return false; - } - - if (settings.debugConflictResolution()) { - Message.debug("selected revisions for " + node + " in " + ancestor + ": " + resolved); - } - if (resolved.contains(node.getNode())) { - // node has been selected for the current parent - - // handle previously selected nodes that are now evicted by this new node - toevict = resolvedNodes; - toevict.removeAll(resolved); - - for (Iterator iter = toevict.iterator(); iter.hasNext();) { - IvyNode te = (IvyNode) iter.next(); - te.markEvicted(node.getRootModuleConf(), ancestor.getNode(), conflictManager, - resolved); - - if (settings.debugConflictResolution()) { - Message.debug("evicting " + te + " by " - + te.getEvictedData(node.getRootModuleConf())); - } - } - - // it's very important to update resolved and evicted nodes BEFORE recompute parent call - // to allow it to recompute its resolved collection with correct data - // if necessary - ancestor.getNode().setResolvedNodes(node.getModuleId(), node.getRootModuleConf(), - resolved); - - Collection evicted = new HashSet(ancestor.getNode().getEvictedNodes(node.getModuleId(), - node.getRootModuleConf())); - evicted.removeAll(resolved); - evicted.addAll(toevict); - ancestor.getNode().setEvictedNodes(node.getModuleId(), node.getRootModuleConf(), - evicted); - ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), - Collections.EMPTY_SET); - - return resolveConflict(node, ancestor.getParent(), toevict); - } else { - // node has been evicted for the current parent - if (resolved.isEmpty()) { - if (settings.debugConflictResolution()) { - Message.verbose("conflict manager '" + conflictManager - + "' evicted all revisions among " + conflicts); - } - } - - // it's time to update parent resolved and evicted with what was found - - Collection evicted = new HashSet(ancestor.getNode().getEvictedNodes(node.getModuleId(), - node.getRootModuleConf())); - toevict.removeAll(resolved); - evicted.removeAll(resolved); - evicted.addAll(toevict); - evicted.add(node.getNode()); - ancestor.getNode().setEvictedNodes(node.getModuleId(), node.getRootModuleConf(), - evicted); - ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), - Collections.EMPTY_SET); - - node.markEvicted(ancestor, conflictManager, resolved); - if (settings.debugConflictResolution()) { - Message.debug("evicting " + node + " by " + node.getEvictedData()); - } - - // if resolved changed we have to go up in the graph - Collection prevResolved = ancestor.getNode().getResolvedNodes(node.getModuleId(), - node.getRootModuleConf()); - boolean solved = true; - if (!prevResolved.equals(resolved)) { - ancestor.getNode().setResolvedNodes(node.getModuleId(), node.getRootModuleConf(), - resolved); - for (Iterator iter = resolved.iterator(); iter.hasNext();) { - IvyNode sel = (IvyNode) iter.next(); - if (!prevResolved.contains(sel)) { - solved &= resolveConflict(node.gotoNode(sel), ancestor.getParent(), toevict); - } - } - } - return solved; - } - } - - private Collection computeConflicts(VisitNode node, VisitNode ancestor, Collection toevict, - Collection resolvedNodes) { - Collection conflicts = new HashSet(); - conflicts.add(node.getNode()); - if (resolvedNodes.removeAll(toevict)) { - // parent.resolved(node.mid) is not up to date: - // recompute resolved from all sub nodes - Collection deps = ancestor.getNode().getDependencies(node.getRootModuleConf(), - ancestor.getRequiredConfigurations()); - for (Iterator iter = deps.iterator(); iter.hasNext();) { - IvyNode dep = (IvyNode) iter.next(); - if (dep.getModuleId().equals(node.getModuleId())) { - conflicts.add(dep); - } - conflicts - .addAll(dep.getResolvedNodes(node.getModuleId(), node.getRootModuleConf())); - } - } else if (resolvedNodes.isEmpty() && node.getParent() != ancestor) { - DependencyDescriptor[] dds = ancestor.getDescriptor().getDependencies(); - for (int i = 0; i < dds.length; i++) { - if (dds[i].getDependencyId().equals(node.getModuleId())) { - IvyNode n = node.getNode().findNode(dds[i].getDependencyRevisionId()); - if (n != null) { - conflicts.add(n); - break; - } - } - } - } else { - conflicts.addAll(resolvedNodes); - } - return conflicts; - } - - private boolean checkConflictSolvedSelected(VisitNode node, VisitNode ancestor) { - if (ancestor.getResolvedRevisions(node.getModuleId()).contains(node.getResolvedId())) { - // resolve conflict has already be done with node with the same id - if (settings.debugConflictResolution()) { - Message.debug("conflict resolution already done for " + node + " in " + ancestor); - } - return true; - } - return false; - } - - private boolean checkConflictSolvedEvicted(VisitNode node, VisitNode ancestor) { - if (ancestor.getEvictedRevisions(node.getModuleId()).contains(node.getResolvedId())) { - // resolve conflict has already be done with node with the same id - if (settings.debugConflictResolution()) { - Message.debug("conflict resolution already done for " + node + " in " + ancestor); - } - return true; - } - return false; - } - - public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options) { - DependencyResolver r = settings.getResolver(id.getModuleId()); - if (r == null) { - throw new IllegalStateException("no resolver found for " + id.getModuleId()); - } - DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(id, - new String[] {"*"}, false, false); - - if (options.getResolveId() == null) { - options.setResolveId(ResolveOptions.getDefaultResolveId(md)); - } - - try { - return r.getDependency(new DefaultDependencyDescriptor(id, true), new ResolveData(this, - options, new ConfigurationResolveReport(this, md, "default", null, options))); - } catch (ParseException e) { - throw new RuntimeException("problem while parsing repository module descriptor for " - + id + ": " + e, e); - } - } - - public EventManager getEventManager() { - return eventManager; - } - - public IvySettings getSettings() { - return settings; - } - - public SortEngine getSortEngine() { - return sortEngine; - } - - private void checkInterrupted() { - IvyContext.getContext().getIvy().checkInterrupted(); - } - -} +/* + * 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.core.resolve; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.text.ParseException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.ListIterator; +import java.util.Properties; +import java.util.Set; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.event.download.PrepareDownloadEvent; +import org.apache.ivy.core.event.resolve.EndResolveEvent; +import org.apache.ivy.core.event.resolve.StartResolveEvent; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.ConfigurationResolveReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.core.sort.SortEngine; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.ivy.plugins.repository.url.URLResource; +import org.apache.ivy.plugins.resolver.CacheResolver; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.filter.Filter; + +/** + * The resolve engine which is the core of the dependency resolution mechanism used in Ivy. It + * features several resolve methods, some very simple, like {@link #resolve(File)} and + * {@link #resolve(URL)} which allow to simply resolve dependencies of a single module descriptor, + * or more complete one, like the {@link #resolve(ModuleDescriptor, ResolveOptions)} which allows to + * provide options to the resolution engine. + * + * @see ResolveOptions + */ +public class ResolveEngine { + private IvySettings settings; + + private EventManager eventManager; + + private SortEngine sortEngine; + + private Set fetchedSet = new HashSet(); + + private DependencyResolver dictatorResolver; + + /** + * Constructs a ResolveEngine. + * + * @param settings + * the settings to use to configure the engine. Must not be null. + * @param eventManager + * the event manager to use to send events about the resolution process. Must not be + * null. + * @param sortEngine + * the sort engine to use to sort modules before producing the dependency resolution + * report. Must not be null. + */ + public ResolveEngine(IvySettings settings, EventManager eventManager, SortEngine sortEngine) { + this.settings = settings; + this.eventManager = eventManager; + this.sortEngine = sortEngine; + } + + /** + * Returns the currently configured dictator resolver, which when non null is used in place of + * any specified resolver in the {@link IvySettings} + * + * @return the currently configured dictator resolver, may be null. + */ + public DependencyResolver getDictatorResolver() { + return dictatorResolver; + } + + /** + * Sets a dictator resolver, which is used in place of regular dependency resolver for + * subsequent dependency resolution by this engine. + * + * @param dictatorResolver + * the dictator resolver to use in this engine, null if regular settings should used + */ + public void setDictatorResolver(DependencyResolver dictatorResolver) { + this.dictatorResolver = dictatorResolver; + settings.setDictatorResolver(dictatorResolver); + } + + public ResolveReport resolve(File ivySource) throws ParseException, IOException { + return resolve(ivySource.toURL()); + } + + public ResolveReport resolve(URL ivySource) throws ParseException, IOException { + return resolve(ivySource, new ResolveOptions()); + } + + /** + * Resolves the module identified by the given mrid with its dependencies if transitive is set + * to true. + */ + public ResolveReport resolve(final ModuleRevisionId mrid, ResolveOptions options, + boolean changing) throws ParseException, IOException { + DefaultModuleDescriptor md; + + String[] confs = options.getConfs(); + if (confs.length == 1 && confs[0].equals("*")) { + // create new resolve options because this is a different resolve than the real resolve + // (which will be a resolve of a newCallerInstance module) + ResolvedModuleRevision rmr = findModule(mrid, new ResolveOptions(options)); + if (rmr == null) { + md = DefaultModuleDescriptor.newCallerInstance(mrid, confs, options.isTransitive(), + changing); + return new ResolveReport(md, options.getResolveId()) { + public boolean hasError() { + return true; + } + + public List getProblemMessages() { + return Arrays.asList(new String[] {"module not found: " + mrid}); + } + }; + } else { + confs = rmr.getDescriptor().getConfigurationsNames(); + md = DefaultModuleDescriptor.newCallerInstance(ModuleRevisionId.newInstance(mrid, + rmr.getId().getRevision()), confs, options.isTransitive(), changing); + } + } else { + md = DefaultModuleDescriptor.newCallerInstance(mrid, confs, options.isTransitive(), + changing); + } + + return resolve(md, options); + } + + /** + * Resolve dependencies of a module described by an ivy file. Note: the method signature is way + * too long, we should use a class to store the settings of the resolve. + */ + public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException, + IOException { + URLResource res = new URLResource(ivySource); + ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res); + Message.verbose("using " + parser + " to parse " + ivySource); + ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, options.isValidate()); + String revision = options.getRevision(); + if (revision == null && md.getResolvedModuleRevisionId().getRevision() == null) { + revision = Ivy.getWorkingRevision(); + } + if (revision != null) { + md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(), + revision)); + } + + return resolve(md, options); + } + + /** + * Resolve dependencies of a module described by a module descriptor Note: the method signature + * is way too long, we should use a class to store the settings of the resolve. + */ + public ResolveReport resolve(ModuleDescriptor md, ResolveOptions options) + throws ParseException, IOException, FileNotFoundException { + DependencyResolver oldDictator = getDictatorResolver(); + if (options.isUseCacheOnly()) { + setDictatorResolver(new CacheResolver(settings)); + } + try { + CacheManager cacheManager = options.getCache(); + if (cacheManager == null) { // ensure that a cache is configured + cacheManager = IvyContext.getContext().getCacheManager(); + options.setCache(cacheManager); + } else { + IvyContext.getContext().setCache(cacheManager.getCache()); + } + + String[] confs = options.getConfs(); + if (confs.length == 1 && confs[0].equals("*")) { + confs = md.getConfigurationsNames(); + } + options.setConfs(confs); + + if (options.getResolveId() == null) { + options.setResolveId(ResolveOptions.getDefaultResolveId(md)); + } + + eventManager.fireIvyEvent(new StartResolveEvent(md, confs)); + + long start = System.currentTimeMillis(); + Message.info(":: resolving dependencies :: " + md.getResolvedModuleRevisionId() + + (options.isTransitive() ? "" : " [not transitive]")); + Message.info("\tconfs: " + Arrays.asList(confs)); + Message.verbose("\tvalidate = " + options.isValidate()); + ResolveReport report = new ResolveReport(md, options.getResolveId()); + + // resolve dependencies + IvyNode[] dependencies = getDependencies(md, options, report); + report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter()); + + // produce resolved ivy file and ivy properties in cache + File ivyFileInCache = cacheManager.getResolvedIvyFileInCache(md + .getResolvedModuleRevisionId()); + md.toIvyFile(ivyFileInCache); + + // we store the resolved dependencies revisions and statuses per asked dependency + // revision id, + // for direct dependencies only. + // this is used by the deliver task to resolve dynamic revisions to static ones + File ivyPropertiesInCache = cacheManager.getResolvedIvyPropertiesInCache(md + .getResolvedModuleRevisionId()); + Properties props = new Properties(); + if (dependencies.length > 0) { + IvyNode root = dependencies[0].getRoot(); + for (int i = 0; i < dependencies.length; i++) { + if (!dependencies[i].isCompletelyEvicted() && !dependencies[i].hasProblem()) { + DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root); + if (dd != null) { + String rev = dependencies[i].getResolvedId().getRevision(); + String status = dependencies[i].getDescriptor().getStatus(); + props.put(dd.getDependencyRevisionId().encodeToString(), rev + " " + + status); + } + } + } + } + FileOutputStream out = new FileOutputStream(ivyPropertiesInCache); + props.store(out, md.getResolvedModuleRevisionId() + " resolved revisions"); + out.close(); + Message.verbose("\tresolved ivy file produced in " + ivyFileInCache); + + report.setResolveTime(System.currentTimeMillis() - start); + + if (options.isDownload()) { + Message.verbose(":: downloading artifacts ::"); + + downloadArtifacts(report, cacheManager, options.isUseOrigin(), options + .getArtifactFilter()); + } + + if (options.isOutputReport()) { + outputReport(report, cacheManager.getCache()); + } + + eventManager.fireIvyEvent(new EndResolveEvent(md, confs, report)); + return report; + } finally { + setDictatorResolver(oldDictator); + } + } + + public void outputReport(ResolveReport report, File cache) { + Message.info(":: resolution report ::"); + report.setProblemMessages(Message.getProblems()); + // output report + report.output(settings.getReportOutputters(), cache); + + Message.verbose("\tresolve done (" + report.getResolveTime() + "ms resolve - " + + report.getDownloadTime() + "ms download)"); + Message.sumupProblems(); + } + + public void downloadArtifacts(ResolveReport report, CacheManager cacheManager, + boolean useOrigin, Filter artifactFilter) { + long start = System.currentTimeMillis(); + IvyNode[] dependencies = (IvyNode[]) report.getDependencies().toArray( + new IvyNode[report.getDependencies().size()]); + + eventManager.fireIvyEvent(new PrepareDownloadEvent((Artifact[]) report.getArtifacts() + .toArray(new Artifact[report.getArtifacts().size()]))); + + for (int i = 0; i < dependencies.length; i++) { + checkInterrupted(); + // download artifacts required in all asked configurations + if (!dependencies[i].isCompletelyEvicted() && !dependencies[i].hasProblem()) { + DependencyResolver resolver = dependencies[i].getModuleRevision() + .getArtifactResolver(); + Artifact[] selectedArtifacts = dependencies[i].getSelectedArtifacts(artifactFilter); + DownloadReport dReport = resolver.download(selectedArtifacts, new DownloadOptions( + settings, cacheManager, eventManager, useOrigin)); + ArtifactDownloadReport[] adrs = dReport.getArtifactsReports(); + for (int j = 0; j < adrs.length; j++) { + if (adrs[j].getDownloadStatus() == DownloadStatus.FAILED) { + Message.warn("\t[NOT FOUND ] " + adrs[j].getArtifact()); + resolver.reportFailure(adrs[j].getArtifact()); + } + } + // update concerned reports + String[] dconfs = dependencies[i].getRootModuleConfigurations(); + for (int j = 0; j < dconfs.length; j++) { + // the report itself is responsible to take into account only + // artifacts required in its corresponding configuration + // (as described by the Dependency object) + if (dependencies[i].isEvicted(dconfs[j])) { + report.getConfigurationReport(dconfs[j]).addDependency(dependencies[i]); + } else { + report.getConfigurationReport(dconfs[j]).addDependency(dependencies[i], + dReport); + } + } + } + } + report.setDownloadTime(System.currentTimeMillis() - start); + } + + /** + * Download an artifact to the cache. Not used internally, useful especially for IDE plugins + * needing to download artifact one by one (for source or javadoc artifact, for instance). + * Downloaded artifact file can be accessed using getArchiveFileInCache method. It is possible + * to track the progression of the download using classical ivy progress monitoring feature (see + * addTransferListener). + * + * @param artifact + * the artifact to download + * @param cacheManager + * the cacheManager to use. + * @return a report concerning the download + */ + public ArtifactDownloadReport download(Artifact artifact, CacheManager cacheManager, + boolean useOrigin) { + DependencyResolver resolver = settings.getResolver(artifact.getModuleRevisionId() + .getModuleId()); + DownloadReport r = resolver.download(new Artifact[] {artifact}, new DownloadOptions( + settings, cacheManager, eventManager, useOrigin)); + return r.getArtifactReport(artifact); + } + + /** + * Resolve the dependencies of a module without downloading corresponding artifacts. The module + * to resolve is given by its ivy file URL. This method requires appropriate configuration of + * the ivy instance, especially resolvers. + * + * @param ivySource + * url of the ivy file to use for dependency resolving + * @param confs + * an array of configuration names to resolve - must not be null nor empty + * @param cache + * the cache to use - default cache is used if null + * @param date + * the date to which resolution must be done - may be null + * @return an array of the resolved dependencies + * @throws ParseException + * if a parsing problem occured in the ivy file + * @throws IOException + * if an IO problem was raised during ivy file parsing + */ + public IvyNode[] getDependencies(URL ivySource, ResolveOptions options) throws ParseException, + IOException { + return getDependencies(ModuleDescriptorParserRegistry.getInstance().parseDescriptor( + settings, ivySource, options.isValidate()), options, null); + } + + /** + * Resolve the dependencies of a module without downloading corresponding artifacts. The module + * to resolve is given by its module descriptor.This method requires appropriate configuration + * of the ivy instance, especially resolvers. + * + * @param md + * the descriptor of the module for which we want to get dependencies - must not be + * null + * @param options + * the resolve options to use to resolve the dependencies + * @param report + * a resolve report to fill during resolution - may be null + * @return an array of the resolved Dependencies + */ + public IvyNode[] getDependencies(ModuleDescriptor md, ResolveOptions options, + ResolveReport report) { + if (md == null) { + throw new NullPointerException("module descriptor must not be null"); + } + CacheManager cacheManager = options.getCache(); + if (cacheManager == null) { // ensure that a cache is configured + cacheManager = IvyContext.getContext().getCacheManager(); + options.setCache(cacheManager); + } else { + IvyContext.getContext().setCache(cacheManager.getCache()); + } + + String[] confs = options.getConfs(); + if (confs.length == 1 && confs[0].equals("*")) { + confs = md.getConfigurationsNames(); + } + options.setConfs(confs); + + Date reportDate = new Date(); + ResolveData data = new ResolveData(this, options); + IvyNode rootNode = new IvyNode(data, md); + + for (int i = 0; i < confs.length; i++) { + if (confs[i] == null) { + throw new NullPointerException("null conf not allowed: confs where: " + + Arrays.asList(confs)); + } + + Message.verbose("resolving dependencies for configuration '" + confs[i] + "'"); + // for each configuration we clear the cache of what's been fetched + fetchedSet.clear(); + + Configuration configuration = md.getConfiguration(confs[i]); + if (configuration == null) { + Message.error("asked configuration not found in " + md.getModuleRevisionId() + ": " + + confs[i]); + } else { + ConfigurationResolveReport confReport = null; + if (report != null) { + confReport = report.getConfigurationReport(confs[i]); + if (confReport == null) { + confReport = new ConfigurationResolveReport(this, md, confs[i], reportDate, + options); + report.addReport(confs[i], confReport); + } + } + // we reuse the same resolve data with a new report for each conf + data.setReport(confReport); + + // update the root module conf we are about to fetch + VisitNode root = new VisitNode(data, rootNode, null, confs[i], null); + root.setRequestedConf(confs[i]); + rootNode.updateConfsToFetch(Collections.singleton(confs[i])); + + // go fetch ! + fetchDependencies(root, confs[i], false); + + // clean data + for (Iterator iter = data.getNodes().iterator(); iter.hasNext();) { + IvyNode dep = (IvyNode) iter.next(); + dep.clean(); + } + } + } + + // prune and reverse sort fectched dependencies + Collection dependencies = new LinkedHashSet(data.getNodes().size()); // use a Set to + // avoids duplicates + for (Iterator iter = data.getNodes().iterator(); iter.hasNext();) { + IvyNode dep = (IvyNode) iter.next(); + if (dep != null) { + dependencies.add(dep); + } + } + List sortedDependencies = sortEngine.sortNodes(dependencies); + Collections.reverse(sortedDependencies); + + // handle transitive eviction now: + // if a module has been evicted then all its dependencies required + // only by it should be evicted too. Since nodes are now sorted from the more dependent to + // the less one, we can traverse the list and check only the direct parent and not all + // the ancestors + for (ListIterator iter = sortedDependencies.listIterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (!node.isCompletelyEvicted()) { + for (int i = 0; i < confs.length; i++) { + IvyNodeCallers.Caller[] callers = node.getCallers(confs[i]); + if (settings.debugConflictResolution()) { + Message.debug("checking if " + node.getId() + + " is transitively evicted in " + confs[i]); + } + boolean allEvicted = callers.length > 0; + for (int j = 0; j < callers.length; j++) { + if (callers[j].getModuleRevisionId().equals(md.getModuleRevisionId())) { + // the caller is the root module itself, it can't be evicted + allEvicted = false; + break; + } else { + IvyNode callerNode = data.getNode(callers[j].getModuleRevisionId()); + if (callerNode == null) { + Message.warn("ivy internal error: no node found for " + + callers[j].getModuleRevisionId() + ": looked in " + + data.getNodeIds() + " and root module id was " + + md.getModuleRevisionId()); + } else if (!callerNode.isEvicted(confs[i])) { + allEvicted = false; + break; + } else { + if (settings.debugConflictResolution()) { + Message.debug("caller " + callerNode.getId() + " of " + + node.getId() + " is evicted"); + } + } + } + } + if (allEvicted) { + Message.verbose("all callers are evicted for " + node + ": evicting too"); + node.markEvicted(confs[i], null, null, null); + } else { + if (settings.debugConflictResolution()) { + Message + .debug(node.getId() + + " isn't transitively evicted, at least one caller was not evicted"); + } + } + } + } + } + + return (IvyNode[]) dependencies.toArray(new IvyNode[dependencies.size()]); + } + + private void fetchDependencies(VisitNode node, String conf, boolean shouldBePublic) { + checkInterrupted(); + long start = System.currentTimeMillis(); + if (node.getParent() != null) { + Message.verbose("== resolving dependencies " + node.getParent().getId() + "->" + + node.getId() + " [" + node.getParentConf() + "->" + conf + "]"); + } else { + Message.verbose("== resolving dependencies for " + node.getId() + " [" + conf + "]"); + } + resolveConflict(node); + + if (node.loadData(conf, shouldBePublic)) { + resolveConflict(node); + if (!node.isEvicted()) { + String[] confs = node.getRealConfs(conf); + for (int i = 0; i < confs.length; i++) { + doFetchDependencies(node, confs[i]); + } + } + } else if (!node.hasProblem()) { + // the node has not been loaded but hasn't problem: it was already loaded + // => we just have to update its dependencies data + if (!node.isEvicted()) { + String[] confs = node.getRealConfs(conf); + for (int i = 0; i < confs.length; i++) { + doFetchDependencies(node, confs[i]); + } + } + } + if (node.isEvicted()) { + // update selected nodes with confs asked in evicted one + EvictionData ed = node.getEvictedData(); + if (ed.getSelected() != null) { + for (Iterator iter = ed.getSelected().iterator(); iter.hasNext();) { + IvyNode selected = (IvyNode) iter.next(); + if (!selected.isLoaded()) { + // the node is not yet loaded, we can simply update its set of + // configurations to fetch + selected.updateConfsToFetch(Collections.singleton(conf)); + } else { + // the node has already been loaded, we must fetch its dependencies in the + // required conf + fetchDependencies(node.gotoNode(selected), conf, true); + } + } + } + } + if (settings.debugConflictResolution()) { + Message.debug(node.getId() + " => dependencies resolved in " + conf + " (" + + (System.currentTimeMillis() - start) + "ms)"); + } + } + + private void doFetchDependencies(VisitNode node, String conf) { + Configuration c = node.getConfiguration(conf); + if (c == null) { + Message.warn("configuration not found '" + conf + "' in " + node.getResolvedId() + + ": ignoring"); + if (node.getParent() != null) { + Message.warn("it was required from " + node.getParent().getResolvedId()); + } + return; + } + // we handle the case where the asked configuration extends others: + // we have to first fetch the extended configurations + + // first we check if this is the actual requested conf (not an extended one) + boolean requestedConfSet = false; + if (node.getRequestedConf() == null) { + node.setRequestedConf(conf); + requestedConfSet = true; + } + // now let's recurse in extended confs + String[] extendedConfs = c.getExtends(); + if (extendedConfs.length > 0) { + node.updateConfsToFetch(Arrays.asList(extendedConfs)); + } + for (int i = 0; i < extendedConfs.length; i++) { + fetchDependencies(node, extendedConfs[i], false); + } + + // now we can actually resolve this configuration dependencies + DependencyDescriptor dd = node.getDependencyDescriptor(); + if (!isDependenciesFetched(node.getNode(), conf) && (dd == null || node.isTransitive())) { + Collection dependencies = node.getDependencies(conf); + for (Iterator iter = dependencies.iterator(); iter.hasNext();) { + VisitNode dep = (VisitNode) iter.next(); + dep.useRealNode(); // the node may have been resolved to another real one while + // resolving other deps + if (dep.isCircular()) { + continue; + } + String[] confs = dep.getRequiredConfigurations(node, conf); + for (int i = 0; i < confs.length; i++) { + fetchDependencies(dep, confs[i], true); + } + // if there are still confs to fetch (usually because they have + // been updated when evicting another module), we fetch them now + confs = dep.getConfsToFetch(); + for (int i = 0; i < confs.length; i++) { + fetchDependencies(dep, confs[i], true); + } + } + } + // we have finiched with this configuration, if it was the original requested conf + // we can clean it now + if (requestedConfSet) { + node.setRequestedConf(null); + } + + } + + /** + * Returns true if we've already fetched the dependencies for this node and configuration + * + * @param node + * node to check + * @param conf + * configuration to check + * @return true if we've already fetched this dependency + */ + private boolean isDependenciesFetched(IvyNode node, String conf) { + ModuleId moduleId = node.getModuleId(); + ModuleRevisionId moduleRevisionId = node.getResolvedId(); + String key = moduleId.getOrganisation() + "|" + moduleId.getName() + "|" + + moduleRevisionId.getRevision() + "|" + conf; + if (fetchedSet.contains(key)) { + return true; + } + fetchedSet.add(key); + return false; + } + + private void resolveConflict(VisitNode node) { + resolveConflict(node, node.getParent(), Collections.EMPTY_SET); + } + + /** + * Resolves conflict for the given node in the given ancestor. This method do conflict + * resolution in ancestor parents recursively, unless not necessary. + * + * @param node + * the node for which conflict resolution should be done + * @param ancestor + * the ancestor in which the conflict resolution should be done + * @param toevict + * a collection of IvyNode to evict (as computed by conflict resolution in + * descendants of ancestor) + * @return true if conflict resolution has been done, false it can't be done yet + */ + private boolean resolveConflict(VisitNode node, VisitNode ancestor, Collection toevict) { + if (ancestor == null || node == ancestor) { + return true; + } + // check if job is not already done + if (checkConflictSolvedEvicted(node, ancestor)) { + // job is done and node is evicted, nothing to do + return true; + } + if (checkConflictSolvedSelected(node, ancestor)) { + // job is done and node is selected, nothing to do for this ancestor, but we still have + // to check higher levels, for which conflict resolution might have been impossible + // before + if (resolveConflict(node, ancestor.getParent(), toevict)) { + // now that conflict resolution is ok in ancestors + // we just have to check if the node wasn't previously evicted in root ancestor + EvictionData evictionData = node.getEvictionDataInRoot(node.getRootModuleConf(), + ancestor); + if (evictionData != null) { + // node has been previously evicted in an ancestor: we mark it as evicted + if (settings.debugConflictResolution()) { + Message.debug(node + " was previously evicted in root module conf " + + node.getRootModuleConf()); + } + + node.markEvicted(evictionData); + if (settings.debugConflictResolution()) { + Message.debug("evicting " + node + " by " + evictionData); + } + } + return true; + } else { + return false; + } + } + + // compute conflicts + Collection resolvedNodes = new HashSet(ancestor.getNode().getResolvedNodes( + node.getModuleId(), node.getRootModuleConf())); + resolvedNodes.addAll(ancestor.getNode().getPendingConflicts(node.getRootModuleConf(), + node.getModuleId())); + Collection conflicts = computeConflicts(node, ancestor, toevict, resolvedNodes); + + if (settings.debugConflictResolution()) { + Message.debug("found conflicting revisions for " + node + " in " + ancestor + ": " + + conflicts); + } + + ConflictManager conflictManager = ancestor.getNode().getConflictManager(node.getModuleId()); + Collection resolved = conflictManager.resolveConflicts(ancestor.getNode(), conflicts); + + if (resolved == null) { + if (settings.debugConflictResolution()) { + Message.debug("impossible to resolve conflicts for " + node + " in " + ancestor + + " yet"); + Message + .debug("setting all nodes as pending conflicts for later conflict resolution: " + + conflicts); + } + ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), + conflicts); + return false; + } + + if (settings.debugConflictResolution()) { + Message.debug("selected revisions for " + node + " in " + ancestor + ": " + resolved); + } + if (resolved.contains(node.getNode())) { + // node has been selected for the current parent + + // handle previously selected nodes that are now evicted by this new node + toevict = resolvedNodes; + toevict.removeAll(resolved); + + for (Iterator iter = toevict.iterator(); iter.hasNext();) { + IvyNode te = (IvyNode) iter.next(); + te.markEvicted(node.getRootModuleConf(), ancestor.getNode(), conflictManager, + resolved); + + if (settings.debugConflictResolution()) { + Message.debug("evicting " + te + " by " + + te.getEvictedData(node.getRootModuleConf())); + } + } + + // it's very important to update resolved and evicted nodes BEFORE recompute parent call + // to allow it to recompute its resolved collection with correct data + // if necessary + ancestor.getNode().setResolvedNodes(node.getModuleId(), node.getRootModuleConf(), + resolved); + + Collection evicted = new HashSet(ancestor.getNode().getEvictedNodes(node.getModuleId(), + node.getRootModuleConf())); + evicted.removeAll(resolved); + evicted.addAll(toevict); + ancestor.getNode().setEvictedNodes(node.getModuleId(), node.getRootModuleConf(), + evicted); + ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), + Collections.EMPTY_SET); + + return resolveConflict(node, ancestor.getParent(), toevict); + } else { + // node has been evicted for the current parent + if (resolved.isEmpty()) { + if (settings.debugConflictResolution()) { + Message.verbose("conflict manager '" + conflictManager + + "' evicted all revisions among " + conflicts); + } + } + + // it's time to update parent resolved and evicted with what was found + + Collection evicted = new HashSet(ancestor.getNode().getEvictedNodes(node.getModuleId(), + node.getRootModuleConf())); + toevict.removeAll(resolved); + evicted.removeAll(resolved); + evicted.addAll(toevict); + evicted.add(node.getNode()); + ancestor.getNode().setEvictedNodes(node.getModuleId(), node.getRootModuleConf(), + evicted); + ancestor.getNode().setPendingConflicts(node.getModuleId(), node.getRootModuleConf(), + Collections.EMPTY_SET); + + node.markEvicted(ancestor, conflictManager, resolved); + if (settings.debugConflictResolution()) { + Message.debug("evicting " + node + " by " + node.getEvictedData()); + } + + // if resolved changed we have to go up in the graph + Collection prevResolved = ancestor.getNode().getResolvedNodes(node.getModuleId(), + node.getRootModuleConf()); + boolean solved = true; + if (!prevResolved.equals(resolved)) { + ancestor.getNode().setResolvedNodes(node.getModuleId(), node.getRootModuleConf(), + resolved); + for (Iterator iter = resolved.iterator(); iter.hasNext();) { + IvyNode sel = (IvyNode) iter.next(); + if (!prevResolved.contains(sel)) { + solved &= resolveConflict(node.gotoNode(sel), ancestor.getParent(), toevict); + } + } + } + return solved; + } + } + + private Collection computeConflicts(VisitNode node, VisitNode ancestor, Collection toevict, + Collection resolvedNodes) { + Collection conflicts = new HashSet(); + conflicts.add(node.getNode()); + if (resolvedNodes.removeAll(toevict)) { + // parent.resolved(node.mid) is not up to date: + // recompute resolved from all sub nodes + Collection deps = ancestor.getNode().getDependencies(node.getRootModuleConf(), + ancestor.getRequiredConfigurations()); + for (Iterator iter = deps.iterator(); iter.hasNext();) { + IvyNode dep = (IvyNode) iter.next(); + if (dep.getModuleId().equals(node.getModuleId())) { + conflicts.add(dep); + } + conflicts + .addAll(dep.getResolvedNodes(node.getModuleId(), node.getRootModuleConf())); + } + } else if (resolvedNodes.isEmpty() && node.getParent() != ancestor) { + DependencyDescriptor[] dds = ancestor.getDescriptor().getDependencies(); + for (int i = 0; i < dds.length; i++) { + if (dds[i].getDependencyId().equals(node.getModuleId())) { + IvyNode n = node.getNode().findNode(dds[i].getDependencyRevisionId()); + if (n != null) { + conflicts.add(n); + break; + } + } + } + } else { + conflicts.addAll(resolvedNodes); + } + return conflicts; + } + + private boolean checkConflictSolvedSelected(VisitNode node, VisitNode ancestor) { + if (ancestor.getResolvedRevisions(node.getModuleId()).contains(node.getResolvedId())) { + // resolve conflict has already be done with node with the same id + if (settings.debugConflictResolution()) { + Message.debug("conflict resolution already done for " + node + " in " + ancestor); + } + return true; + } + return false; + } + + private boolean checkConflictSolvedEvicted(VisitNode node, VisitNode ancestor) { + if (ancestor.getEvictedRevisions(node.getModuleId()).contains(node.getResolvedId())) { + // resolve conflict has already be done with node with the same id + if (settings.debugConflictResolution()) { + Message.debug("conflict resolution already done for " + node + " in " + ancestor); + } + return true; + } + return false; + } + + public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options) { + DependencyResolver r = settings.getResolver(id.getModuleId()); + if (r == null) { + throw new IllegalStateException("no resolver found for " + id.getModuleId()); + } + DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(id, + new String[] {"*"}, false, false); + + if (options.getResolveId() == null) { + options.setResolveId(ResolveOptions.getDefaultResolveId(md)); + } + + try { + return r.getDependency(new DefaultDependencyDescriptor(id, true), new ResolveData(this, + options, new ConfigurationResolveReport(this, md, "default", null, options))); + } catch (ParseException e) { + throw new RuntimeException("problem while parsing repository module descriptor for " + + id + ": " + e, e); + } + } + + public EventManager getEventManager() { + return eventManager; + } + + public IvySettings getSettings() { + return settings; + } + + public SortEngine getSortEngine() { + return sortEngine; + } + + private void checkInterrupted() { + IvyContext.getContext().getIvy().checkInterrupted(); + } + +} diff --git a/src/java/org/apache/ivy/core/resolve/ResolveOptions.java b/src/java/org/apache/ivy/core/resolve/ResolveOptions.java index b7d9cc19..d8f611e2 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolveOptions.java +++ b/src/java/org/apache/ivy/core/resolve/ResolveOptions.java @@ -1,238 +1,238 @@ -/* - * 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.core.resolve; - -import java.util.Date; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.util.filter.Filter; -import org.apache.ivy.util.filter.FilterHelper; - -/** - * A set of options used during resolve related tasks - * - * @see ResolveEngine - */ -public class ResolveOptions { - /** - * an array of configuration names to resolve - must not be null nor empty - */ - private String[] confs = new String[] {"*"}; - - /** - * the revision of the module for which dependencies should be resolved. This revision is - * considered as the resolved revision of the module, unless it is null. If it is null, then a - * default revision is given if necessary (no revision found in ivy file) - */ - private String revision = null; - - /** - * The cache manager to use during resolve. If it is null, default cache manager will be used. - */ - private CacheManager cache = null; - - /** - * the date for which the dependencies should be resolved. All obtained artifacts should have a - * publication date which is before or equal to the given date. The date can be null, in which - * case all artifacts will be considered - */ - private Date date = null; - - /** - * True if validation of module descriptors should done, false otherwise - */ - private boolean validate = true; - - /** - * True if only the cache should be used for resolve, false if a real resolve with dependency - * resolvers should be done - */ - private boolean useCacheOnly = false; - - /** - * True if the dependencies should be resolved transitively, false if only direct dependencies - * should be resolved - */ - private boolean transitive = true; - - /** - * True if the resolve should also download artifacts, false if only dependency resolution with - * module descriptors should be done - */ - private boolean download = true; - - /** - * True if a report of the resolve process should be output at the end of the process, false - * otherwise - */ - private boolean outputReport = true; - - /** - * True if the original files from the repositories should be used instead of downloaded ones, - * false otherwise. This means that artifacts which can be used directory in their original - * location won't be downloaded if this option is set to true - */ - private boolean useOrigin = false; - - /** - * A filter to use to avoid downloading all artifacts. - */ - private Filter artifactFilter = FilterHelper.NO_FILTER; - - /** - * The id used to store the resolve information. - */ - private String resolveId; - - public ResolveOptions() { - } - - public ResolveOptions(ResolveOptions options) { - confs = options.confs; - revision = options.revision; - cache = options.cache; - date = options.date; - validate = options.validate; - useCacheOnly = options.useCacheOnly; - transitive = options.transitive; - download = options.download; - outputReport = options.outputReport; - useOrigin = options.useOrigin; - artifactFilter = options.artifactFilter; - resolveId = options.resolveId; - } - - public Filter getArtifactFilter() { - return artifactFilter; - } - - public ResolveOptions setArtifactFilter(Filter artifactFilter) { - this.artifactFilter = artifactFilter; - return this; - } - - public CacheManager getCache() { - return cache; - } - - public ResolveOptions setCache(CacheManager cache) { - this.cache = cache; - return this; - } - - public String[] getConfs() { - return confs; - } - - public ResolveOptions setConfs(String[] confs) { - this.confs = confs; - return this; - } - - public Date getDate() { - return date; - } - - public ResolveOptions setDate(Date date) { - this.date = date; - return this; - } - - public boolean isDownload() { - return download; - } - - public ResolveOptions setDownload(boolean download) { - this.download = download; - return this; - } - - public boolean isOutputReport() { - return outputReport; - } - - public ResolveOptions setOutputReport(boolean outputReport) { - this.outputReport = outputReport; - return this; - } - - public boolean isTransitive() { - return transitive; - } - - public ResolveOptions setTransitive(boolean transitive) { - this.transitive = transitive; - return this; - } - - public boolean isUseCacheOnly() { - return useCacheOnly; - } - - public ResolveOptions setUseCacheOnly(boolean useCacheOnly) { - this.useCacheOnly = useCacheOnly; - return this; - } - - public boolean isValidate() { - return validate; - } - - public ResolveOptions setValidate(boolean validate) { - this.validate = validate; - return this; - } - - public String getRevision() { - return revision; - } - - public ResolveOptions setRevision(String revision) { - this.revision = revision; - return this; - } - - public boolean isUseOrigin() { - return useOrigin; - } - - public ResolveOptions setUseOrigin(boolean useOrigin) { - this.useOrigin = useOrigin; - return this; - } - - public String getResolveId() { - return resolveId; - } - - public ResolveOptions setResolveId(String resolveId) { - this.resolveId = resolveId; - return this; - } - - public static String getDefaultResolveId(ModuleDescriptor md) { - ModuleId module = md.getModuleRevisionId().getModuleId(); - return getDefaultResolveId(module); - } - - public static String getDefaultResolveId(ModuleId moduleId) { - return moduleId.getOrganisation() + "-" + moduleId.getName(); - } -} +/* + * 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.core.resolve; + +import java.util.Date; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.util.filter.Filter; +import org.apache.ivy.util.filter.FilterHelper; + +/** + * A set of options used during resolve related tasks + * + * @see ResolveEngine + */ +public class ResolveOptions { + /** + * an array of configuration names to resolve - must not be null nor empty + */ + private String[] confs = new String[] {"*"}; + + /** + * the revision of the module for which dependencies should be resolved. This revision is + * considered as the resolved revision of the module, unless it is null. If it is null, then a + * default revision is given if necessary (no revision found in ivy file) + */ + private String revision = null; + + /** + * The cache manager to use during resolve. If it is null, default cache manager will be used. + */ + private CacheManager cache = null; + + /** + * the date for which the dependencies should be resolved. All obtained artifacts should have a + * publication date which is before or equal to the given date. The date can be null, in which + * case all artifacts will be considered + */ + private Date date = null; + + /** + * True if validation of module descriptors should done, false otherwise + */ + private boolean validate = true; + + /** + * True if only the cache should be used for resolve, false if a real resolve with dependency + * resolvers should be done + */ + private boolean useCacheOnly = false; + + /** + * True if the dependencies should be resolved transitively, false if only direct dependencies + * should be resolved + */ + private boolean transitive = true; + + /** + * True if the resolve should also download artifacts, false if only dependency resolution with + * module descriptors should be done + */ + private boolean download = true; + + /** + * True if a report of the resolve process should be output at the end of the process, false + * otherwise + */ + private boolean outputReport = true; + + /** + * True if the original files from the repositories should be used instead of downloaded ones, + * false otherwise. This means that artifacts which can be used directory in their original + * location won't be downloaded if this option is set to true + */ + private boolean useOrigin = false; + + /** + * A filter to use to avoid downloading all artifacts. + */ + private Filter artifactFilter = FilterHelper.NO_FILTER; + + /** + * The id used to store the resolve information. + */ + private String resolveId; + + public ResolveOptions() { + } + + public ResolveOptions(ResolveOptions options) { + confs = options.confs; + revision = options.revision; + cache = options.cache; + date = options.date; + validate = options.validate; + useCacheOnly = options.useCacheOnly; + transitive = options.transitive; + download = options.download; + outputReport = options.outputReport; + useOrigin = options.useOrigin; + artifactFilter = options.artifactFilter; + resolveId = options.resolveId; + } + + public Filter getArtifactFilter() { + return artifactFilter; + } + + public ResolveOptions setArtifactFilter(Filter artifactFilter) { + this.artifactFilter = artifactFilter; + return this; + } + + public CacheManager getCache() { + return cache; + } + + public ResolveOptions setCache(CacheManager cache) { + this.cache = cache; + return this; + } + + public String[] getConfs() { + return confs; + } + + public ResolveOptions setConfs(String[] confs) { + this.confs = confs; + return this; + } + + public Date getDate() { + return date; + } + + public ResolveOptions setDate(Date date) { + this.date = date; + return this; + } + + public boolean isDownload() { + return download; + } + + public ResolveOptions setDownload(boolean download) { + this.download = download; + return this; + } + + public boolean isOutputReport() { + return outputReport; + } + + public ResolveOptions setOutputReport(boolean outputReport) { + this.outputReport = outputReport; + return this; + } + + public boolean isTransitive() { + return transitive; + } + + public ResolveOptions setTransitive(boolean transitive) { + this.transitive = transitive; + return this; + } + + public boolean isUseCacheOnly() { + return useCacheOnly; + } + + public ResolveOptions setUseCacheOnly(boolean useCacheOnly) { + this.useCacheOnly = useCacheOnly; + return this; + } + + public boolean isValidate() { + return validate; + } + + public ResolveOptions setValidate(boolean validate) { + this.validate = validate; + return this; + } + + public String getRevision() { + return revision; + } + + public ResolveOptions setRevision(String revision) { + this.revision = revision; + return this; + } + + public boolean isUseOrigin() { + return useOrigin; + } + + public ResolveOptions setUseOrigin(boolean useOrigin) { + this.useOrigin = useOrigin; + return this; + } + + public String getResolveId() { + return resolveId; + } + + public ResolveOptions setResolveId(String resolveId) { + this.resolveId = resolveId; + return this; + } + + public static String getDefaultResolveId(ModuleDescriptor md) { + ModuleId module = md.getModuleRevisionId().getModuleId(); + return getDefaultResolveId(module); + } + + public static String getDefaultResolveId(ModuleId moduleId) { + return moduleId.getOrganisation() + "-" + moduleId.getName(); + } +} diff --git a/src/java/org/apache/ivy/core/resolve/ResolvedModuleRevision.java b/src/java/org/apache/ivy/core/resolve/ResolvedModuleRevision.java index ae6347f0..f396f523 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolvedModuleRevision.java +++ b/src/java/org/apache/ivy/core/resolve/ResolvedModuleRevision.java @@ -1,56 +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. - * - */ -package org.apache.ivy.core.resolve; - -import java.net.URL; -import java.util.Date; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -/** - * - */ -public interface ResolvedModuleRevision { - /** - * The resolver which resolved this ResolvedModuleRevision - * - * @return The resolver which resolved this ResolvedModuleRevision - */ - DependencyResolver getResolver(); - - /** - * The resolver to use to download artifacts - * - * @return The resolver to use to download artifacts - */ - DependencyResolver getArtifactResolver(); - - ModuleRevisionId getId(); - - Date getPublicationDate(); - - ModuleDescriptor getDescriptor(); - - boolean isDownloaded(); - - boolean isSearched(); - - public URL getLocalMDUrl(); -} +/* + * 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.core.resolve; + +import java.net.URL; +import java.util.Date; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +/** + * + */ +public interface ResolvedModuleRevision { + /** + * The resolver which resolved this ResolvedModuleRevision + * + * @return The resolver which resolved this ResolvedModuleRevision + */ + DependencyResolver getResolver(); + + /** + * The resolver to use to download artifacts + * + * @return The resolver to use to download artifacts + */ + DependencyResolver getArtifactResolver(); + + ModuleRevisionId getId(); + + Date getPublicationDate(); + + ModuleDescriptor getDescriptor(); + + boolean isDownloaded(); + + boolean isSearched(); + + public URL getLocalMDUrl(); +} diff --git a/src/java/org/apache/ivy/core/resolve/VisitData.java b/src/java/org/apache/ivy/core/resolve/VisitData.java index f78cc430..16a10ab5 100644 --- a/src/java/org/apache/ivy/core/resolve/VisitData.java +++ b/src/java/org/apache/ivy/core/resolve/VisitData.java @@ -1,72 +1,72 @@ -/* - * 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.core.resolve; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * This class is used to store data related to one node of the dependency graph visit. It stores - * both an {@link IvyNode} and related {@link VisitNode} objects. Indeed, during the visit of the - * graph, the algorithm can visit the same node from several parents, thus requiring several - * VisitNode. - */ -public class VisitData { - /** - * A node in the graph of module dependencies resolution - */ - private IvyNode node; - - /** - * The associated visit nodes, per rootModuleConf Note that the value is a List, because a node - * can be visited from several parents during the resolution process - */ - private Map visitNodes = new HashMap(); // Map (String rootModuleConf -> List(VisitNode)) - - public VisitData(IvyNode node) { - this.node = node; - } - - public void addVisitNode(VisitNode node) { - String rootModuleConf = node.getRootModuleConf(); - getVisitNodes(rootModuleConf).add(node); - } - - public List getVisitNodes(String rootModuleConf) { - List visits = (List) visitNodes.get(rootModuleConf); - if (visits == null) { - visits = new ArrayList(); - visitNodes.put(rootModuleConf, visits); - } - return visits; - } - - public IvyNode getNode() { - return node; - } - - public void setNode(IvyNode node) { - this.node = node; - } - - public void addVisitNodes(String rootModuleConf, List visitNodes) { - getVisitNodes(rootModuleConf).addAll(visitNodes); - } -} +/* + * 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.core.resolve; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This class is used to store data related to one node of the dependency graph visit. It stores + * both an {@link IvyNode} and related {@link VisitNode} objects. Indeed, during the visit of the + * graph, the algorithm can visit the same node from several parents, thus requiring several + * VisitNode. + */ +public class VisitData { + /** + * A node in the graph of module dependencies resolution + */ + private IvyNode node; + + /** + * The associated visit nodes, per rootModuleConf Note that the value is a List, because a node + * can be visited from several parents during the resolution process + */ + private Map visitNodes = new HashMap(); // Map (String rootModuleConf -> List(VisitNode)) + + public VisitData(IvyNode node) { + this.node = node; + } + + public void addVisitNode(VisitNode node) { + String rootModuleConf = node.getRootModuleConf(); + getVisitNodes(rootModuleConf).add(node); + } + + public List getVisitNodes(String rootModuleConf) { + List visits = (List) visitNodes.get(rootModuleConf); + if (visits == null) { + visits = new ArrayList(); + visitNodes.put(rootModuleConf, visits); + } + return visits; + } + + public IvyNode getNode() { + return node; + } + + public void setNode(IvyNode node) { + this.node = node; + } + + public void addVisitNodes(String rootModuleConf, List visitNodes) { + getVisitNodes(rootModuleConf).addAll(visitNodes); + } +} diff --git a/src/java/org/apache/ivy/core/resolve/VisitNode.java b/src/java/org/apache/ivy/core/resolve/VisitNode.java index 034dadd7..90251d5e 100644 --- a/src/java/org/apache/ivy/core/resolve/VisitNode.java +++ b/src/java/org/apache/ivy/core/resolve/VisitNode.java @@ -1,483 +1,483 @@ -/* - * 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.core.resolve; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; -import org.apache.ivy.plugins.conflict.ConflictManager; - -/** - * A visit node is an object used to represent one visit from one parent on an {@link IvyNode} of - * the dependency graph. During dependency resolution, the {@link ResolveEngine} visits nodes of the - * depency graph following the dependencies, thus the same node can be visited several times, if it - * is requested from several module. In this case you will have one VisitNode per parent and per - * root module configuration. Thus VisitNode stores data specific to the visit: - *

        - *
      • parent
      • - * the node from which the visit is occuring - *
      • parentConf
      • - * the configuration of the parent in which this node is visited - *
      • rootModuleConf
      • - * the configuration of the root module which is currently resolved - *
      - */ -public class VisitNode { - /** - * The node which is currently visited - */ - private IvyNode node; - - /** - * Represents the current parent of the node during ivy visit of dependency graph. - */ - private VisitNode parent = null; - - /** - * The root node of the current visit It is null until it is required, see getRoot - */ - private VisitNode root = null; - - /** - * Direct path from root to this node. Note that the colleciton is ordered but is not a list - * implementation This collection is null until it is required, see getPath - */ - private Collection path = null; // Collection(VisitNode) - - /** - * The configuration of the parent module in the current visit - */ - private String parentConf = null; - - /** - * The configuration requested by the parent Note that this is the actual conf requested by the - * parent, not a configuration extended by the requested conf which actually trigger the node - * visit - */ - private String requestedConf; - - /** - * The root configuration which is currently visited - */ - private String rootModuleConf; - - /** - * Shared ResolveData instance, which can be used to get info on the current resolve process - */ - private ResolveData data; - - /** - * Boolean.TRUE if a node with a same module id as the one visited has already been visited in - * the current path. null if not computed yet Boolean.FALSE otherwise - */ - private Boolean isCircular; - - public VisitNode(ResolveData data, IvyNode node, VisitNode parent, String rootModuleConf, - String parentConf) { - if (data == null) { - throw new NullPointerException("data must not be null"); - } - if (node == null) { - throw new NullPointerException("node must not be null"); - } - if (rootModuleConf == null) { - throw new NullPointerException("rootModuleConf must not be null"); - } - this.data = data; - this.node = node; - this.parent = parent; - this.rootModuleConf = rootModuleConf; - this.parentConf = parentConf; - - // we do not register if this is a root module (root == no parent) - init(data, this.parent != null); - } - - private void init(ResolveData data, boolean register) { - this.data = data; - if (register) { - this.data.register(this); - } - } - - public IvyNode getNode() { - return node; - } - - /** - * @return Returns the configuration requested by the parent - */ - public String getRequestedConf() { - return requestedConf; - } - - public void setRequestedConf(String requestedConf) { - this.requestedConf = requestedConf; - } - - public VisitNode getParent() { - return parent; - } - - public VisitNode getRoot() { - if (root == null) { - root = computeRoot(); - } - return root; - } - - public Collection getPath() { - if (path == null) { - path = computePath(); - } - return path; - } - - private Collection computePath() { - if (parent != null) { - Collection p = new LinkedHashSet(parent.getPath()); - p.add(this); - return p; - } else { - return Collections.singletonList(this); - } - } - - private VisitNode computeRoot() { - if (node.isRoot()) { - return this; - } else if (parent != null) { - return parent.getRoot(); - } else { - return null; - } - } - - public String getParentConf() { - return parentConf; - } - - public void setParentConf(String parentConf) { - this.parentConf = parentConf; - } - - public String getRootModuleConf() { - return rootModuleConf; - } - - public static VisitNode getRoot(VisitNode parent) { - VisitNode root = parent; - Collection path = new HashSet(); - path.add(root); - while (root.getParent() != null && !root.getNode().isRoot()) { - if (path.contains(root.getParent())) { - return root; - } - root = root.getParent(); - path.add(root); - } - return root; - } - - /** - * Returns true if the current dependency descriptor is transitive and the parent configuration - * is transitive. Otherwise returns false. - * - * @param node - * curent node - * @return true if current node is transitive and the parent configuration is transitive. - */ - public boolean isTransitive() { - return (data.isTransitive() && node.getDependencyDescriptor(getParentNode()).isTransitive() && isParentConfTransitive()); - } - - /** - * Checks if the current node's parent configuration is transitive. - * - * @param node - * current node - * @return true if the node's parent configuration is transitive - */ - protected boolean isParentConfTransitive() { - String conf = getParent().getRequestedConf(); - if (conf == null) { - return true; - } - Configuration parentConf = getParentNode().getConfiguration(conf); - return parentConf.isTransitive(); - - } - - /** - * Returns the 'real' node currently visited. 'Real' means that if we are visiting a node - * created originally with only a version constraint, and if this version constraint has been - * resolved to an existing node in the graph, we will return the existing node, and not the one - * originally used which is about to be discarded, since it's not possible to have in the graph - * two nodes for the same ModuleRevisionId - * - * @return the 'real' node currently visited. - */ - public IvyNode getRealNode() { - IvyNode node = this.node.getRealNode(); - if (node != null) { - return node; - } else { - return this.node; - } - } - - /** - * Ask to the current visited node to use a real node only, if one exist. See getRealNode for - * details about what a 'real' node is. - */ - public void useRealNode() { - if (parent != null) { // use real node make sense only for non root module - IvyNode node = data.getNode(this.node.getId()); - if (node != null && node != this.node) { - this.node = node; - } - } - } - - public boolean loadData(String conf, boolean shouldBePublic) { - boolean loaded = node.loadData(rootModuleConf, getParentNode(), parentConf, conf, - shouldBePublic); - if (loaded) { - useRealNode(); - - // if the revision was a dynamic one (which has now be resolved) - // we now register this node on the resolved id - if (data.getSettings().getVersionMatcher().isDynamic(getId())) { - data.register(node.getResolvedId(), this); - } - } - - return loaded; - } - - public Collection getDependencies(String conf) { - Collection deps = node.getDependencies(rootModuleConf, conf, requestedConf); - Collection ret = new ArrayList(deps.size()); - for (Iterator iter = deps.iterator(); iter.hasNext();) { - IvyNode depNode = (IvyNode) iter.next(); - ret.add(traverseChild(conf, depNode)); - } - return ret; - } - - /** - * Returns a VisitNode for the given node. The given node must be a representation of the same - * module (usually in another revision) as the one visited by this node. The given node must - * also have been already visited. - * - * @param node - * the node to visit - * @return a VisitNode for the given node - */ - VisitNode gotoNode(IvyNode node) { - if (!getModuleId().equals(node.getModuleId())) { - throw new IllegalArgumentException( - "you can't use gotoNode for a node which does not represent the same Module as the one represented by this node.\nCurrent node module id=" - + getModuleId() + " Given node module id=" + node.getModuleId()); - } - VisitData visitData = data.getVisitData(node.getId()); - if (visitData == null) { - throw new IllegalArgumentException( - "you can't use gotoNode with a node which has not been visited yet.\nGiven node id=" - + node.getId()); - } - for (Iterator iter = visitData.getVisitNodes(rootModuleConf).iterator(); iter.hasNext();) { - VisitNode vnode = (VisitNode) iter.next(); - if ((parent == null && vnode.getParent() == null) - || (parent != null && parent.getId().equals(vnode.getParent().getId()))) { - return vnode; - } - } - // the node has not yet been visited from the current parent, we create a new visit node - return traverse(parent, parentConf, node); - } - - private VisitNode traverseChild(String parentConf, IvyNode child) { - VisitNode parent = this; - return traverse(parent, parentConf, child); - } - - private VisitNode traverse(VisitNode parent, String parentConf, IvyNode node) { - if (getPath().contains(node)) { - IvyContext.getContext().getCircularDependencyStrategy().handleCircularDependency( - toMrids(getPath(), node.getId())); - // we do not use the new parent, but the first one, to always be able to go up to the - // root - // parent = getVisitNode(depNode).getParent(); - } - return new VisitNode(data, node, parent, rootModuleConf, parentConf); - } - - private ModuleRevisionId[] toMrids(Collection path, ModuleRevisionId last) { - ModuleRevisionId[] ret = new ModuleRevisionId[path.size() + 1]; - int i = 0; - for (Iterator iter = path.iterator(); iter.hasNext(); i++) { - VisitNode node = (VisitNode) iter.next(); - ret[i] = node.getNode().getId(); - } - ret[ret.length - 1] = last; - return ret; - } - - public ModuleRevisionId getResolvedId() { - return node.getResolvedId(); - } - - public void updateConfsToFetch(Collection confs) { - node.updateConfsToFetch(confs); - } - - public ModuleRevisionId getId() { - return node.getId(); - } - - public boolean isEvicted() { - return node.isEvicted(rootModuleConf); - } - - public String[] getRealConfs(String conf) { - return node.getRealConfs(conf); - } - - public boolean hasProblem() { - return node.hasProblem(); - } - - public Configuration getConfiguration(String conf) { - return node.getConfiguration(conf); - } - - public EvictionData getEvictedData() { - return node.getEvictedData(rootModuleConf); - } - - public DependencyDescriptor getDependencyDescriptor() { - return node.getDependencyDescriptor(getParentNode()); - } - - private IvyNode getParentNode() { - return parent == null ? null : parent.getNode(); - } - - /** - * Returns true if this node can already be found in the path - * - * @return - */ - public boolean isCircular() { - if (isCircular == null) { - if (parent != null) { - isCircular = Boolean.FALSE; // asumme it's false, and see if it isn't by checking - // the parent path - for (Iterator iter = parent.getPath().iterator(); iter.hasNext();) { - VisitNode ancestor = (VisitNode) iter.next(); - if (getId().getModuleId().equals(ancestor.getId().getModuleId())) { - isCircular = Boolean.TRUE; - break; - } - } - } else { - isCircular = Boolean.FALSE; - } - } - return isCircular.booleanValue(); - } - - public String[] getConfsToFetch() { - return node.getConfsToFetch(); - } - - public String[] getRequiredConfigurations(VisitNode in, String inConf) { - return node.getRequiredConfigurations(in.getNode(), inConf); - } - - public ModuleId getModuleId() { - return node.getModuleId(); - } - - public Collection getResolvedRevisions(ModuleId mid) { - return node.getResolvedRevisions(mid, rootModuleConf); - } - - public void markEvicted(EvictionData evictionData) { - node.markEvicted(evictionData); - } - - public String[] getRequiredConfigurations() { - return node.getRequiredConfigurations(); - } - - /** - * Marks the current node as evicted by the the given selected IvyNodes, in the given parent and - * root module configuration, with the given {@link ConflictManager} - * - * @param parent - * the VisitNode in which eviction has been made - * @param conflictManager - * the conflict manager responsible for the eviction - * @param selected - * a Collection of {@link IvyNode} which have been selected - */ - public void markEvicted(VisitNode parent, ConflictManager conflictManager, Collection selected) { - node.markEvicted(rootModuleConf, parent.getNode(), conflictManager, selected); - } - - public ModuleDescriptor getDescriptor() { - return node.getDescriptor(); - } - - public EvictionData getEvictionDataInRoot(String rootModuleConf, VisitNode ancestor) { - return node.getEvictionDataInRoot(rootModuleConf, ancestor.getNode()); - } - - public Collection getEvictedRevisions(ModuleId moduleId) { - return node.getEvictedRevisions(moduleId, rootModuleConf); - } - - // public void setRootModuleConf(String rootModuleConf) { - // if (rootModuleConf != null && !rootModuleConf.equals(rootModuleConf)) { - // _confsToFetch.clear(); // we change of root module conf => we discard all confs to fetch - // } - // if (rootModuleConf != null && rootModuleConf.equals(rootModuleConf)) { - // _selectedDeps.put(new ModuleIdConf(_id.getModuleId(), rootModuleConf), - // Collections.singleton(this)); - // } - // rootModuleConf = rootModuleConf; - // } - - public String toString() { - return node.toString(); - } - -} +/* + * 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.core.resolve; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; +import org.apache.ivy.plugins.conflict.ConflictManager; + +/** + * A visit node is an object used to represent one visit from one parent on an {@link IvyNode} of + * the dependency graph. During dependency resolution, the {@link ResolveEngine} visits nodes of the + * depency graph following the dependencies, thus the same node can be visited several times, if it + * is requested from several module. In this case you will have one VisitNode per parent and per + * root module configuration. Thus VisitNode stores data specific to the visit: + *
        + *
      • parent
      • + * the node from which the visit is occuring + *
      • parentConf
      • + * the configuration of the parent in which this node is visited + *
      • rootModuleConf
      • + * the configuration of the root module which is currently resolved + *
      + */ +public class VisitNode { + /** + * The node which is currently visited + */ + private IvyNode node; + + /** + * Represents the current parent of the node during ivy visit of dependency graph. + */ + private VisitNode parent = null; + + /** + * The root node of the current visit It is null until it is required, see getRoot + */ + private VisitNode root = null; + + /** + * Direct path from root to this node. Note that the colleciton is ordered but is not a list + * implementation This collection is null until it is required, see getPath + */ + private Collection path = null; // Collection(VisitNode) + + /** + * The configuration of the parent module in the current visit + */ + private String parentConf = null; + + /** + * The configuration requested by the parent Note that this is the actual conf requested by the + * parent, not a configuration extended by the requested conf which actually trigger the node + * visit + */ + private String requestedConf; + + /** + * The root configuration which is currently visited + */ + private String rootModuleConf; + + /** + * Shared ResolveData instance, which can be used to get info on the current resolve process + */ + private ResolveData data; + + /** + * Boolean.TRUE if a node with a same module id as the one visited has already been visited in + * the current path. null if not computed yet Boolean.FALSE otherwise + */ + private Boolean isCircular; + + public VisitNode(ResolveData data, IvyNode node, VisitNode parent, String rootModuleConf, + String parentConf) { + if (data == null) { + throw new NullPointerException("data must not be null"); + } + if (node == null) { + throw new NullPointerException("node must not be null"); + } + if (rootModuleConf == null) { + throw new NullPointerException("rootModuleConf must not be null"); + } + this.data = data; + this.node = node; + this.parent = parent; + this.rootModuleConf = rootModuleConf; + this.parentConf = parentConf; + + // we do not register if this is a root module (root == no parent) + init(data, this.parent != null); + } + + private void init(ResolveData data, boolean register) { + this.data = data; + if (register) { + this.data.register(this); + } + } + + public IvyNode getNode() { + return node; + } + + /** + * @return Returns the configuration requested by the parent + */ + public String getRequestedConf() { + return requestedConf; + } + + public void setRequestedConf(String requestedConf) { + this.requestedConf = requestedConf; + } + + public VisitNode getParent() { + return parent; + } + + public VisitNode getRoot() { + if (root == null) { + root = computeRoot(); + } + return root; + } + + public Collection getPath() { + if (path == null) { + path = computePath(); + } + return path; + } + + private Collection computePath() { + if (parent != null) { + Collection p = new LinkedHashSet(parent.getPath()); + p.add(this); + return p; + } else { + return Collections.singletonList(this); + } + } + + private VisitNode computeRoot() { + if (node.isRoot()) { + return this; + } else if (parent != null) { + return parent.getRoot(); + } else { + return null; + } + } + + public String getParentConf() { + return parentConf; + } + + public void setParentConf(String parentConf) { + this.parentConf = parentConf; + } + + public String getRootModuleConf() { + return rootModuleConf; + } + + public static VisitNode getRoot(VisitNode parent) { + VisitNode root = parent; + Collection path = new HashSet(); + path.add(root); + while (root.getParent() != null && !root.getNode().isRoot()) { + if (path.contains(root.getParent())) { + return root; + } + root = root.getParent(); + path.add(root); + } + return root; + } + + /** + * Returns true if the current dependency descriptor is transitive and the parent configuration + * is transitive. Otherwise returns false. + * + * @param node + * curent node + * @return true if current node is transitive and the parent configuration is transitive. + */ + public boolean isTransitive() { + return (data.isTransitive() && node.getDependencyDescriptor(getParentNode()).isTransitive() && isParentConfTransitive()); + } + + /** + * Checks if the current node's parent configuration is transitive. + * + * @param node + * current node + * @return true if the node's parent configuration is transitive + */ + protected boolean isParentConfTransitive() { + String conf = getParent().getRequestedConf(); + if (conf == null) { + return true; + } + Configuration parentConf = getParentNode().getConfiguration(conf); + return parentConf.isTransitive(); + + } + + /** + * Returns the 'real' node currently visited. 'Real' means that if we are visiting a node + * created originally with only a version constraint, and if this version constraint has been + * resolved to an existing node in the graph, we will return the existing node, and not the one + * originally used which is about to be discarded, since it's not possible to have in the graph + * two nodes for the same ModuleRevisionId + * + * @return the 'real' node currently visited. + */ + public IvyNode getRealNode() { + IvyNode node = this.node.getRealNode(); + if (node != null) { + return node; + } else { + return this.node; + } + } + + /** + * Ask to the current visited node to use a real node only, if one exist. See getRealNode for + * details about what a 'real' node is. + */ + public void useRealNode() { + if (parent != null) { // use real node make sense only for non root module + IvyNode node = data.getNode(this.node.getId()); + if (node != null && node != this.node) { + this.node = node; + } + } + } + + public boolean loadData(String conf, boolean shouldBePublic) { + boolean loaded = node.loadData(rootModuleConf, getParentNode(), parentConf, conf, + shouldBePublic); + if (loaded) { + useRealNode(); + + // if the revision was a dynamic one (which has now be resolved) + // we now register this node on the resolved id + if (data.getSettings().getVersionMatcher().isDynamic(getId())) { + data.register(node.getResolvedId(), this); + } + } + + return loaded; + } + + public Collection getDependencies(String conf) { + Collection deps = node.getDependencies(rootModuleConf, conf, requestedConf); + Collection ret = new ArrayList(deps.size()); + for (Iterator iter = deps.iterator(); iter.hasNext();) { + IvyNode depNode = (IvyNode) iter.next(); + ret.add(traverseChild(conf, depNode)); + } + return ret; + } + + /** + * Returns a VisitNode for the given node. The given node must be a representation of the same + * module (usually in another revision) as the one visited by this node. The given node must + * also have been already visited. + * + * @param node + * the node to visit + * @return a VisitNode for the given node + */ + VisitNode gotoNode(IvyNode node) { + if (!getModuleId().equals(node.getModuleId())) { + throw new IllegalArgumentException( + "you can't use gotoNode for a node which does not represent the same Module as the one represented by this node.\nCurrent node module id=" + + getModuleId() + " Given node module id=" + node.getModuleId()); + } + VisitData visitData = data.getVisitData(node.getId()); + if (visitData == null) { + throw new IllegalArgumentException( + "you can't use gotoNode with a node which has not been visited yet.\nGiven node id=" + + node.getId()); + } + for (Iterator iter = visitData.getVisitNodes(rootModuleConf).iterator(); iter.hasNext();) { + VisitNode vnode = (VisitNode) iter.next(); + if ((parent == null && vnode.getParent() == null) + || (parent != null && parent.getId().equals(vnode.getParent().getId()))) { + return vnode; + } + } + // the node has not yet been visited from the current parent, we create a new visit node + return traverse(parent, parentConf, node); + } + + private VisitNode traverseChild(String parentConf, IvyNode child) { + VisitNode parent = this; + return traverse(parent, parentConf, child); + } + + private VisitNode traverse(VisitNode parent, String parentConf, IvyNode node) { + if (getPath().contains(node)) { + IvyContext.getContext().getCircularDependencyStrategy().handleCircularDependency( + toMrids(getPath(), node.getId())); + // we do not use the new parent, but the first one, to always be able to go up to the + // root + // parent = getVisitNode(depNode).getParent(); + } + return new VisitNode(data, node, parent, rootModuleConf, parentConf); + } + + private ModuleRevisionId[] toMrids(Collection path, ModuleRevisionId last) { + ModuleRevisionId[] ret = new ModuleRevisionId[path.size() + 1]; + int i = 0; + for (Iterator iter = path.iterator(); iter.hasNext(); i++) { + VisitNode node = (VisitNode) iter.next(); + ret[i] = node.getNode().getId(); + } + ret[ret.length - 1] = last; + return ret; + } + + public ModuleRevisionId getResolvedId() { + return node.getResolvedId(); + } + + public void updateConfsToFetch(Collection confs) { + node.updateConfsToFetch(confs); + } + + public ModuleRevisionId getId() { + return node.getId(); + } + + public boolean isEvicted() { + return node.isEvicted(rootModuleConf); + } + + public String[] getRealConfs(String conf) { + return node.getRealConfs(conf); + } + + public boolean hasProblem() { + return node.hasProblem(); + } + + public Configuration getConfiguration(String conf) { + return node.getConfiguration(conf); + } + + public EvictionData getEvictedData() { + return node.getEvictedData(rootModuleConf); + } + + public DependencyDescriptor getDependencyDescriptor() { + return node.getDependencyDescriptor(getParentNode()); + } + + private IvyNode getParentNode() { + return parent == null ? null : parent.getNode(); + } + + /** + * Returns true if this node can already be found in the path + * + * @return + */ + public boolean isCircular() { + if (isCircular == null) { + if (parent != null) { + isCircular = Boolean.FALSE; // asumme it's false, and see if it isn't by checking + // the parent path + for (Iterator iter = parent.getPath().iterator(); iter.hasNext();) { + VisitNode ancestor = (VisitNode) iter.next(); + if (getId().getModuleId().equals(ancestor.getId().getModuleId())) { + isCircular = Boolean.TRUE; + break; + } + } + } else { + isCircular = Boolean.FALSE; + } + } + return isCircular.booleanValue(); + } + + public String[] getConfsToFetch() { + return node.getConfsToFetch(); + } + + public String[] getRequiredConfigurations(VisitNode in, String inConf) { + return node.getRequiredConfigurations(in.getNode(), inConf); + } + + public ModuleId getModuleId() { + return node.getModuleId(); + } + + public Collection getResolvedRevisions(ModuleId mid) { + return node.getResolvedRevisions(mid, rootModuleConf); + } + + public void markEvicted(EvictionData evictionData) { + node.markEvicted(evictionData); + } + + public String[] getRequiredConfigurations() { + return node.getRequiredConfigurations(); + } + + /** + * Marks the current node as evicted by the the given selected IvyNodes, in the given parent and + * root module configuration, with the given {@link ConflictManager} + * + * @param parent + * the VisitNode in which eviction has been made + * @param conflictManager + * the conflict manager responsible for the eviction + * @param selected + * a Collection of {@link IvyNode} which have been selected + */ + public void markEvicted(VisitNode parent, ConflictManager conflictManager, Collection selected) { + node.markEvicted(rootModuleConf, parent.getNode(), conflictManager, selected); + } + + public ModuleDescriptor getDescriptor() { + return node.getDescriptor(); + } + + public EvictionData getEvictionDataInRoot(String rootModuleConf, VisitNode ancestor) { + return node.getEvictionDataInRoot(rootModuleConf, ancestor.getNode()); + } + + public Collection getEvictedRevisions(ModuleId moduleId) { + return node.getEvictedRevisions(moduleId, rootModuleConf); + } + + // public void setRootModuleConf(String rootModuleConf) { + // if (rootModuleConf != null && !rootModuleConf.equals(rootModuleConf)) { + // _confsToFetch.clear(); // we change of root module conf => we discard all confs to fetch + // } + // if (rootModuleConf != null && rootModuleConf.equals(rootModuleConf)) { + // _selectedDeps.put(new ModuleIdConf(_id.getModuleId(), rootModuleConf), + // Collections.singleton(this)); + // } + // rootModuleConf = rootModuleConf; + // } + + public String toString() { + return node.toString(); + } + +} diff --git a/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java b/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java index 31273e13..713a3ef8 100644 --- a/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java +++ b/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java @@ -1,367 +1,367 @@ -/* - * 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.core.retrieve; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.ivy.plugins.report.XmlReportParser; -import org.apache.ivy.plugins.repository.url.URLResource; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; - -public class RetrieveEngine { - private IvySettings settings; - - public RetrieveEngine(IvySettings settings) { - this.settings = settings; - } - - /** - * example of destFilePattern : - lib/[organisation]/[module]/[artifact]-[revision].[type] - - * lib/[artifact].[type] : flatten with no revision moduleId is used with confs and - * localCacheDirectory to determine an ivy report file, used as input for the copy If such a - * file does not exist for any conf (resolve has not been called before ?) then an - * IllegalStateException is thrown and nothing is copied. - */ - public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) - throws IOException { - ModuleId moduleId = mrid.getModuleId(); - Message.info(":: retrieving :: " + moduleId + (options.isSync() ? " [sync]" : "")); - Message.verbose("\tcheckUpToDate=" + settings.isCheckUpToDate()); - long start = System.currentTimeMillis(); - - destFilePattern = IvyPatternHelper.substituteVariables(destFilePattern, settings - .getVariables()); - String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), - settings.getVariables()); - - CacheManager cacheManager = getCacheManager(options); - String[] confs = getConfs(mrid, options); - Message.info("\tconfs: " + Arrays.asList(confs)); - - try { - Map artifactsToCopy = determineArtifactsToCopy(mrid, destFilePattern, options); - File fileRetrieveRoot = new File(IvyPatternHelper.getTokenRoot(destFilePattern)); - File ivyRetrieveRoot = destIvyPattern == null ? null : new File(IvyPatternHelper - .getTokenRoot(destIvyPattern)); - Collection targetArtifactsStructure = new HashSet(); // Set(File) set of all paths - // which should be present at - // then end of retrieve (useful - // for sync) - Collection targetIvysStructure = new HashSet(); // same for ivy files - - // do retrieve - int targetsCopied = 0; - int targetsUpToDate = 0; - for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - File archive; - if ("ivy".equals(artifact.getType())) { - archive = cacheManager.getIvyFileInCache(artifact.getModuleRevisionId()); - } else { - archive = cacheManager.getArchiveFileInCache(artifact, cacheManager - .getSavedArtifactOrigin(artifact), options.isUseOrigin()); - if (!options.isUseOrigin() && !archive.exists()) { - // file is not available in cache, maybe the last resolve was performed with - // useOrigin=true. - // we try to use the best we can - archive = cacheManager.getArchiveFileInCache(artifact, cacheManager - .getSavedArtifactOrigin(artifact)); - } - } - Set dest = (Set) artifactsToCopy.get(artifact); - Message.verbose("\tretrieving " + archive); - for (Iterator it2 = dest.iterator(); it2.hasNext();) { - IvyContext.getContext().checkInterrupted(); - File destFile = new File((String) it2.next()); - if (!settings.isCheckUpToDate() || !upToDate(archive, destFile)) { - Message.verbose("\t\tto " + destFile); - if (options.isMakeSymlinks()) { - FileUtil.symlink(archive, destFile, null, true); - } else { - FileUtil.copy(archive, destFile, null, true); - } - targetsCopied++; - } else { - Message.verbose("\t\tto " + destFile + " [NOT REQUIRED]"); - targetsUpToDate++; - } - if ("ivy".equals(artifact.getType())) { - targetIvysStructure - .addAll(FileUtil.getPathFiles(ivyRetrieveRoot, destFile)); - } else { - targetArtifactsStructure.addAll(FileUtil.getPathFiles(fileRetrieveRoot, - destFile)); - } - } - } - - if (options.isSync()) { - Message.verbose("\tsyncing..."); - Collection existingArtifacts = FileUtil.listAll(fileRetrieveRoot); - Collection existingIvys = ivyRetrieveRoot == null ? null : FileUtil - .listAll(ivyRetrieveRoot); - - if (fileRetrieveRoot.equals(ivyRetrieveRoot)) { - Collection target = targetArtifactsStructure; - target.addAll(targetIvysStructure); - Collection existing = existingArtifacts; - existing.addAll(existingIvys); - sync(target, existing); - } else { - sync(targetArtifactsStructure, existingArtifacts); - if (existingIvys != null) { - sync(targetIvysStructure, existingIvys); - } - } - } - Message.info("\t" - + targetsCopied - + " artifacts copied" - + (settings.isCheckUpToDate() ? (", " + targetsUpToDate + " already retrieved") - : "")); - Message.verbose("\tretrieve done (" + (System.currentTimeMillis() - start) + "ms)"); - - return targetsCopied; - } catch (Exception ex) { - throw new RuntimeException("problem during retrieve of " + moduleId + ": " + ex, ex); - } - } - - private String[] getConfs(ModuleRevisionId mrid, RetrieveOptions options) throws IOException { - String[] confs = options.getConfs(); - if (confs == null || (confs.length == 1 && "*".equals(confs[0]))) { - try { - File ivyFile = options.getCache().getResolvedIvyFileInCache(mrid); - Message.verbose("no explicit confs given for retrieve, using ivy file: " + ivyFile); - URL ivySource = ivyFile.toURL(); - URLResource res = new URLResource(ivySource); - ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance() - .getParser(res); - Message.debug("using " + parser + " to parse " + ivyFile); - ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, false); - confs = md.getConfigurationsNames(); - options.setConfs(confs); - } catch (IOException e) { - throw e; - } catch (Exception e) { - IOException ioex = new IOException(e.getMessage()); - ioex.initCause(e); - throw ioex; - } - } - return confs; - } - - private CacheManager getCacheManager(RetrieveOptions options) { - CacheManager cacheManager = options.getCache(); - if (cacheManager == null) { // ensure that a cache is configured - cacheManager = IvyContext.getContext().getCacheManager(); - options.setCache(cacheManager); - } else { - IvyContext.getContext().setCache(cacheManager.getCache()); - } - return cacheManager; - } - - private void sync(Collection target, Collection existing) { - Collection toRemove = new HashSet(); - for (Iterator iter = existing.iterator(); iter.hasNext();) { - File file = (File) iter.next(); - toRemove.add(file.getAbsoluteFile()); - } - for (Iterator iter = target.iterator(); iter.hasNext();) { - File file = (File) iter.next(); - toRemove.remove(file.getAbsoluteFile()); - } - for (Iterator iter = toRemove.iterator(); iter.hasNext();) { - File file = (File) iter.next(); - if (file.exists()) { - Message.verbose("\t\tdeleting " + file); - FileUtil.forceDelete(file); - } - } - } - - public Map determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern, - RetrieveOptions options) throws ParseException, IOException { - ModuleId moduleId = mrid.getModuleId(); - - if (options.getResolveId() == null) { - options.setResolveId(ResolveOptions.getDefaultResolveId(moduleId)); - } - - CacheManager cacheManager = getCacheManager(options); - String[] confs = getConfs(mrid, options); - String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), - settings.getVariables()); - - // find what we must retrieve where - final Map artifactsToCopy = new HashMap(); // Artifact source -> Set (String - // copyDestAbsolutePath) - final Map conflictsMap = new HashMap(); // String copyDestAbsolutePath -> Set (Artifact - // source) - final Map conflictsConfMap = new HashMap(); // String copyDestAbsolutePath -> Set (String - // conf) - XmlReportParser parser = new XmlReportParser(); - for (int i = 0; i < confs.length; i++) { - final String conf = confs[i]; - - File report = cacheManager.getConfigurationResolveReportInCache(options.getResolveId(), - conf); - parser.parse(report); - - Collection artifacts = new ArrayList(Arrays.asList(parser.getArtifacts())); - if (destIvyPattern != null) { - ModuleRevisionId[] mrids = parser.getRealDependencyRevisionIds(); - for (int j = 0; j < mrids.length; j++) { - artifacts.add(DefaultArtifact.newIvyArtifact(mrids[j], null)); - } - } - for (Iterator iter = artifacts.iterator(); iter.hasNext();) { - Artifact artifact = (Artifact) iter.next(); - String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern - : destFilePattern; - - if (!"ivy".equals(artifact.getType()) - && !options.getArtifactFilter().accept(artifact)) { - continue; // skip this artifact, the filter didn't accept it! - } - - String destFileName = IvyPatternHelper.substitute(destPattern, artifact, conf); - - Set dest = (Set) artifactsToCopy.get(artifact); - if (dest == null) { - dest = new HashSet(); - artifactsToCopy.put(artifact, dest); - } - String copyDest = new File(destFileName).getAbsolutePath(); - dest.add(copyDest); - - Set conflicts = (Set) conflictsMap.get(copyDest); - Set conflictsConf = (Set) conflictsConfMap.get(copyDest); - if (conflicts == null) { - conflicts = new HashSet(); - conflictsMap.put(copyDest, conflicts); - } - if (conflictsConf == null) { - conflictsConf = new HashSet(); - conflictsConfMap.put(copyDest, conflictsConf); - } - conflicts.add(artifact); - conflictsConf.add(conf); - } - } - - // resolve conflicts if any - for (Iterator iter = conflictsMap.keySet().iterator(); iter.hasNext();) { - String copyDest = (String) iter.next(); - Set artifacts = (Set) conflictsMap.get(copyDest); - Set conflictsConfs = (Set) conflictsConfMap.get(copyDest); - if (artifacts.size() > 1) { - List artifactsList = new ArrayList(artifacts); - // conflicts battle is resolved by a sort using a conflict resolving policy - // comparator - // which consider as greater a winning artifact - Collections.sort(artifactsList, getConflictResolvingPolicy()); - // after the sort, the winning artifact is the greatest one, i.e. the last one - Message.info("\tconflict on " - + copyDest - + " in " - + conflictsConfs - + ": " - + ((Artifact) artifactsList.get(artifactsList.size() - 1)) - .getModuleRevisionId().getRevision() + " won"); - - // we now iterate over the list beginning with the artifact preceding the winner, - // and going backward to the least artifact - for (int i = artifactsList.size() - 2; i >= 0; i--) { - Artifact looser = (Artifact) artifactsList.get(i); - Message.verbose("\t\tremoving conflict looser artifact: " + looser); - // for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy - // map - Set dest = (Set) artifactsToCopy.get(looser); - dest.remove(copyDest); - if (dest.isEmpty()) { - artifactsToCopy.remove(looser); - } - } - } - } - return artifactsToCopy; - } - - private boolean upToDate(File source, File target) { - if (!target.exists()) { - return false; - } - return source.lastModified() <= target.lastModified(); - } - - /** - * The returned comparator should consider greater the artifact which gains the conflict battle. - * This is used only during retrieve... prefer resolve conflict manager to resolve conflicts. - * - * @return - */ - private Comparator getConflictResolvingPolicy() { - return new Comparator() { - // younger conflict resolving policy - public int compare(Object o1, Object o2) { - Artifact a1 = (Artifact) o1; - Artifact a2 = (Artifact) o2; - if (a1.getPublicationDate().after(a2.getPublicationDate())) { - // a1 is after a2 <=> a1 is younger than a2 <=> a1 wins the conflict battle - return +1; - } else if (a1.getPublicationDate().before(a2.getPublicationDate())) { - // a1 is before a2 <=> a2 is younger than a1 <=> a2 wins the conflict battle - return -1; - } else { - return 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. + * + */ +package org.apache.ivy.core.retrieve; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.ivy.plugins.report.XmlReportParser; +import org.apache.ivy.plugins.repository.url.URLResource; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; + +public class RetrieveEngine { + private IvySettings settings; + + public RetrieveEngine(IvySettings settings) { + this.settings = settings; + } + + /** + * example of destFilePattern : - lib/[organisation]/[module]/[artifact]-[revision].[type] - + * lib/[artifact].[type] : flatten with no revision moduleId is used with confs and + * localCacheDirectory to determine an ivy report file, used as input for the copy If such a + * file does not exist for any conf (resolve has not been called before ?) then an + * IllegalStateException is thrown and nothing is copied. + */ + public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options) + throws IOException { + ModuleId moduleId = mrid.getModuleId(); + Message.info(":: retrieving :: " + moduleId + (options.isSync() ? " [sync]" : "")); + Message.verbose("\tcheckUpToDate=" + settings.isCheckUpToDate()); + long start = System.currentTimeMillis(); + + destFilePattern = IvyPatternHelper.substituteVariables(destFilePattern, settings + .getVariables()); + String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), + settings.getVariables()); + + CacheManager cacheManager = getCacheManager(options); + String[] confs = getConfs(mrid, options); + Message.info("\tconfs: " + Arrays.asList(confs)); + + try { + Map artifactsToCopy = determineArtifactsToCopy(mrid, destFilePattern, options); + File fileRetrieveRoot = new File(IvyPatternHelper.getTokenRoot(destFilePattern)); + File ivyRetrieveRoot = destIvyPattern == null ? null : new File(IvyPatternHelper + .getTokenRoot(destIvyPattern)); + Collection targetArtifactsStructure = new HashSet(); // Set(File) set of all paths + // which should be present at + // then end of retrieve (useful + // for sync) + Collection targetIvysStructure = new HashSet(); // same for ivy files + + // do retrieve + int targetsCopied = 0; + int targetsUpToDate = 0; + for (Iterator iter = artifactsToCopy.keySet().iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + File archive; + if ("ivy".equals(artifact.getType())) { + archive = cacheManager.getIvyFileInCache(artifact.getModuleRevisionId()); + } else { + archive = cacheManager.getArchiveFileInCache(artifact, cacheManager + .getSavedArtifactOrigin(artifact), options.isUseOrigin()); + if (!options.isUseOrigin() && !archive.exists()) { + // file is not available in cache, maybe the last resolve was performed with + // useOrigin=true. + // we try to use the best we can + archive = cacheManager.getArchiveFileInCache(artifact, cacheManager + .getSavedArtifactOrigin(artifact)); + } + } + Set dest = (Set) artifactsToCopy.get(artifact); + Message.verbose("\tretrieving " + archive); + for (Iterator it2 = dest.iterator(); it2.hasNext();) { + IvyContext.getContext().checkInterrupted(); + File destFile = new File((String) it2.next()); + if (!settings.isCheckUpToDate() || !upToDate(archive, destFile)) { + Message.verbose("\t\tto " + destFile); + if (options.isMakeSymlinks()) { + FileUtil.symlink(archive, destFile, null, true); + } else { + FileUtil.copy(archive, destFile, null, true); + } + targetsCopied++; + } else { + Message.verbose("\t\tto " + destFile + " [NOT REQUIRED]"); + targetsUpToDate++; + } + if ("ivy".equals(artifact.getType())) { + targetIvysStructure + .addAll(FileUtil.getPathFiles(ivyRetrieveRoot, destFile)); + } else { + targetArtifactsStructure.addAll(FileUtil.getPathFiles(fileRetrieveRoot, + destFile)); + } + } + } + + if (options.isSync()) { + Message.verbose("\tsyncing..."); + Collection existingArtifacts = FileUtil.listAll(fileRetrieveRoot); + Collection existingIvys = ivyRetrieveRoot == null ? null : FileUtil + .listAll(ivyRetrieveRoot); + + if (fileRetrieveRoot.equals(ivyRetrieveRoot)) { + Collection target = targetArtifactsStructure; + target.addAll(targetIvysStructure); + Collection existing = existingArtifacts; + existing.addAll(existingIvys); + sync(target, existing); + } else { + sync(targetArtifactsStructure, existingArtifacts); + if (existingIvys != null) { + sync(targetIvysStructure, existingIvys); + } + } + } + Message.info("\t" + + targetsCopied + + " artifacts copied" + + (settings.isCheckUpToDate() ? (", " + targetsUpToDate + " already retrieved") + : "")); + Message.verbose("\tretrieve done (" + (System.currentTimeMillis() - start) + "ms)"); + + return targetsCopied; + } catch (Exception ex) { + throw new RuntimeException("problem during retrieve of " + moduleId + ": " + ex, ex); + } + } + + private String[] getConfs(ModuleRevisionId mrid, RetrieveOptions options) throws IOException { + String[] confs = options.getConfs(); + if (confs == null || (confs.length == 1 && "*".equals(confs[0]))) { + try { + File ivyFile = options.getCache().getResolvedIvyFileInCache(mrid); + Message.verbose("no explicit confs given for retrieve, using ivy file: " + ivyFile); + URL ivySource = ivyFile.toURL(); + URLResource res = new URLResource(ivySource); + ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance() + .getParser(res); + Message.debug("using " + parser + " to parse " + ivyFile); + ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, false); + confs = md.getConfigurationsNames(); + options.setConfs(confs); + } catch (IOException e) { + throw e; + } catch (Exception e) { + IOException ioex = new IOException(e.getMessage()); + ioex.initCause(e); + throw ioex; + } + } + return confs; + } + + private CacheManager getCacheManager(RetrieveOptions options) { + CacheManager cacheManager = options.getCache(); + if (cacheManager == null) { // ensure that a cache is configured + cacheManager = IvyContext.getContext().getCacheManager(); + options.setCache(cacheManager); + } else { + IvyContext.getContext().setCache(cacheManager.getCache()); + } + return cacheManager; + } + + private void sync(Collection target, Collection existing) { + Collection toRemove = new HashSet(); + for (Iterator iter = existing.iterator(); iter.hasNext();) { + File file = (File) iter.next(); + toRemove.add(file.getAbsoluteFile()); + } + for (Iterator iter = target.iterator(); iter.hasNext();) { + File file = (File) iter.next(); + toRemove.remove(file.getAbsoluteFile()); + } + for (Iterator iter = toRemove.iterator(); iter.hasNext();) { + File file = (File) iter.next(); + if (file.exists()) { + Message.verbose("\t\tdeleting " + file); + FileUtil.forceDelete(file); + } + } + } + + public Map determineArtifactsToCopy(ModuleRevisionId mrid, String destFilePattern, + RetrieveOptions options) throws ParseException, IOException { + ModuleId moduleId = mrid.getModuleId(); + + if (options.getResolveId() == null) { + options.setResolveId(ResolveOptions.getDefaultResolveId(moduleId)); + } + + CacheManager cacheManager = getCacheManager(options); + String[] confs = getConfs(mrid, options); + String destIvyPattern = IvyPatternHelper.substituteVariables(options.getDestIvyPattern(), + settings.getVariables()); + + // find what we must retrieve where + final Map artifactsToCopy = new HashMap(); // Artifact source -> Set (String + // copyDestAbsolutePath) + final Map conflictsMap = new HashMap(); // String copyDestAbsolutePath -> Set (Artifact + // source) + final Map conflictsConfMap = new HashMap(); // String copyDestAbsolutePath -> Set (String + // conf) + XmlReportParser parser = new XmlReportParser(); + for (int i = 0; i < confs.length; i++) { + final String conf = confs[i]; + + File report = cacheManager.getConfigurationResolveReportInCache(options.getResolveId(), + conf); + parser.parse(report); + + Collection artifacts = new ArrayList(Arrays.asList(parser.getArtifacts())); + if (destIvyPattern != null) { + ModuleRevisionId[] mrids = parser.getRealDependencyRevisionIds(); + for (int j = 0; j < mrids.length; j++) { + artifacts.add(DefaultArtifact.newIvyArtifact(mrids[j], null)); + } + } + for (Iterator iter = artifacts.iterator(); iter.hasNext();) { + Artifact artifact = (Artifact) iter.next(); + String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern + : destFilePattern; + + if (!"ivy".equals(artifact.getType()) + && !options.getArtifactFilter().accept(artifact)) { + continue; // skip this artifact, the filter didn't accept it! + } + + String destFileName = IvyPatternHelper.substitute(destPattern, artifact, conf); + + Set dest = (Set) artifactsToCopy.get(artifact); + if (dest == null) { + dest = new HashSet(); + artifactsToCopy.put(artifact, dest); + } + String copyDest = new File(destFileName).getAbsolutePath(); + dest.add(copyDest); + + Set conflicts = (Set) conflictsMap.get(copyDest); + Set conflictsConf = (Set) conflictsConfMap.get(copyDest); + if (conflicts == null) { + conflicts = new HashSet(); + conflictsMap.put(copyDest, conflicts); + } + if (conflictsConf == null) { + conflictsConf = new HashSet(); + conflictsConfMap.put(copyDest, conflictsConf); + } + conflicts.add(artifact); + conflictsConf.add(conf); + } + } + + // resolve conflicts if any + for (Iterator iter = conflictsMap.keySet().iterator(); iter.hasNext();) { + String copyDest = (String) iter.next(); + Set artifacts = (Set) conflictsMap.get(copyDest); + Set conflictsConfs = (Set) conflictsConfMap.get(copyDest); + if (artifacts.size() > 1) { + List artifactsList = new ArrayList(artifacts); + // conflicts battle is resolved by a sort using a conflict resolving policy + // comparator + // which consider as greater a winning artifact + Collections.sort(artifactsList, getConflictResolvingPolicy()); + // after the sort, the winning artifact is the greatest one, i.e. the last one + Message.info("\tconflict on " + + copyDest + + " in " + + conflictsConfs + + ": " + + ((Artifact) artifactsList.get(artifactsList.size() - 1)) + .getModuleRevisionId().getRevision() + " won"); + + // we now iterate over the list beginning with the artifact preceding the winner, + // and going backward to the least artifact + for (int i = artifactsList.size() - 2; i >= 0; i--) { + Artifact looser = (Artifact) artifactsList.get(i); + Message.verbose("\t\tremoving conflict looser artifact: " + looser); + // for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy + // map + Set dest = (Set) artifactsToCopy.get(looser); + dest.remove(copyDest); + if (dest.isEmpty()) { + artifactsToCopy.remove(looser); + } + } + } + } + return artifactsToCopy; + } + + private boolean upToDate(File source, File target) { + if (!target.exists()) { + return false; + } + return source.lastModified() <= target.lastModified(); + } + + /** + * The returned comparator should consider greater the artifact which gains the conflict battle. + * This is used only during retrieve... prefer resolve conflict manager to resolve conflicts. + * + * @return + */ + private Comparator getConflictResolvingPolicy() { + return new Comparator() { + // younger conflict resolving policy + public int compare(Object o1, Object o2) { + Artifact a1 = (Artifact) o1; + Artifact a2 = (Artifact) o2; + if (a1.getPublicationDate().after(a2.getPublicationDate())) { + // a1 is after a2 <=> a1 is younger than a2 <=> a1 wins the conflict battle + return +1; + } else if (a1.getPublicationDate().before(a2.getPublicationDate())) { + // a1 is before a2 <=> a2 is younger than a1 <=> a2 wins the conflict battle + return -1; + } else { + return 0; + } + } + }; + } + +} diff --git a/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java b/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java index c0e600c4..b24cede1 100644 --- a/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java +++ b/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java @@ -1,148 +1,148 @@ -/* - * 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.core.retrieve; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.util.filter.Filter; -import org.apache.ivy.util.filter.FilterHelper; - -/** - * A set of options used during retrieve related tasks - * - * @see RetrieveEngine - */ -public class RetrieveOptions { - /** - * The names of configurations to retrieve. If the array consists only of '*', then all - * configurations of the module will be retrieved. - */ - private String[] confs = new String[] {"*"}; - - /** - * The cache manager to retrieve files from. If null, the default cache manager of the current - * Ivy instance will be used. - */ - private CacheManager cache = null; - - /** - * The pattern to which ivy files should be retrieved. If destIvyPattern is null no ivy files - * will be copied. - */ - private String destIvyPattern = null; - - /** - * The filter to apply before retrieving artifacts. - */ - private Filter artifactFilter = FilterHelper.NO_FILTER; - - /** - * True if a synchronisation of the destination directory should be done, false if a simple copy - * is enough. Synchronisation means that after the retrieve only files which have been retrieved - * will be present in the destination directory, which means that some files may be deleted. - */ - private boolean sync = false; - - /** - * True if the original files should be used insteaad of their cache copy. - */ - private boolean useOrigin = false; - - /** - * True if symbolic links should be created instead of plain copy. Works only on OS supporting - * symbolic links. - */ - private boolean makeSymlinks = false; - - /** - * The id used to store the resolve information. - */ - private String resolveId; - - public Filter getArtifactFilter() { - return artifactFilter; - } - - public RetrieveOptions setArtifactFilter(Filter artifactFilter) { - this.artifactFilter = artifactFilter; - return this; - } - - public CacheManager getCache() { - return cache; - } - - public RetrieveOptions setCache(CacheManager cacheManager) { - this.cache = cacheManager; - return this; - } - - public String[] getConfs() { - return confs; - } - - public RetrieveOptions setConfs(String[] confs) { - this.confs = confs; - return this; - } - - public String getDestIvyPattern() { - return destIvyPattern; - } - - public RetrieveOptions setDestIvyPattern(String destIvyPattern) { - this.destIvyPattern = destIvyPattern; - return this; - } - - public boolean isMakeSymlinks() { - return makeSymlinks; - } - - public RetrieveOptions setMakeSymlinks(boolean makeSymlinks) { - this.makeSymlinks = makeSymlinks; - return this; - } - - public boolean isSync() { - return sync; - } - - public RetrieveOptions setSync(boolean sync) { - this.sync = sync; - return this; - } - - public boolean isUseOrigin() { - return useOrigin; - } - - public RetrieveOptions setUseOrigin(boolean useOrigin) { - this.useOrigin = useOrigin; - return this; - } - - public String getResolveId() { - return resolveId; - } - - public RetrieveOptions setResolveId(String resolveId) { - this.resolveId = resolveId; - return this; - } - -} +/* + * 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.core.retrieve; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.util.filter.Filter; +import org.apache.ivy.util.filter.FilterHelper; + +/** + * A set of options used during retrieve related tasks + * + * @see RetrieveEngine + */ +public class RetrieveOptions { + /** + * The names of configurations to retrieve. If the array consists only of '*', then all + * configurations of the module will be retrieved. + */ + private String[] confs = new String[] {"*"}; + + /** + * The cache manager to retrieve files from. If null, the default cache manager of the current + * Ivy instance will be used. + */ + private CacheManager cache = null; + + /** + * The pattern to which ivy files should be retrieved. If destIvyPattern is null no ivy files + * will be copied. + */ + private String destIvyPattern = null; + + /** + * The filter to apply before retrieving artifacts. + */ + private Filter artifactFilter = FilterHelper.NO_FILTER; + + /** + * True if a synchronisation of the destination directory should be done, false if a simple copy + * is enough. Synchronisation means that after the retrieve only files which have been retrieved + * will be present in the destination directory, which means that some files may be deleted. + */ + private boolean sync = false; + + /** + * True if the original files should be used insteaad of their cache copy. + */ + private boolean useOrigin = false; + + /** + * True if symbolic links should be created instead of plain copy. Works only on OS supporting + * symbolic links. + */ + private boolean makeSymlinks = false; + + /** + * The id used to store the resolve information. + */ + private String resolveId; + + public Filter getArtifactFilter() { + return artifactFilter; + } + + public RetrieveOptions setArtifactFilter(Filter artifactFilter) { + this.artifactFilter = artifactFilter; + return this; + } + + public CacheManager getCache() { + return cache; + } + + public RetrieveOptions setCache(CacheManager cacheManager) { + this.cache = cacheManager; + return this; + } + + public String[] getConfs() { + return confs; + } + + public RetrieveOptions setConfs(String[] confs) { + this.confs = confs; + return this; + } + + public String getDestIvyPattern() { + return destIvyPattern; + } + + public RetrieveOptions setDestIvyPattern(String destIvyPattern) { + this.destIvyPattern = destIvyPattern; + return this; + } + + public boolean isMakeSymlinks() { + return makeSymlinks; + } + + public RetrieveOptions setMakeSymlinks(boolean makeSymlinks) { + this.makeSymlinks = makeSymlinks; + return this; + } + + public boolean isSync() { + return sync; + } + + public RetrieveOptions setSync(boolean sync) { + this.sync = sync; + return this; + } + + public boolean isUseOrigin() { + return useOrigin; + } + + public RetrieveOptions setUseOrigin(boolean useOrigin) { + this.useOrigin = useOrigin; + return this; + } + + public String getResolveId() { + return resolveId; + } + + public RetrieveOptions setResolveId(String resolveId) { + this.resolveId = resolveId; + return this; + } + +} diff --git a/src/java/org/apache/ivy/core/search/ModuleEntry.java b/src/java/org/apache/ivy/core/search/ModuleEntry.java index 3ef50398..136c7b49 100644 --- a/src/java/org/apache/ivy/core/search/ModuleEntry.java +++ b/src/java/org/apache/ivy/core/search/ModuleEntry.java @@ -1,48 +1,48 @@ -/* - * 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.core.search; - -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class ModuleEntry { - private OrganisationEntry organisationEntry; - - private String module; - - public ModuleEntry(OrganisationEntry org, String name) { - organisationEntry = org; - module = name; - } - - public String getOrganisation() { - return organisationEntry.getOrganisation(); - } - - public DependencyResolver getResolver() { - return organisationEntry.getResolver(); - } - - public String getModule() { - return module; - } - - public OrganisationEntry getOrganisationEntry() { - return organisationEntry; - } - -} +/* + * 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.core.search; + +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class ModuleEntry { + private OrganisationEntry organisationEntry; + + private String module; + + public ModuleEntry(OrganisationEntry org, String name) { + organisationEntry = org; + module = name; + } + + public String getOrganisation() { + return organisationEntry.getOrganisation(); + } + + public DependencyResolver getResolver() { + return organisationEntry.getResolver(); + } + + public String getModule() { + return module; + } + + public OrganisationEntry getOrganisationEntry() { + return organisationEntry; + } + +} diff --git a/src/java/org/apache/ivy/core/search/OrganisationEntry.java b/src/java/org/apache/ivy/core/search/OrganisationEntry.java index 2452649a..c583c8b8 100644 --- a/src/java/org/apache/ivy/core/search/OrganisationEntry.java +++ b/src/java/org/apache/ivy/core/search/OrganisationEntry.java @@ -1,40 +1,40 @@ -/* - * 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.core.search; - -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class OrganisationEntry { - private DependencyResolver resolver; - - private String organisation; - - public OrganisationEntry(DependencyResolver resolver, String organisation) { - this.resolver = resolver; - this.organisation = organisation; - } - - public String getOrganisation() { - return organisation; - } - - public DependencyResolver getResolver() { - return resolver; - } - -} +/* + * 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.core.search; + +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class OrganisationEntry { + private DependencyResolver resolver; + + private String organisation; + + public OrganisationEntry(DependencyResolver resolver, String organisation) { + this.resolver = resolver; + this.organisation = organisation; + } + + public String getOrganisation() { + return organisation; + } + + public DependencyResolver getResolver() { + return resolver; + } + +} diff --git a/src/java/org/apache/ivy/core/search/RevisionEntry.java b/src/java/org/apache/ivy/core/search/RevisionEntry.java index df24deec..97afb4ac 100644 --- a/src/java/org/apache/ivy/core/search/RevisionEntry.java +++ b/src/java/org/apache/ivy/core/search/RevisionEntry.java @@ -1,56 +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. - * - */ -package org.apache.ivy.core.search; - -import org.apache.ivy.plugins.resolver.DependencyResolver; - -public class RevisionEntry { - private ModuleEntry moduleEntry; - - private String revision; - - public RevisionEntry(ModuleEntry mod, String name) { - moduleEntry = mod; - revision = name; - } - - public ModuleEntry getModuleEntry() { - return moduleEntry; - } - - public String getRevision() { - return revision; - } - - public String getModule() { - return moduleEntry.getModule(); - } - - public String getOrganisation() { - return moduleEntry.getOrganisation(); - } - - public OrganisationEntry getOrganisationEntry() { - return moduleEntry.getOrganisationEntry(); - } - - public DependencyResolver getResolver() { - return moduleEntry.getResolver(); - } - -} +/* + * 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.core.search; + +import org.apache.ivy.plugins.resolver.DependencyResolver; + +public class RevisionEntry { + private ModuleEntry moduleEntry; + + private String revision; + + public RevisionEntry(ModuleEntry mod, String name) { + moduleEntry = mod; + revision = name; + } + + public ModuleEntry getModuleEntry() { + return moduleEntry; + } + + public String getRevision() { + return revision; + } + + public String getModule() { + return moduleEntry.getModule(); + } + + public String getOrganisation() { + return moduleEntry.getOrganisation(); + } + + public OrganisationEntry getOrganisationEntry() { + return moduleEntry.getOrganisationEntry(); + } + + public DependencyResolver getResolver() { + return moduleEntry.getResolver(); + } + +} diff --git a/src/java/org/apache/ivy/core/search/SearchEngine.java b/src/java/org/apache/ivy/core/search/SearchEngine.java index fa6edac0..21980530 100644 --- a/src/java/org/apache/ivy/core/search/SearchEngine.java +++ b/src/java/org/apache/ivy/core/search/SearchEngine.java @@ -1,307 +1,307 @@ -/* - * 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.core.search; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.matcher.Matcher; -import org.apache.ivy.plugins.matcher.MatcherHelper; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.namespace.NameSpaceHelper; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.plugins.resolver.AbstractResolver; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.util.Message; - -public class SearchEngine { - private IvySettings settings; - - public SearchEngine(IvySettings settings) { - this.settings = settings; - } - - /** - * Returns an empty array when no token values are found. - * - * @param token - * @param otherTokenValues - * @return - */ - public String[] listTokenValues(String token, Map otherTokenValues) { - List r = new ArrayList(); - for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - r.addAll(Arrays.asList(resolver.listTokenValues(token, otherTokenValues))); - } - return (String[]) r.toArray(new String[r.size()]); - } - - public OrganisationEntry[] listOrganisationEntries() { - List entries = new ArrayList(); - for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - entries.addAll(Arrays.asList(resolver.listOrganisations())); - } - return (OrganisationEntry[]) entries.toArray(new OrganisationEntry[entries.size()]); - } - - public String[] listOrganisations() { - Collection orgs = new HashSet(); - for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - OrganisationEntry[] entries = resolver.listOrganisations(); - if (entries != null) { - for (int i = 0; i < entries.length; i++) { - if (entries[i] != null) { - orgs.add(entries[i].getOrganisation()); - } - } - } - } - return (String[]) orgs.toArray(new String[orgs.size()]); - } - - public ModuleEntry[] listModuleEntries(OrganisationEntry org) { - List entries = new ArrayList(); - for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - entries.addAll(Arrays.asList(resolver.listModules(org))); - } - return (ModuleEntry[]) entries.toArray(new ModuleEntry[entries.size()]); - } - - public String[] listModules(String org) { - List mods = new ArrayList(); - for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - ModuleEntry[] entries = resolver.listModules(new OrganisationEntry(resolver, org)); - if (entries != null) { - for (int i = 0; i < entries.length; i++) { - if (entries[i] != null) { - mods.add(entries[i].getModule()); - } - } - } - } - return (String[]) mods.toArray(new String[mods.size()]); - } - - public RevisionEntry[] listRevisionEntries(ModuleEntry module) { - List entries = new ArrayList(); - for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - entries.addAll(Arrays.asList(resolver.listRevisions(module))); - } - return (RevisionEntry[]) entries.toArray(new RevisionEntry[entries.size()]); - } - - public String[] listRevisions(String org, String module) { - List revs = new ArrayList(); - for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - RevisionEntry[] entries = resolver.listRevisions(new ModuleEntry(new OrganisationEntry( - resolver, org), module)); - if (entries != null) { - for (int i = 0; i < entries.length; i++) { - if (entries[i] != null) { - revs.add(entries[i].getRevision()); - } - } - } - } - return (String[]) revs.toArray(new String[revs.size()]); - } - - /** - * List module ids of the module accessible through the current resolvers matching the given mid - * criteria according to the given matcher. - * - * @param criteria - * @param matcher - * @return - */ - public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) { - List ret = new ArrayList(); - Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation()); - Matcher modMatcher = matcher.getMatcher(criteria.getName()); - Map tokenValues = new HashMap(); - String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues); - for (int i = 0; i < orgs.length; i++) { - if (orgMatcher.matches(orgs[i])) { - tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]); - String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues); - for (int j = 0; j < mods.length; j++) { - if (modMatcher.matches(mods[j])) { - ret.add(new ModuleId(orgs[i], mods[j])); - } - } - } - } - return (ModuleId[]) ret.toArray(new ModuleId[ret.size()]); - } - - /** - * List module revision ids of the module accessible through the current resolvers matching the - * given mrid criteria according to the given matcher. - * - * @param criteria - * @param matcher - * @return - */ - public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) { - List ret = new ArrayList(); - Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation()); - Matcher modMatcher = matcher.getMatcher(criteria.getName()); - Matcher branchMatcher = matcher.getMatcher(criteria.getBranch()); - Matcher revMatcher = matcher.getMatcher(criteria.getRevision()); - Map tokenValues = new HashMap(); - String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues); - for (int i = 0; i < orgs.length; i++) { - if (orgMatcher.matches(orgs[i])) { - tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]); - String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues); - for (int j = 0; j < mods.length; j++) { - if (modMatcher.matches(mods[j])) { - tokenValues.put(IvyPatternHelper.MODULE_KEY, mods[j]); - String[] branches = listTokenValues(IvyPatternHelper.BRANCH_KEY, - tokenValues); - if (branches == null || branches.length == 0) { - branches = new String[] {settings.getDefaultBranch(new ModuleId( - orgs[i], mods[j]))}; - } - for (int k = 0; k < branches.length; k++) { - if (branches[k] == null || branchMatcher.matches(branches[k])) { - tokenValues.put(IvyPatternHelper.BRANCH_KEY, tokenValues); - String[] revs = listTokenValues(IvyPatternHelper.REVISION_KEY, - tokenValues); - for (int l = 0; l < revs.length; l++) { - if (revMatcher.matches(revs[l])) { - ret.add(ModuleRevisionId.newInstance(orgs[i], mods[j], - branches[k], revs[l])); - } - } - } - } - } - } - } - } - return (ModuleRevisionId[]) ret.toArray(new ModuleRevisionId[ret.size()]); - } - - public Collection findModuleRevisionIds(DependencyResolver resolver, ModuleRevisionId pattern, - PatternMatcher matcher) { - Collection mrids = new ArrayList(); - String resolverName = resolver.getName(); - - Message.verbose("looking for modules matching " + pattern + " using " + matcher.getName()); - Namespace fromNamespace = resolver instanceof AbstractResolver ? ((AbstractResolver) resolver) - .getNamespace() - : null; - - Collection modules = new ArrayList(); - - OrganisationEntry[] orgs = resolver.listOrganisations(); - if (orgs == null || orgs.length == 0) { - // hack for resolvers which are not able to list organisation, we try to see if the - // asked organisation is not an exact one: - String org = pattern.getOrganisation(); - if (fromNamespace != null) { - org = NameSpaceHelper.transform(pattern.getModuleId(), - fromNamespace.getFromSystemTransformer()).getOrganisation(); - } - modules.addAll(Arrays - .asList(resolver.listModules(new OrganisationEntry(resolver, org)))); - } else { - Matcher orgMatcher = matcher.getMatcher(pattern.getOrganisation()); - for (int i = 0; i < orgs.length; i++) { - String org = orgs[i].getOrganisation(); - String systemOrg = org; - if (fromNamespace != null) { - systemOrg = NameSpaceHelper.transformOrganisation(org, fromNamespace - .getToSystemTransformer()); - } - if (orgMatcher.matches(systemOrg)) { - modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry( - resolver, org)))); - } - } - } - Message.debug("found " + modules.size() + " modules for " + pattern.getOrganisation() - + " on " + resolverName); - boolean foundModule = false; - for (Iterator iter = modules.iterator(); iter.hasNext();) { - ModuleEntry mEntry = (ModuleEntry) iter.next(); - - ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule()); - ModuleId systemMid = foundMid; - if (fromNamespace != null) { - systemMid = NameSpaceHelper.transform(foundMid, fromNamespace - .getToSystemTransformer()); - } - - if (MatcherHelper.matches(matcher, pattern.getModuleId(), systemMid)) { - // The module corresponds to the searched module pattern - foundModule = true; - RevisionEntry[] rEntries = resolver.listRevisions(mEntry); - Message.debug("found " + rEntries.length + " revisions for [" - + mEntry.getOrganisation() + ", " + mEntry.getModule() + "] on " - + resolverName); - - boolean foundRevision = false; - for (int j = 0; j < rEntries.length; j++) { - RevisionEntry rEntry = rEntries[j]; - - ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mEntry - .getOrganisation(), mEntry.getModule(), rEntry.getRevision()); - ModuleRevisionId systemMrid = foundMrid; - if (fromNamespace != null) { - systemMrid = fromNamespace.getToSystemTransformer().transform(foundMrid); - } - - if (MatcherHelper.matches(matcher, pattern, systemMrid)) { - // We have a matching module revision - foundRevision = true; - mrids.add(systemMrid); - } - } - if (!foundRevision) { - Message.debug("no revision found matching " + pattern + " in [" - + mEntry.getOrganisation() + "," + mEntry.getModule() + "] using " - + resolverName); - } - } - } - if (!foundModule) { - Message.debug("no module found matching " + pattern + " using " + resolverName); - } - return mrids; - } - -} +/* + * 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.core.search; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.matcher.Matcher; +import org.apache.ivy.plugins.matcher.MatcherHelper; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.namespace.NameSpaceHelper; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.plugins.resolver.AbstractResolver; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.util.Message; + +public class SearchEngine { + private IvySettings settings; + + public SearchEngine(IvySettings settings) { + this.settings = settings; + } + + /** + * Returns an empty array when no token values are found. + * + * @param token + * @param otherTokenValues + * @return + */ + public String[] listTokenValues(String token, Map otherTokenValues) { + List r = new ArrayList(); + for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + r.addAll(Arrays.asList(resolver.listTokenValues(token, otherTokenValues))); + } + return (String[]) r.toArray(new String[r.size()]); + } + + public OrganisationEntry[] listOrganisationEntries() { + List entries = new ArrayList(); + for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + entries.addAll(Arrays.asList(resolver.listOrganisations())); + } + return (OrganisationEntry[]) entries.toArray(new OrganisationEntry[entries.size()]); + } + + public String[] listOrganisations() { + Collection orgs = new HashSet(); + for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + OrganisationEntry[] entries = resolver.listOrganisations(); + if (entries != null) { + for (int i = 0; i < entries.length; i++) { + if (entries[i] != null) { + orgs.add(entries[i].getOrganisation()); + } + } + } + } + return (String[]) orgs.toArray(new String[orgs.size()]); + } + + public ModuleEntry[] listModuleEntries(OrganisationEntry org) { + List entries = new ArrayList(); + for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + entries.addAll(Arrays.asList(resolver.listModules(org))); + } + return (ModuleEntry[]) entries.toArray(new ModuleEntry[entries.size()]); + } + + public String[] listModules(String org) { + List mods = new ArrayList(); + for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + ModuleEntry[] entries = resolver.listModules(new OrganisationEntry(resolver, org)); + if (entries != null) { + for (int i = 0; i < entries.length; i++) { + if (entries[i] != null) { + mods.add(entries[i].getModule()); + } + } + } + } + return (String[]) mods.toArray(new String[mods.size()]); + } + + public RevisionEntry[] listRevisionEntries(ModuleEntry module) { + List entries = new ArrayList(); + for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + entries.addAll(Arrays.asList(resolver.listRevisions(module))); + } + return (RevisionEntry[]) entries.toArray(new RevisionEntry[entries.size()]); + } + + public String[] listRevisions(String org, String module) { + List revs = new ArrayList(); + for (Iterator iter = settings.getResolvers().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + RevisionEntry[] entries = resolver.listRevisions(new ModuleEntry(new OrganisationEntry( + resolver, org), module)); + if (entries != null) { + for (int i = 0; i < entries.length; i++) { + if (entries[i] != null) { + revs.add(entries[i].getRevision()); + } + } + } + } + return (String[]) revs.toArray(new String[revs.size()]); + } + + /** + * List module ids of the module accessible through the current resolvers matching the given mid + * criteria according to the given matcher. + * + * @param criteria + * @param matcher + * @return + */ + public ModuleId[] listModules(ModuleId criteria, PatternMatcher matcher) { + List ret = new ArrayList(); + Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation()); + Matcher modMatcher = matcher.getMatcher(criteria.getName()); + Map tokenValues = new HashMap(); + String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues); + for (int i = 0; i < orgs.length; i++) { + if (orgMatcher.matches(orgs[i])) { + tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]); + String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues); + for (int j = 0; j < mods.length; j++) { + if (modMatcher.matches(mods[j])) { + ret.add(new ModuleId(orgs[i], mods[j])); + } + } + } + } + return (ModuleId[]) ret.toArray(new ModuleId[ret.size()]); + } + + /** + * List module revision ids of the module accessible through the current resolvers matching the + * given mrid criteria according to the given matcher. + * + * @param criteria + * @param matcher + * @return + */ + public ModuleRevisionId[] listModules(ModuleRevisionId criteria, PatternMatcher matcher) { + List ret = new ArrayList(); + Matcher orgMatcher = matcher.getMatcher(criteria.getOrganisation()); + Matcher modMatcher = matcher.getMatcher(criteria.getName()); + Matcher branchMatcher = matcher.getMatcher(criteria.getBranch()); + Matcher revMatcher = matcher.getMatcher(criteria.getRevision()); + Map tokenValues = new HashMap(); + String[] orgs = listTokenValues(IvyPatternHelper.ORGANISATION_KEY, tokenValues); + for (int i = 0; i < orgs.length; i++) { + if (orgMatcher.matches(orgs[i])) { + tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, orgs[i]); + String[] mods = listTokenValues(IvyPatternHelper.MODULE_KEY, tokenValues); + for (int j = 0; j < mods.length; j++) { + if (modMatcher.matches(mods[j])) { + tokenValues.put(IvyPatternHelper.MODULE_KEY, mods[j]); + String[] branches = listTokenValues(IvyPatternHelper.BRANCH_KEY, + tokenValues); + if (branches == null || branches.length == 0) { + branches = new String[] {settings.getDefaultBranch(new ModuleId( + orgs[i], mods[j]))}; + } + for (int k = 0; k < branches.length; k++) { + if (branches[k] == null || branchMatcher.matches(branches[k])) { + tokenValues.put(IvyPatternHelper.BRANCH_KEY, tokenValues); + String[] revs = listTokenValues(IvyPatternHelper.REVISION_KEY, + tokenValues); + for (int l = 0; l < revs.length; l++) { + if (revMatcher.matches(revs[l])) { + ret.add(ModuleRevisionId.newInstance(orgs[i], mods[j], + branches[k], revs[l])); + } + } + } + } + } + } + } + } + return (ModuleRevisionId[]) ret.toArray(new ModuleRevisionId[ret.size()]); + } + + public Collection findModuleRevisionIds(DependencyResolver resolver, ModuleRevisionId pattern, + PatternMatcher matcher) { + Collection mrids = new ArrayList(); + String resolverName = resolver.getName(); + + Message.verbose("looking for modules matching " + pattern + " using " + matcher.getName()); + Namespace fromNamespace = resolver instanceof AbstractResolver ? ((AbstractResolver) resolver) + .getNamespace() + : null; + + Collection modules = new ArrayList(); + + OrganisationEntry[] orgs = resolver.listOrganisations(); + if (orgs == null || orgs.length == 0) { + // hack for resolvers which are not able to list organisation, we try to see if the + // asked organisation is not an exact one: + String org = pattern.getOrganisation(); + if (fromNamespace != null) { + org = NameSpaceHelper.transform(pattern.getModuleId(), + fromNamespace.getFromSystemTransformer()).getOrganisation(); + } + modules.addAll(Arrays + .asList(resolver.listModules(new OrganisationEntry(resolver, org)))); + } else { + Matcher orgMatcher = matcher.getMatcher(pattern.getOrganisation()); + for (int i = 0; i < orgs.length; i++) { + String org = orgs[i].getOrganisation(); + String systemOrg = org; + if (fromNamespace != null) { + systemOrg = NameSpaceHelper.transformOrganisation(org, fromNamespace + .getToSystemTransformer()); + } + if (orgMatcher.matches(systemOrg)) { + modules.addAll(Arrays.asList(resolver.listModules(new OrganisationEntry( + resolver, org)))); + } + } + } + Message.debug("found " + modules.size() + " modules for " + pattern.getOrganisation() + + " on " + resolverName); + boolean foundModule = false; + for (Iterator iter = modules.iterator(); iter.hasNext();) { + ModuleEntry mEntry = (ModuleEntry) iter.next(); + + ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule()); + ModuleId systemMid = foundMid; + if (fromNamespace != null) { + systemMid = NameSpaceHelper.transform(foundMid, fromNamespace + .getToSystemTransformer()); + } + + if (MatcherHelper.matches(matcher, pattern.getModuleId(), systemMid)) { + // The module corresponds to the searched module pattern + foundModule = true; + RevisionEntry[] rEntries = resolver.listRevisions(mEntry); + Message.debug("found " + rEntries.length + " revisions for [" + + mEntry.getOrganisation() + ", " + mEntry.getModule() + "] on " + + resolverName); + + boolean foundRevision = false; + for (int j = 0; j < rEntries.length; j++) { + RevisionEntry rEntry = rEntries[j]; + + ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mEntry + .getOrganisation(), mEntry.getModule(), rEntry.getRevision()); + ModuleRevisionId systemMrid = foundMrid; + if (fromNamespace != null) { + systemMrid = fromNamespace.getToSystemTransformer().transform(foundMrid); + } + + if (MatcherHelper.matches(matcher, pattern, systemMrid)) { + // We have a matching module revision + foundRevision = true; + mrids.add(systemMrid); + } + } + if (!foundRevision) { + Message.debug("no revision found matching " + pattern + " in [" + + mEntry.getOrganisation() + "," + mEntry.getModule() + "] using " + + resolverName); + } + } + } + if (!foundModule) { + Message.debug("no module found matching " + pattern + " using " + resolverName); + } + return mrids; + } + +} diff --git a/src/java/org/apache/ivy/core/settings/IvyPattern.java b/src/java/org/apache/ivy/core/settings/IvyPattern.java index b02e40e2..14647142 100644 --- a/src/java/org/apache/ivy/core/settings/IvyPattern.java +++ b/src/java/org/apache/ivy/core/settings/IvyPattern.java @@ -1,33 +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. - * - */ -package org.apache.ivy.core.settings; - -/** - * - */ -public class IvyPattern { - private String pattern; - - public String getPattern() { - return pattern; - } - - public void setPattern(String pattern) { - this.pattern = pattern; - } -} +/* + * 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.core.settings; + +/** + * + */ +public class IvyPattern { + private String pattern; + + public String getPattern() { + return pattern; + } + + public void setPattern(String pattern) { + this.pattern = pattern; + } +} diff --git a/src/java/org/apache/ivy/core/settings/IvySettings.java b/src/java/org/apache/ivy/core/settings/IvySettings.java index 423f1987..450b322b 100644 --- a/src/java/org/apache/ivy/core/settings/IvySettings.java +++ b/src/java/org/apache/ivy/core/settings/IvySettings.java @@ -1,1150 +1,1150 @@ -/* - * 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.core.settings; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.status.StatusManager; -import org.apache.ivy.plugins.IvyAware; -import org.apache.ivy.plugins.IvySettingsAware; -import org.apache.ivy.plugins.circular.CircularDependencyStrategy; -import org.apache.ivy.plugins.circular.ErrorCircularDependencyStrategy; -import org.apache.ivy.plugins.circular.IgnoreCircularDependencyStrategy; -import org.apache.ivy.plugins.circular.WarnCircularDependencyStrategy; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.conflict.LatestConflictManager; -import org.apache.ivy.plugins.conflict.NoConflictManager; -import org.apache.ivy.plugins.conflict.StrictConflictManager; -import org.apache.ivy.plugins.latest.LatestLexicographicStrategy; -import org.apache.ivy.plugins.latest.LatestRevisionStrategy; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.plugins.latest.LatestTimeStrategy; -import org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher; -import org.apache.ivy.plugins.matcher.ExactPatternMatcher; -import org.apache.ivy.plugins.matcher.ModuleIdMatcher; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.matcher.RegexpPatternMatcher; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.ivy.plugins.report.LogReportOutputter; -import org.apache.ivy.plugins.report.ReportOutputter; -import org.apache.ivy.plugins.report.XmlReportOutputter; -import org.apache.ivy.plugins.resolver.ChainResolver; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.plugins.resolver.DualResolver; -import org.apache.ivy.plugins.trigger.Trigger; -import org.apache.ivy.plugins.version.ChainVersionMatcher; -import org.apache.ivy.plugins.version.ExactVersionMatcher; -import org.apache.ivy.plugins.version.LatestVersionMatcher; -import org.apache.ivy.plugins.version.SubVersionMatcher; -import org.apache.ivy.plugins.version.VersionMatcher; -import org.apache.ivy.plugins.version.VersionRangeMatcher; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.url.URLHandlerRegistry; - -public class IvySettings { - private static final String DEFAULT_CACHE_ARTIFACT_PATTERN = "[organisation]/[module]/[type]s/[artifact]-[revision](.[ext])"; - - private static final String DEFAULT_CACHE_DATA_FILE_PATTERN = "[organisation]/[module]/ivydata-[revision].properties"; - - private static final String DEFAULT_CACHE_IVY_PATTERN = "[organisation]/[module]/ivy-[revision].xml"; - - private static final String DEFAULT_CACHE_RESOLVED_IVY_PATTERN = "resolved-[organisation]-[module]-[revision].xml"; - - private static final String DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN = "resolved-[organisation]-[module]-[revision].properties"; - - private Map typeDefs = new HashMap(); - - private Map resolversMap = new HashMap(); - - private DependencyResolver defaultResolver; - - private DependencyResolver dictatorResolver = null; - - private String defaultResolverName; - - private File defaultCache; - - private String defaultBranch = null; - - private boolean checkUpToDate = true; - - private Map moduleSettings = new LinkedHashMap(); // Map (ModuleIdMatcher -> ModuleSettings) - - private Map conflictsManager = new HashMap(); // Map (String conflictManagerName -> - - // ConflictManager) - - private Map latestStrategies = new HashMap(); // Map (String latestStrategyName -> - - // LatestStrategy) - - private Map namespaces = new HashMap(); // Map (String namespaceName -> Namespace) - - private Map matchers = new HashMap(); // Map (String matcherName -> Matcher) - - private Map reportOutputters = new HashMap(); // Map (String outputterName -> ReportOutputter) - - private Map versionMatchers = new HashMap(); // Map (String matcherName -> VersionMatcher) - - private Map circularDependencyStrategies = new HashMap(); // Map (String name -> - - // CircularDependencyStrategy) - - private List triggers = new ArrayList(); // List (Trigger) - - private IvyVariableContainer variableContainer = new IvyVariableContainerImpl(); - - private String cacheIvyPattern = DEFAULT_CACHE_IVY_PATTERN; - - private String cacheResolvedIvyPattern = DEFAULT_CACHE_RESOLVED_IVY_PATTERN; - - private String cacheResolvedIvyPropertiesPattern = DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN; - - private String cacheArtifactPattern = DEFAULT_CACHE_ARTIFACT_PATTERN; - - private String cacheDataFilePattern = DEFAULT_CACHE_DATA_FILE_PATTERN; - - private boolean validate = true; - - private LatestStrategy defaultLatestStrategy = null; - - private ConflictManager defaultConflictManager = null; - - private CircularDependencyStrategy circularDependencyStrategy = null; - - private List listingIgnore = new ArrayList(); - - private boolean repositoriesConfigured; - - private boolean useRemoteConfig = false; - - private File defaultUserDir; - - private List classpathURLs = new ArrayList(); - - private ClassLoader classloader; - - private long interruptTimeout = 2000; - - private Boolean debugConflictResolution; - - private boolean logNotConvertedExclusionRule; - - private VersionMatcher versionMatcher; - - private StatusManager statusManager; - - public IvySettings() { - this(new IvyVariableContainerImpl()); - } - - public IvySettings(IvyVariableContainer variableContainer) { - setVariableContainer(variableContainer); - setVariable("ivy.default.settings.dir", getDefaultSettingsDir(), true); - setDeprecatedVariable("ivy.default.conf.dir", "ivy.default.settings.dir"); - - String ivyTypeDefs = System.getProperty("ivy.typedef.files"); - if (ivyTypeDefs != null) { - String[] files = ivyTypeDefs.split("\\,"); - for (int i = 0; i < files.length; i++) { - try { - typeDefs(new FileInputStream(new File(files[i].trim())), true); - } catch (FileNotFoundException e) { - Message.warn("typedefs file not found: " + files[i].trim()); - } catch (IOException e) { - Message.warn("problem with typedef file: " + files[i].trim() + ": " - + e.getMessage()); - } - } - } else { - try { - typeDefs(getSettingsURL("typedef.properties").openStream(), true); - } catch (IOException e) { - Message.warn("impossible to load default type defs"); - } - } - LatestLexicographicStrategy latestLexicographicStrategy = new LatestLexicographicStrategy(); - LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); - LatestTimeStrategy latestTimeStrategy = new LatestTimeStrategy(); - - addLatestStrategy("latest-revision", latestRevisionStrategy); - addLatestStrategy("latest-lexico", latestLexicographicStrategy); - addLatestStrategy("latest-time", latestTimeStrategy); - - addConflictManager("latest-revision", new LatestConflictManager("latest-revision", - latestRevisionStrategy)); - addConflictManager("latest-time", new LatestConflictManager("latest-time", - latestTimeStrategy)); - addConflictManager("all", new NoConflictManager()); - addConflictManager("strict", new StrictConflictManager()); - - addMatcher(ExactPatternMatcher.INSTANCE); - addMatcher(RegexpPatternMatcher.INSTANCE); - addMatcher(ExactOrRegexpPatternMatcher.INSTANCE); - - try { - // GlobPatternMatcher is optional. Only add it when available. - Class globClazz = IvySettings.class.getClassLoader().loadClass( - "org.apache.ivy.plugins.matcher.GlobPatternMatcher"); - Field instanceField = globClazz.getField("INSTANCE"); - addMatcher((PatternMatcher) instanceField.get(null)); - } catch (Exception e) { - // ignore: the matcher isn't on the classpath - Message - .info("impossible to define glob matcher: org.apache.ivy.plugins.matcher.GlobPatternMatcher was not found on the classpath"); - } - - addReportOutputter(new XmlReportOutputter()); - addReportOutputter(new LogReportOutputter()); - - configureDefaultCircularDependencyStrategies(); - - listingIgnore.add(".cvsignore"); - listingIgnore.add("CVS"); - listingIgnore.add(".svn"); - - addSystemProperties(); - } - - private void addSystemProperties() { - addAllVariables(System.getProperties()); - } - - /** - * Call this method to ask ivy to configure some variables using either a remote or a local - * properties file - */ - public void configureRepositories(boolean remote) { - if (!repositoriesConfigured) { - Properties props = new Properties(); - boolean configured = false; - if (useRemoteConfig && remote) { - try { - URL url = new URL("http://incubator.apache.org/ivy/repository.properties"); - Message.verbose("configuring repositories with " + url); - props.load(URLHandlerRegistry.getDefault().openStream(url)); - configured = true; - } catch (Exception ex) { - Message.verbose("unable to use remote repository configuration: " - + ex.getMessage()); - props = new Properties(); - } - } - if (!configured) { - InputStream repositoryPropsStream = null; - try { - repositoryPropsStream = getSettingsURL("repository.properties").openStream(); - props.load(repositoryPropsStream); - } catch (IOException e) { - Message.error("unable to use internal repository configuration: " - + e.getMessage()); - if (repositoryPropsStream != null) { - try { - repositoryPropsStream.close(); - } catch (Exception ex) { - } - ; - } - } - } - addAllVariables(props, false); - repositoriesConfigured = true; - } - } - - public void typeDefs(InputStream stream) throws IOException { - typeDefs(stream, false); - } - - public void typeDefs(InputStream stream, boolean silentFail) throws IOException { - try { - Properties p = new Properties(); - p.load(stream); - typeDefs(p, silentFail); - } finally { - stream.close(); - } - } - - public void typeDefs(Properties p) { - typeDefs(p, false); - } - - public void typeDefs(Properties p, boolean silentFail) { - for (Iterator iter = p.keySet().iterator(); iter.hasNext();) { - String name = (String) iter.next(); - typeDef(name, p.getProperty(name), silentFail); - } - } - - public void load(File settingsFile) throws ParseException, IOException { - Message.info(":: loading settings :: file = " + settingsFile); - long start = System.currentTimeMillis(); - setSettingsVariables(settingsFile); - if (getVariable("ivy.default.ivy.user.dir") != null) { - setDefaultIvyUserDir(new File(getVariable("ivy.default.ivy.user.dir"))); - } else { - getDefaultIvyUserDir(); - } - getDefaultCache(); - - loadDefaultProperties(); - try { - new XmlSettingsParser(this).parse(settingsFile.toURL()); - } catch (MalformedURLException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "given file cannot be transformed to url: " + settingsFile); - iae.initCause(e); - throw iae; - } - setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir().getAbsolutePath(), false); - Message.verbose("settings loaded (" + (System.currentTimeMillis() - start) + "ms)"); - dumpSettings(); - } - - public void load(URL settingsURL) throws ParseException, IOException { - Message.info(":: loading settings :: url = " + settingsURL); - long start = System.currentTimeMillis(); - setSettingsVariables(settingsURL); - if (getVariable("ivy.default.ivy.user.dir") != null) { - setDefaultIvyUserDir(new File(getVariable("ivy.default.ivy.user.dir"))); - } else { - getDefaultIvyUserDir(); - } - getDefaultCache(); - - loadDefaultProperties(); - new XmlSettingsParser(this).parse(settingsURL); - setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir().getAbsolutePath(), false); - Message.verbose("settings loaded (" + (System.currentTimeMillis() - start) + "ms)"); - dumpSettings(); - } - - public void loadDefault() throws ParseException, IOException { - load(getDefaultSettingsURL()); - } - - public void loadDefault14() throws ParseException, IOException { - load(getDefault14SettingsURL()); - } - - private void loadDefaultProperties() throws IOException { - loadProperties(getDefaultPropertiesURL(), false); - } - - public static URL getDefaultPropertiesURL() { - return getSettingsURL("ivy.properties"); - } - - public static URL getDefaultSettingsURL() { - return getSettingsURL("ivysettings.xml"); - } - - public static URL getDefault14SettingsURL() { - return getSettingsURL("ivysettings-1.4.xml"); - } - - private String getDefaultSettingsDir() { - String ivysettingsLocation = getDefaultSettingsURL().toExternalForm(); - return ivysettingsLocation.substring(0, ivysettingsLocation.length() - - "ivysettings.xml".length() - 1); - } - - private static URL getSettingsURL(String file) { - return XmlSettingsParser.class.getResource(file); - } - - public void setSettingsVariables(File settingsFile) { - try { - setVariable("ivy.settings.dir", new File(settingsFile.getAbsolutePath()).getParent()); - setDeprecatedVariable("ivy.conf.dir", "ivy.settings.dir"); - setVariable("ivy.settings.file", settingsFile.getAbsolutePath()); - setDeprecatedVariable("ivy.conf.file", "ivy.settings.file"); - setVariable("ivy.settings.url", settingsFile.toURL().toExternalForm()); - setDeprecatedVariable("ivy.conf.url", "ivy.settings.url"); - } catch (MalformedURLException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "given file cannot be transformed to url: " + settingsFile); - iae.initCause(e); - throw iae; - } - } - - /** - * Sets a deprecated variable with the value of the new variable - * - * @param deprecatedKey - * the deprecated variable name - * @param newKey - * the new variable name - */ - private void setDeprecatedVariable(String deprecatedKey, String newKey) { - setVariable(deprecatedKey, getVariable(newKey)); - } - - public void setSettingsVariables(URL settingsURL) { - String settingsURLStr = settingsURL.toExternalForm(); - setVariable("ivy.settings.url", settingsURLStr); - setDeprecatedVariable("ivy.conf.url", "ivy.settings.url"); - int slashIndex = settingsURLStr.lastIndexOf('/'); - if (slashIndex != -1) { - setVariable("ivy.settings.dir", settingsURLStr.substring(0, slashIndex)); - setDeprecatedVariable("ivy.conf.dir", "ivy.settings.dir"); - } else { - Message - .warn("settings url does not contain any slash (/): ivy.settings.dir variable not set"); - } - } - - private void dumpSettings() { - Message.verbose("\tdefault cache: " + getDefaultCache()); - Message.verbose("\tdefault resolver: " + getDefaultResolver()); - Message.debug("\tdefault latest strategy: " + getDefaultLatestStrategy()); - Message.debug("\tdefault conflict manager: " + getDefaultConflictManager()); - Message.debug("\tcircular dependency strategy: " + getCircularDependencyStrategy()); - Message.debug("\tvalidate: " + doValidate()); - Message.debug("\tcheck up2date: " + isCheckUpToDate()); - Message.debug("\tcache ivy pattern: " + getCacheIvyPattern()); - Message.debug("\tcache artifact pattern: " + getCacheArtifactPattern()); - - if (!classpathURLs.isEmpty()) { - Message.verbose("\t-- " + classpathURLs.size() + " custom classpath urls:"); - for (Iterator iter = classpathURLs.iterator(); iter.hasNext();) { - Message.debug("\t\t" + iter.next()); - } - } - Message.verbose("\t-- " + resolversMap.size() + " resolvers:"); - for (Iterator iter = resolversMap.values().iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - resolver.dumpSettings(); - } - if (!moduleSettings.isEmpty()) { - Message.debug("\tmodule settings:"); - for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { - ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); - ModuleSettings s = (ModuleSettings) moduleSettings.get(midm); - Message.debug("\t\t" + midm + " -> " + s); - } - } - } - - public void loadProperties(URL url) throws IOException { - loadProperties(url, true); - } - - public void loadProperties(URL url, boolean overwrite) throws IOException { - loadProperties(url.openStream(), overwrite); - } - - public void loadProperties(File file) throws IOException { - loadProperties(file, true); - } - - public void loadProperties(File file, boolean overwrite) throws IOException { - loadProperties(new FileInputStream(file), overwrite); - } - - private void loadProperties(InputStream stream, boolean overwrite) throws IOException { - try { - Properties properties = new Properties(); - properties.load(stream); - addAllVariables(properties, overwrite); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - } - } - } - } - - public void setVariable(String varName, String value) { - setVariable(varName, value, true); - } - - public void setVariable(String varName, String value, boolean overwrite) { - variableContainer.setVariable(varName, value, overwrite); - } - - public void addAllVariables(Map variables) { - addAllVariables(variables, true); - } - - public void addAllVariables(Map variables, boolean overwrite) { - for (Iterator iter = variables.keySet().iterator(); iter.hasNext();) { - String key = (String) iter.next(); - String val = (String) variables.get(key); - setVariable(key, val, overwrite); - } - } - - /** - * Substitute variables in the given string by their value found in the current set of variables - * - * @param str - * the string in which substitution should be made - * @return the string where all current ivy variables have been substituted by their value - */ - public String substitute(String str) { - return IvyPatternHelper.substituteVariables(str, getVariables()); - } - - /** - * Returns the variables loaded in configuration file. Those variables may better be seen as ant - * properties - * - * @return - */ - public Map getVariables() { - return variableContainer.getVariables(); - } - - public Class typeDef(String name, String className) { - return typeDef(name, className, false); - } - - public Class typeDef(String name, String className, boolean silentFail) { - Class clazz = classForName(className, silentFail); - if (clazz != null) { - typeDefs.put(name, clazz); - } - return clazz; - } - - private Class classForName(String className, boolean silentFail) { - try { - return getClassLoader().loadClass(className); - } catch (ClassNotFoundException e) { - if (silentFail) { - Message.info("impossible to define new type: class not found: " + className - + " in " + classpathURLs + " nor Ivy classloader"); - return null; - } else { - throw new RuntimeException("impossible to define new type: class not found: " - + className + " in " + classpathURLs + " nor Ivy classloader"); - } - } - } - - private ClassLoader getClassLoader() { - if (classloader == null) { - if (classpathURLs.isEmpty()) { - classloader = Ivy.class.getClassLoader(); - } else { - classloader = new URLClassLoader((URL[]) classpathURLs - .toArray(new URL[classpathURLs.size()]), Ivy.class.getClassLoader()); - } - } - return classloader; - } - - public void addClasspathURL(URL url) { - classpathURLs.add(url); - classloader = null; - } - - public Map getTypeDefs() { - return typeDefs; - } - - public Class getTypeDef(String name) { - return (Class) typeDefs.get(name); - } - - // methods which match ivy conf method signature specs - public void addConfigured(DependencyResolver resolver) { - addResolver(resolver); - } - - public void addConfigured(ModuleDescriptorParser parser) { - ModuleDescriptorParserRegistry.getInstance().addParser(parser); - } - - public void addResolver(DependencyResolver resolver) { - if (resolver == null) { - throw new NullPointerException("null resolver"); - } - init(resolver); - resolversMap.put(resolver.getName(), resolver); - if (resolver instanceof ChainResolver) { - List subresolvers = ((ChainResolver) resolver).getResolvers(); - for (Iterator iter = subresolvers.iterator(); iter.hasNext();) { - DependencyResolver dr = (DependencyResolver) iter.next(); - addResolver(dr); - } - } else if (resolver instanceof DualResolver) { - DependencyResolver ivyResolver = ((DualResolver) resolver).getIvyResolver(); - if (ivyResolver != null) { - addResolver(ivyResolver); - } - DependencyResolver artifactResolver = ((DualResolver) resolver).getArtifactResolver(); - if (artifactResolver != null) { - addResolver(artifactResolver); - } - } - } - - public void setDefaultCache(File cacheDirectory) { - defaultCache = cacheDirectory; - } - - public void setDefaultResolver(String resolverName) { - checkResolverName(resolverName); - defaultResolverName = resolverName; - } - - private void checkResolverName(String resolverName) { - if (resolverName != null && !resolversMap.containsKey(resolverName)) { - throw new IllegalArgumentException("no resolver found called " + resolverName - + ": check your settings"); - } - } - - /** - * regular expressions as explained in Pattern class may be used in ModuleId organisation and - * name - * - * @param moduleId - * @param resolverName - * @param branch - */ - public void addModuleConfiguration(ModuleId mid, PatternMatcher matcher, String resolverName, - String branch, String conflictManager) { - checkResolverName(resolverName); - moduleSettings.put(new ModuleIdMatcher(mid, matcher), new ModuleSettings(resolverName, - branch, conflictManager)); - } - - public File getDefaultIvyUserDir() { - if (defaultUserDir == null) { - if (getVariable("ivy.home") != null) { - setDefaultIvyUserDir(new File(getVariable("ivy.home"))); - Message - .verbose("using ivy.default.ivy.user.dir variable for default ivy user dir: " - + defaultUserDir); - } else { - setDefaultIvyUserDir(new File(System.getProperty("user.home"), ".ivy")); - Message.verbose("no default ivy user dir defined: set to " + defaultUserDir); - } - } - return defaultUserDir; - } - - public void setDefaultIvyUserDir(File defaultUserDir) { - this.defaultUserDir = defaultUserDir; - setVariable("ivy.default.ivy.user.dir", this.defaultUserDir.getAbsolutePath()); - setVariable("ivy.home", this.defaultUserDir.getAbsolutePath()); - } - - public File getDefaultCache() { - if (defaultCache == null) { - defaultCache = new File(getDefaultIvyUserDir(), "cache"); - Message.verbose("no default cache defined: set to " + defaultCache); - } - return defaultCache; - } - - public void setDictatorResolver(DependencyResolver resolver) { - dictatorResolver = resolver; - } - - public DependencyResolver getResolver(ModuleId moduleId) { - if (dictatorResolver != null) { - return dictatorResolver; - } - String resolverName = getResolverName(moduleId); - return getResolver(resolverName); - } - - public DependencyResolver getResolver(String resolverName) { - if (dictatorResolver != null) { - return dictatorResolver; - } - DependencyResolver resolver = (DependencyResolver) resolversMap.get(resolverName); - if (resolver == null) { - Message.error("unknown resolver " + resolverName); - } - return resolver; - } - - public DependencyResolver getDefaultResolver() { - if (dictatorResolver != null) { - return dictatorResolver; - } - if (defaultResolver == null) { - defaultResolver = (DependencyResolver) resolversMap.get(defaultResolverName); - } - return defaultResolver; - } - - public String getResolverName(ModuleId moduleId) { - for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { - ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); - if (midm.matches(moduleId)) { - ModuleSettings ms = (ModuleSettings) moduleSettings.get(midm); - if (ms.getResolverName() != null) { - return ms.getResolverName(); - } - } - } - return defaultResolverName; - } - - public String getDefaultBranch(ModuleId moduleId) { - for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { - ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); - if (midm.matches(moduleId)) { - ModuleSettings ms = (ModuleSettings) moduleSettings.get(midm); - if (ms.getBranch() != null) { - return ms.getBranch(); - } - } - } - return getDefaultBranch(); - } - - public String getDefaultBranch() { - return defaultBranch; - } - - public void setDefaultBranch(String defaultBranch) { - this.defaultBranch = defaultBranch; - } - - public ConflictManager getConflictManager(ModuleId moduleId) { - for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { - ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); - if (midm.matches(moduleId)) { - ModuleSettings ms = (ModuleSettings) moduleSettings.get(midm); - if (ms.getConflictManager() != null) { - ConflictManager cm = getConflictManager(ms.getConflictManager()); - if (cm == null) { - throw new IllegalStateException( - "ivy badly configured: unknown conflict manager " - + ms.getConflictManager()); - } - return cm; - } - } - } - return getDefaultConflictManager(); - } - - public void addConfigured(ConflictManager cm) { - addConflictManager(cm.getName(), cm); - } - - public ConflictManager getConflictManager(String name) { - if ("default".equals(name)) { - return getDefaultConflictManager(); - } - return (ConflictManager) conflictsManager.get(name); - } - - public void addConflictManager(String name, ConflictManager cm) { - init(cm); - conflictsManager.put(name, cm); - } - - public void addConfigured(LatestStrategy latest) { - addLatestStrategy(latest.getName(), latest); - } - - public LatestStrategy getLatestStrategy(String name) { - if ("default".equals(name)) { - return getDefaultLatestStrategy(); - } - return (LatestStrategy) latestStrategies.get(name); - } - - public void addLatestStrategy(String name, LatestStrategy latest) { - init(latest); - latestStrategies.put(name, latest); - } - - public void addConfigured(Namespace ns) { - addNamespace(ns); - } - - public Namespace getNamespace(String name) { - if ("system".equals(name)) { - return getSystemNamespace(); - } - return (Namespace) namespaces.get(name); - } - - public Namespace getSystemNamespace() { - return Namespace.SYSTEM_NAMESPACE; - } - - public void addNamespace(Namespace ns) { - init(ns); - namespaces.put(ns.getName(), ns); - } - - public void addConfigured(PatternMatcher m) { - addMatcher(m); - } - - public PatternMatcher getMatcher(String name) { - return (PatternMatcher) matchers.get(name); - } - - public void addMatcher(PatternMatcher m) { - init(m); - matchers.put(m.getName(), m); - } - - public void addConfigured(ReportOutputter outputter) { - addReportOutputter(outputter); - } - - public ReportOutputter getReportOutputter(String name) { - return (ReportOutputter) reportOutputters.get(name); - } - - public void addReportOutputter(ReportOutputter outputter) { - init(outputter); - reportOutputters.put(outputter.getName(), outputter); - } - - public ReportOutputter[] getReportOutputters() { - return (ReportOutputter[]) reportOutputters.values().toArray( - new ReportOutputter[reportOutputters.size()]); - } - - public void addConfigured(VersionMatcher vmatcher) { - addVersionMatcher(vmatcher); - } - - public VersionMatcher getVersionMatcher(String name) { - return (VersionMatcher) versionMatchers.get(name); - } - - public void addVersionMatcher(VersionMatcher vmatcher) { - init(vmatcher); - versionMatchers.put(vmatcher.getName(), vmatcher); - - if (versionMatcher == null) { - versionMatcher = new ChainVersionMatcher(); - addVersionMatcher(new ExactVersionMatcher()); - } - if (versionMatcher instanceof ChainVersionMatcher) { - ChainVersionMatcher chain = (ChainVersionMatcher) versionMatcher; - chain.add(vmatcher); - } - } - - public VersionMatcher[] getVersionMatchers() { - return (VersionMatcher[]) versionMatchers.values().toArray( - new VersionMatcher[versionMatchers.size()]); - } - - public VersionMatcher getVersionMatcher() { - if (versionMatcher == null) { - configureDefaultVersionMatcher(); - } - return versionMatcher; - } - - public void configureDefaultVersionMatcher() { - addVersionMatcher(new LatestVersionMatcher()); - addVersionMatcher(new SubVersionMatcher()); - addVersionMatcher(new VersionRangeMatcher()); - } - - public CircularDependencyStrategy getCircularDependencyStrategy() { - if (circularDependencyStrategy == null) { - circularDependencyStrategy = getCircularDependencyStrategy("default"); - } - return circularDependencyStrategy; - } - - public CircularDependencyStrategy getCircularDependencyStrategy(String name) { - if ("default".equals(name)) { - name = "warn"; - } - return (CircularDependencyStrategy) circularDependencyStrategies.get(name); - } - - public void setCircularDependencyStrategy(CircularDependencyStrategy strategy) { - circularDependencyStrategy = strategy; - } - - public void addConfigured(CircularDependencyStrategy strategy) { - addCircularDependencyStrategy(strategy); - } - - private void addCircularDependencyStrategy(CircularDependencyStrategy strategy) { - circularDependencyStrategies.put(strategy.getName(), strategy); - } - - private void configureDefaultCircularDependencyStrategies() { - addCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance()); - addCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); - addCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance()); - } - - public StatusManager getStatusManager() { - if (statusManager == null) { - statusManager = StatusManager.newDefaultInstance(); - } - return statusManager; - } - - public void setStatusManager(StatusManager statusManager) { - this.statusManager = statusManager; - } - - /** - * Returns true if the name should be ignored in listing - * - * @param name - * @return - */ - public boolean listingIgnore(String name) { - return listingIgnore.contains(name); - } - - /** - * Filters the names list by removing all names that should be ignored as defined by the listing - * ignore list - * - * @param names - */ - public void filterIgnore(Collection names) { - names.removeAll(listingIgnore); - } - - public boolean isCheckUpToDate() { - return checkUpToDate; - } - - public void setCheckUpToDate(boolean checkUpToDate) { - this.checkUpToDate = checkUpToDate; - } - - public String getCacheArtifactPattern() { - return cacheArtifactPattern; - } - - public void setCacheArtifactPattern(String cacheArtifactPattern) { - this.cacheArtifactPattern = cacheArtifactPattern; - } - - public String getCacheIvyPattern() { - return cacheIvyPattern; - } - - public void setCacheIvyPattern(String cacheIvyPattern) { - this.cacheIvyPattern = cacheIvyPattern; - } - - public String getCacheDataFilePattern() { - return cacheDataFilePattern; - } - - public boolean doValidate() { - return validate; - } - - public void setValidate(boolean validate) { - this.validate = validate; - } - - public String getVariable(String name) { - return variableContainer.getVariable(name); - } - - public ConflictManager getDefaultConflictManager() { - if (defaultConflictManager == null) { - defaultConflictManager = new LatestConflictManager(getDefaultLatestStrategy()); - } - return defaultConflictManager; - } - - public void setDefaultConflictManager(ConflictManager defaultConflictManager) { - this.defaultConflictManager = defaultConflictManager; - } - - public LatestStrategy getDefaultLatestStrategy() { - if (defaultLatestStrategy == null) { - defaultLatestStrategy = new LatestRevisionStrategy(); - } - return defaultLatestStrategy; - } - - public void setDefaultLatestStrategy(LatestStrategy defaultLatestStrategy) { - this.defaultLatestStrategy = defaultLatestStrategy; - } - - public void addTrigger(Trigger trigger) { - init(trigger); - triggers.add(trigger); - } - - public List getTriggers() { - return triggers; - } - - public void addConfigured(Trigger trigger) { - addTrigger(trigger); - } - - public boolean isUseRemoteConfig() { - return useRemoteConfig; - } - - public void setUseRemoteConfig(boolean useRemoteConfig) { - this.useRemoteConfig = useRemoteConfig; - } - - public boolean logModulesInUse() { - String var = getVariable("ivy.log.modules.in.use"); - return var == null || Boolean.valueOf(var).booleanValue(); - } - - public boolean logModuleWhenFound() { - String var = getVariable("ivy.log.module.when.found"); - return var == null || Boolean.valueOf(var).booleanValue(); - } - - public boolean logResolvedRevision() { - String var = getVariable("ivy.log.resolved.revision"); - return var == null || Boolean.valueOf(var).booleanValue(); - } - - public boolean debugConflictResolution() { - if (debugConflictResolution == null) { - String var = getVariable("ivy.log.conflict.resolution"); - debugConflictResolution = Boolean.valueOf(var != null - && Boolean.valueOf(var).booleanValue()); - } - return debugConflictResolution.booleanValue(); - } - - public boolean logNotConvertedExclusionRule() { - return logNotConvertedExclusionRule; - } - - public void setLogNotConvertedExclusionRule(boolean logNotConvertedExclusionRule) { - this.logNotConvertedExclusionRule = logNotConvertedExclusionRule; - } - - private void init(Object obj) { - if (obj instanceof IvySettingsAware) { - ((IvySettingsAware) obj).setSettings(this); - } - if (obj instanceof IvyAware) { - // TODO - // ((IvyAware)obj).setIvy(this); - } - } - - private static class ModuleSettings { - private String _resolverName; - - private String _branch; - - private String _conflictManager; - - public ModuleSettings(String resolverName, String branch, String conflictManager) { - _resolverName = resolverName; - _branch = branch; - _conflictManager = conflictManager; - } - - public String toString() { - return _resolverName != null ? "resolver: " + _resolverName - : "" + _branch != null ? "branch: " + _branch : ""; - } - - public String getBranch() { - return _branch; - } - - public String getResolverName() { - return _resolverName; - } - - protected String getConflictManager() { - return _conflictManager; - } - } - - public String getCacheResolvedIvyPattern() { - return cacheResolvedIvyPattern; - } - - public String getCacheResolvedIvyPropertiesPattern() { - return cacheResolvedIvyPropertiesPattern; - } - - public long getInterruptTimeout() { - return interruptTimeout; - } - - public Collection getResolvers() { - return resolversMap.values(); - } - - public Collection getResolverNames() { - return resolversMap.keySet(); - } - - public Collection getMatcherNames() { - return matchers.keySet(); - } - - public IvyVariableContainer getVariableContainer() { - return variableContainer; - } - - /** - * Use a different variable container. - * - * @param variables - */ - public void setVariableContainer(IvyVariableContainer variables) { - variableContainer = variables; - } - -} +/* + * 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.core.settings; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.status.StatusManager; +import org.apache.ivy.plugins.IvyAware; +import org.apache.ivy.plugins.IvySettingsAware; +import org.apache.ivy.plugins.circular.CircularDependencyStrategy; +import org.apache.ivy.plugins.circular.ErrorCircularDependencyStrategy; +import org.apache.ivy.plugins.circular.IgnoreCircularDependencyStrategy; +import org.apache.ivy.plugins.circular.WarnCircularDependencyStrategy; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.conflict.LatestConflictManager; +import org.apache.ivy.plugins.conflict.NoConflictManager; +import org.apache.ivy.plugins.conflict.StrictConflictManager; +import org.apache.ivy.plugins.latest.LatestLexicographicStrategy; +import org.apache.ivy.plugins.latest.LatestRevisionStrategy; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.plugins.latest.LatestTimeStrategy; +import org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher; +import org.apache.ivy.plugins.matcher.ExactPatternMatcher; +import org.apache.ivy.plugins.matcher.ModuleIdMatcher; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.matcher.RegexpPatternMatcher; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.ivy.plugins.report.LogReportOutputter; +import org.apache.ivy.plugins.report.ReportOutputter; +import org.apache.ivy.plugins.report.XmlReportOutputter; +import org.apache.ivy.plugins.resolver.ChainResolver; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.plugins.resolver.DualResolver; +import org.apache.ivy.plugins.trigger.Trigger; +import org.apache.ivy.plugins.version.ChainVersionMatcher; +import org.apache.ivy.plugins.version.ExactVersionMatcher; +import org.apache.ivy.plugins.version.LatestVersionMatcher; +import org.apache.ivy.plugins.version.SubVersionMatcher; +import org.apache.ivy.plugins.version.VersionMatcher; +import org.apache.ivy.plugins.version.VersionRangeMatcher; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.url.URLHandlerRegistry; + +public class IvySettings { + private static final String DEFAULT_CACHE_ARTIFACT_PATTERN = "[organisation]/[module]/[type]s/[artifact]-[revision](.[ext])"; + + private static final String DEFAULT_CACHE_DATA_FILE_PATTERN = "[organisation]/[module]/ivydata-[revision].properties"; + + private static final String DEFAULT_CACHE_IVY_PATTERN = "[organisation]/[module]/ivy-[revision].xml"; + + private static final String DEFAULT_CACHE_RESOLVED_IVY_PATTERN = "resolved-[organisation]-[module]-[revision].xml"; + + private static final String DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN = "resolved-[organisation]-[module]-[revision].properties"; + + private Map typeDefs = new HashMap(); + + private Map resolversMap = new HashMap(); + + private DependencyResolver defaultResolver; + + private DependencyResolver dictatorResolver = null; + + private String defaultResolverName; + + private File defaultCache; + + private String defaultBranch = null; + + private boolean checkUpToDate = true; + + private Map moduleSettings = new LinkedHashMap(); // Map (ModuleIdMatcher -> ModuleSettings) + + private Map conflictsManager = new HashMap(); // Map (String conflictManagerName -> + + // ConflictManager) + + private Map latestStrategies = new HashMap(); // Map (String latestStrategyName -> + + // LatestStrategy) + + private Map namespaces = new HashMap(); // Map (String namespaceName -> Namespace) + + private Map matchers = new HashMap(); // Map (String matcherName -> Matcher) + + private Map reportOutputters = new HashMap(); // Map (String outputterName -> ReportOutputter) + + private Map versionMatchers = new HashMap(); // Map (String matcherName -> VersionMatcher) + + private Map circularDependencyStrategies = new HashMap(); // Map (String name -> + + // CircularDependencyStrategy) + + private List triggers = new ArrayList(); // List (Trigger) + + private IvyVariableContainer variableContainer = new IvyVariableContainerImpl(); + + private String cacheIvyPattern = DEFAULT_CACHE_IVY_PATTERN; + + private String cacheResolvedIvyPattern = DEFAULT_CACHE_RESOLVED_IVY_PATTERN; + + private String cacheResolvedIvyPropertiesPattern = DEFAULT_CACHE_RESOLVED_IVY_PROPERTIES_PATTERN; + + private String cacheArtifactPattern = DEFAULT_CACHE_ARTIFACT_PATTERN; + + private String cacheDataFilePattern = DEFAULT_CACHE_DATA_FILE_PATTERN; + + private boolean validate = true; + + private LatestStrategy defaultLatestStrategy = null; + + private ConflictManager defaultConflictManager = null; + + private CircularDependencyStrategy circularDependencyStrategy = null; + + private List listingIgnore = new ArrayList(); + + private boolean repositoriesConfigured; + + private boolean useRemoteConfig = false; + + private File defaultUserDir; + + private List classpathURLs = new ArrayList(); + + private ClassLoader classloader; + + private long interruptTimeout = 2000; + + private Boolean debugConflictResolution; + + private boolean logNotConvertedExclusionRule; + + private VersionMatcher versionMatcher; + + private StatusManager statusManager; + + public IvySettings() { + this(new IvyVariableContainerImpl()); + } + + public IvySettings(IvyVariableContainer variableContainer) { + setVariableContainer(variableContainer); + setVariable("ivy.default.settings.dir", getDefaultSettingsDir(), true); + setDeprecatedVariable("ivy.default.conf.dir", "ivy.default.settings.dir"); + + String ivyTypeDefs = System.getProperty("ivy.typedef.files"); + if (ivyTypeDefs != null) { + String[] files = ivyTypeDefs.split("\\,"); + for (int i = 0; i < files.length; i++) { + try { + typeDefs(new FileInputStream(new File(files[i].trim())), true); + } catch (FileNotFoundException e) { + Message.warn("typedefs file not found: " + files[i].trim()); + } catch (IOException e) { + Message.warn("problem with typedef file: " + files[i].trim() + ": " + + e.getMessage()); + } + } + } else { + try { + typeDefs(getSettingsURL("typedef.properties").openStream(), true); + } catch (IOException e) { + Message.warn("impossible to load default type defs"); + } + } + LatestLexicographicStrategy latestLexicographicStrategy = new LatestLexicographicStrategy(); + LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); + LatestTimeStrategy latestTimeStrategy = new LatestTimeStrategy(); + + addLatestStrategy("latest-revision", latestRevisionStrategy); + addLatestStrategy("latest-lexico", latestLexicographicStrategy); + addLatestStrategy("latest-time", latestTimeStrategy); + + addConflictManager("latest-revision", new LatestConflictManager("latest-revision", + latestRevisionStrategy)); + addConflictManager("latest-time", new LatestConflictManager("latest-time", + latestTimeStrategy)); + addConflictManager("all", new NoConflictManager()); + addConflictManager("strict", new StrictConflictManager()); + + addMatcher(ExactPatternMatcher.INSTANCE); + addMatcher(RegexpPatternMatcher.INSTANCE); + addMatcher(ExactOrRegexpPatternMatcher.INSTANCE); + + try { + // GlobPatternMatcher is optional. Only add it when available. + Class globClazz = IvySettings.class.getClassLoader().loadClass( + "org.apache.ivy.plugins.matcher.GlobPatternMatcher"); + Field instanceField = globClazz.getField("INSTANCE"); + addMatcher((PatternMatcher) instanceField.get(null)); + } catch (Exception e) { + // ignore: the matcher isn't on the classpath + Message + .info("impossible to define glob matcher: org.apache.ivy.plugins.matcher.GlobPatternMatcher was not found on the classpath"); + } + + addReportOutputter(new XmlReportOutputter()); + addReportOutputter(new LogReportOutputter()); + + configureDefaultCircularDependencyStrategies(); + + listingIgnore.add(".cvsignore"); + listingIgnore.add("CVS"); + listingIgnore.add(".svn"); + + addSystemProperties(); + } + + private void addSystemProperties() { + addAllVariables(System.getProperties()); + } + + /** + * Call this method to ask ivy to configure some variables using either a remote or a local + * properties file + */ + public void configureRepositories(boolean remote) { + if (!repositoriesConfigured) { + Properties props = new Properties(); + boolean configured = false; + if (useRemoteConfig && remote) { + try { + URL url = new URL("http://incubator.apache.org/ivy/repository.properties"); + Message.verbose("configuring repositories with " + url); + props.load(URLHandlerRegistry.getDefault().openStream(url)); + configured = true; + } catch (Exception ex) { + Message.verbose("unable to use remote repository configuration: " + + ex.getMessage()); + props = new Properties(); + } + } + if (!configured) { + InputStream repositoryPropsStream = null; + try { + repositoryPropsStream = getSettingsURL("repository.properties").openStream(); + props.load(repositoryPropsStream); + } catch (IOException e) { + Message.error("unable to use internal repository configuration: " + + e.getMessage()); + if (repositoryPropsStream != null) { + try { + repositoryPropsStream.close(); + } catch (Exception ex) { + } + ; + } + } + } + addAllVariables(props, false); + repositoriesConfigured = true; + } + } + + public void typeDefs(InputStream stream) throws IOException { + typeDefs(stream, false); + } + + public void typeDefs(InputStream stream, boolean silentFail) throws IOException { + try { + Properties p = new Properties(); + p.load(stream); + typeDefs(p, silentFail); + } finally { + stream.close(); + } + } + + public void typeDefs(Properties p) { + typeDefs(p, false); + } + + public void typeDefs(Properties p, boolean silentFail) { + for (Iterator iter = p.keySet().iterator(); iter.hasNext();) { + String name = (String) iter.next(); + typeDef(name, p.getProperty(name), silentFail); + } + } + + public void load(File settingsFile) throws ParseException, IOException { + Message.info(":: loading settings :: file = " + settingsFile); + long start = System.currentTimeMillis(); + setSettingsVariables(settingsFile); + if (getVariable("ivy.default.ivy.user.dir") != null) { + setDefaultIvyUserDir(new File(getVariable("ivy.default.ivy.user.dir"))); + } else { + getDefaultIvyUserDir(); + } + getDefaultCache(); + + loadDefaultProperties(); + try { + new XmlSettingsParser(this).parse(settingsFile.toURL()); + } catch (MalformedURLException e) { + IllegalArgumentException iae = new IllegalArgumentException( + "given file cannot be transformed to url: " + settingsFile); + iae.initCause(e); + throw iae; + } + setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir().getAbsolutePath(), false); + Message.verbose("settings loaded (" + (System.currentTimeMillis() - start) + "ms)"); + dumpSettings(); + } + + public void load(URL settingsURL) throws ParseException, IOException { + Message.info(":: loading settings :: url = " + settingsURL); + long start = System.currentTimeMillis(); + setSettingsVariables(settingsURL); + if (getVariable("ivy.default.ivy.user.dir") != null) { + setDefaultIvyUserDir(new File(getVariable("ivy.default.ivy.user.dir"))); + } else { + getDefaultIvyUserDir(); + } + getDefaultCache(); + + loadDefaultProperties(); + new XmlSettingsParser(this).parse(settingsURL); + setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir().getAbsolutePath(), false); + Message.verbose("settings loaded (" + (System.currentTimeMillis() - start) + "ms)"); + dumpSettings(); + } + + public void loadDefault() throws ParseException, IOException { + load(getDefaultSettingsURL()); + } + + public void loadDefault14() throws ParseException, IOException { + load(getDefault14SettingsURL()); + } + + private void loadDefaultProperties() throws IOException { + loadProperties(getDefaultPropertiesURL(), false); + } + + public static URL getDefaultPropertiesURL() { + return getSettingsURL("ivy.properties"); + } + + public static URL getDefaultSettingsURL() { + return getSettingsURL("ivysettings.xml"); + } + + public static URL getDefault14SettingsURL() { + return getSettingsURL("ivysettings-1.4.xml"); + } + + private String getDefaultSettingsDir() { + String ivysettingsLocation = getDefaultSettingsURL().toExternalForm(); + return ivysettingsLocation.substring(0, ivysettingsLocation.length() + - "ivysettings.xml".length() - 1); + } + + private static URL getSettingsURL(String file) { + return XmlSettingsParser.class.getResource(file); + } + + public void setSettingsVariables(File settingsFile) { + try { + setVariable("ivy.settings.dir", new File(settingsFile.getAbsolutePath()).getParent()); + setDeprecatedVariable("ivy.conf.dir", "ivy.settings.dir"); + setVariable("ivy.settings.file", settingsFile.getAbsolutePath()); + setDeprecatedVariable("ivy.conf.file", "ivy.settings.file"); + setVariable("ivy.settings.url", settingsFile.toURL().toExternalForm()); + setDeprecatedVariable("ivy.conf.url", "ivy.settings.url"); + } catch (MalformedURLException e) { + IllegalArgumentException iae = new IllegalArgumentException( + "given file cannot be transformed to url: " + settingsFile); + iae.initCause(e); + throw iae; + } + } + + /** + * Sets a deprecated variable with the value of the new variable + * + * @param deprecatedKey + * the deprecated variable name + * @param newKey + * the new variable name + */ + private void setDeprecatedVariable(String deprecatedKey, String newKey) { + setVariable(deprecatedKey, getVariable(newKey)); + } + + public void setSettingsVariables(URL settingsURL) { + String settingsURLStr = settingsURL.toExternalForm(); + setVariable("ivy.settings.url", settingsURLStr); + setDeprecatedVariable("ivy.conf.url", "ivy.settings.url"); + int slashIndex = settingsURLStr.lastIndexOf('/'); + if (slashIndex != -1) { + setVariable("ivy.settings.dir", settingsURLStr.substring(0, slashIndex)); + setDeprecatedVariable("ivy.conf.dir", "ivy.settings.dir"); + } else { + Message + .warn("settings url does not contain any slash (/): ivy.settings.dir variable not set"); + } + } + + private void dumpSettings() { + Message.verbose("\tdefault cache: " + getDefaultCache()); + Message.verbose("\tdefault resolver: " + getDefaultResolver()); + Message.debug("\tdefault latest strategy: " + getDefaultLatestStrategy()); + Message.debug("\tdefault conflict manager: " + getDefaultConflictManager()); + Message.debug("\tcircular dependency strategy: " + getCircularDependencyStrategy()); + Message.debug("\tvalidate: " + doValidate()); + Message.debug("\tcheck up2date: " + isCheckUpToDate()); + Message.debug("\tcache ivy pattern: " + getCacheIvyPattern()); + Message.debug("\tcache artifact pattern: " + getCacheArtifactPattern()); + + if (!classpathURLs.isEmpty()) { + Message.verbose("\t-- " + classpathURLs.size() + " custom classpath urls:"); + for (Iterator iter = classpathURLs.iterator(); iter.hasNext();) { + Message.debug("\t\t" + iter.next()); + } + } + Message.verbose("\t-- " + resolversMap.size() + " resolvers:"); + for (Iterator iter = resolversMap.values().iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + resolver.dumpSettings(); + } + if (!moduleSettings.isEmpty()) { + Message.debug("\tmodule settings:"); + for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { + ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); + ModuleSettings s = (ModuleSettings) moduleSettings.get(midm); + Message.debug("\t\t" + midm + " -> " + s); + } + } + } + + public void loadProperties(URL url) throws IOException { + loadProperties(url, true); + } + + public void loadProperties(URL url, boolean overwrite) throws IOException { + loadProperties(url.openStream(), overwrite); + } + + public void loadProperties(File file) throws IOException { + loadProperties(file, true); + } + + public void loadProperties(File file, boolean overwrite) throws IOException { + loadProperties(new FileInputStream(file), overwrite); + } + + private void loadProperties(InputStream stream, boolean overwrite) throws IOException { + try { + Properties properties = new Properties(); + properties.load(stream); + addAllVariables(properties, overwrite); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + } + } + } + } + + public void setVariable(String varName, String value) { + setVariable(varName, value, true); + } + + public void setVariable(String varName, String value, boolean overwrite) { + variableContainer.setVariable(varName, value, overwrite); + } + + public void addAllVariables(Map variables) { + addAllVariables(variables, true); + } + + public void addAllVariables(Map variables, boolean overwrite) { + for (Iterator iter = variables.keySet().iterator(); iter.hasNext();) { + String key = (String) iter.next(); + String val = (String) variables.get(key); + setVariable(key, val, overwrite); + } + } + + /** + * Substitute variables in the given string by their value found in the current set of variables + * + * @param str + * the string in which substitution should be made + * @return the string where all current ivy variables have been substituted by their value + */ + public String substitute(String str) { + return IvyPatternHelper.substituteVariables(str, getVariables()); + } + + /** + * Returns the variables loaded in configuration file. Those variables may better be seen as ant + * properties + * + * @return + */ + public Map getVariables() { + return variableContainer.getVariables(); + } + + public Class typeDef(String name, String className) { + return typeDef(name, className, false); + } + + public Class typeDef(String name, String className, boolean silentFail) { + Class clazz = classForName(className, silentFail); + if (clazz != null) { + typeDefs.put(name, clazz); + } + return clazz; + } + + private Class classForName(String className, boolean silentFail) { + try { + return getClassLoader().loadClass(className); + } catch (ClassNotFoundException e) { + if (silentFail) { + Message.info("impossible to define new type: class not found: " + className + + " in " + classpathURLs + " nor Ivy classloader"); + return null; + } else { + throw new RuntimeException("impossible to define new type: class not found: " + + className + " in " + classpathURLs + " nor Ivy classloader"); + } + } + } + + private ClassLoader getClassLoader() { + if (classloader == null) { + if (classpathURLs.isEmpty()) { + classloader = Ivy.class.getClassLoader(); + } else { + classloader = new URLClassLoader((URL[]) classpathURLs + .toArray(new URL[classpathURLs.size()]), Ivy.class.getClassLoader()); + } + } + return classloader; + } + + public void addClasspathURL(URL url) { + classpathURLs.add(url); + classloader = null; + } + + public Map getTypeDefs() { + return typeDefs; + } + + public Class getTypeDef(String name) { + return (Class) typeDefs.get(name); + } + + // methods which match ivy conf method signature specs + public void addConfigured(DependencyResolver resolver) { + addResolver(resolver); + } + + public void addConfigured(ModuleDescriptorParser parser) { + ModuleDescriptorParserRegistry.getInstance().addParser(parser); + } + + public void addResolver(DependencyResolver resolver) { + if (resolver == null) { + throw new NullPointerException("null resolver"); + } + init(resolver); + resolversMap.put(resolver.getName(), resolver); + if (resolver instanceof ChainResolver) { + List subresolvers = ((ChainResolver) resolver).getResolvers(); + for (Iterator iter = subresolvers.iterator(); iter.hasNext();) { + DependencyResolver dr = (DependencyResolver) iter.next(); + addResolver(dr); + } + } else if (resolver instanceof DualResolver) { + DependencyResolver ivyResolver = ((DualResolver) resolver).getIvyResolver(); + if (ivyResolver != null) { + addResolver(ivyResolver); + } + DependencyResolver artifactResolver = ((DualResolver) resolver).getArtifactResolver(); + if (artifactResolver != null) { + addResolver(artifactResolver); + } + } + } + + public void setDefaultCache(File cacheDirectory) { + defaultCache = cacheDirectory; + } + + public void setDefaultResolver(String resolverName) { + checkResolverName(resolverName); + defaultResolverName = resolverName; + } + + private void checkResolverName(String resolverName) { + if (resolverName != null && !resolversMap.containsKey(resolverName)) { + throw new IllegalArgumentException("no resolver found called " + resolverName + + ": check your settings"); + } + } + + /** + * regular expressions as explained in Pattern class may be used in ModuleId organisation and + * name + * + * @param moduleId + * @param resolverName + * @param branch + */ + public void addModuleConfiguration(ModuleId mid, PatternMatcher matcher, String resolverName, + String branch, String conflictManager) { + checkResolverName(resolverName); + moduleSettings.put(new ModuleIdMatcher(mid, matcher), new ModuleSettings(resolverName, + branch, conflictManager)); + } + + public File getDefaultIvyUserDir() { + if (defaultUserDir == null) { + if (getVariable("ivy.home") != null) { + setDefaultIvyUserDir(new File(getVariable("ivy.home"))); + Message + .verbose("using ivy.default.ivy.user.dir variable for default ivy user dir: " + + defaultUserDir); + } else { + setDefaultIvyUserDir(new File(System.getProperty("user.home"), ".ivy")); + Message.verbose("no default ivy user dir defined: set to " + defaultUserDir); + } + } + return defaultUserDir; + } + + public void setDefaultIvyUserDir(File defaultUserDir) { + this.defaultUserDir = defaultUserDir; + setVariable("ivy.default.ivy.user.dir", this.defaultUserDir.getAbsolutePath()); + setVariable("ivy.home", this.defaultUserDir.getAbsolutePath()); + } + + public File getDefaultCache() { + if (defaultCache == null) { + defaultCache = new File(getDefaultIvyUserDir(), "cache"); + Message.verbose("no default cache defined: set to " + defaultCache); + } + return defaultCache; + } + + public void setDictatorResolver(DependencyResolver resolver) { + dictatorResolver = resolver; + } + + public DependencyResolver getResolver(ModuleId moduleId) { + if (dictatorResolver != null) { + return dictatorResolver; + } + String resolverName = getResolverName(moduleId); + return getResolver(resolverName); + } + + public DependencyResolver getResolver(String resolverName) { + if (dictatorResolver != null) { + return dictatorResolver; + } + DependencyResolver resolver = (DependencyResolver) resolversMap.get(resolverName); + if (resolver == null) { + Message.error("unknown resolver " + resolverName); + } + return resolver; + } + + public DependencyResolver getDefaultResolver() { + if (dictatorResolver != null) { + return dictatorResolver; + } + if (defaultResolver == null) { + defaultResolver = (DependencyResolver) resolversMap.get(defaultResolverName); + } + return defaultResolver; + } + + public String getResolverName(ModuleId moduleId) { + for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { + ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); + if (midm.matches(moduleId)) { + ModuleSettings ms = (ModuleSettings) moduleSettings.get(midm); + if (ms.getResolverName() != null) { + return ms.getResolverName(); + } + } + } + return defaultResolverName; + } + + public String getDefaultBranch(ModuleId moduleId) { + for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { + ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); + if (midm.matches(moduleId)) { + ModuleSettings ms = (ModuleSettings) moduleSettings.get(midm); + if (ms.getBranch() != null) { + return ms.getBranch(); + } + } + } + return getDefaultBranch(); + } + + public String getDefaultBranch() { + return defaultBranch; + } + + public void setDefaultBranch(String defaultBranch) { + this.defaultBranch = defaultBranch; + } + + public ConflictManager getConflictManager(ModuleId moduleId) { + for (Iterator iter = moduleSettings.keySet().iterator(); iter.hasNext();) { + ModuleIdMatcher midm = (ModuleIdMatcher) iter.next(); + if (midm.matches(moduleId)) { + ModuleSettings ms = (ModuleSettings) moduleSettings.get(midm); + if (ms.getConflictManager() != null) { + ConflictManager cm = getConflictManager(ms.getConflictManager()); + if (cm == null) { + throw new IllegalStateException( + "ivy badly configured: unknown conflict manager " + + ms.getConflictManager()); + } + return cm; + } + } + } + return getDefaultConflictManager(); + } + + public void addConfigured(ConflictManager cm) { + addConflictManager(cm.getName(), cm); + } + + public ConflictManager getConflictManager(String name) { + if ("default".equals(name)) { + return getDefaultConflictManager(); + } + return (ConflictManager) conflictsManager.get(name); + } + + public void addConflictManager(String name, ConflictManager cm) { + init(cm); + conflictsManager.put(name, cm); + } + + public void addConfigured(LatestStrategy latest) { + addLatestStrategy(latest.getName(), latest); + } + + public LatestStrategy getLatestStrategy(String name) { + if ("default".equals(name)) { + return getDefaultLatestStrategy(); + } + return (LatestStrategy) latestStrategies.get(name); + } + + public void addLatestStrategy(String name, LatestStrategy latest) { + init(latest); + latestStrategies.put(name, latest); + } + + public void addConfigured(Namespace ns) { + addNamespace(ns); + } + + public Namespace getNamespace(String name) { + if ("system".equals(name)) { + return getSystemNamespace(); + } + return (Namespace) namespaces.get(name); + } + + public Namespace getSystemNamespace() { + return Namespace.SYSTEM_NAMESPACE; + } + + public void addNamespace(Namespace ns) { + init(ns); + namespaces.put(ns.getName(), ns); + } + + public void addConfigured(PatternMatcher m) { + addMatcher(m); + } + + public PatternMatcher getMatcher(String name) { + return (PatternMatcher) matchers.get(name); + } + + public void addMatcher(PatternMatcher m) { + init(m); + matchers.put(m.getName(), m); + } + + public void addConfigured(ReportOutputter outputter) { + addReportOutputter(outputter); + } + + public ReportOutputter getReportOutputter(String name) { + return (ReportOutputter) reportOutputters.get(name); + } + + public void addReportOutputter(ReportOutputter outputter) { + init(outputter); + reportOutputters.put(outputter.getName(), outputter); + } + + public ReportOutputter[] getReportOutputters() { + return (ReportOutputter[]) reportOutputters.values().toArray( + new ReportOutputter[reportOutputters.size()]); + } + + public void addConfigured(VersionMatcher vmatcher) { + addVersionMatcher(vmatcher); + } + + public VersionMatcher getVersionMatcher(String name) { + return (VersionMatcher) versionMatchers.get(name); + } + + public void addVersionMatcher(VersionMatcher vmatcher) { + init(vmatcher); + versionMatchers.put(vmatcher.getName(), vmatcher); + + if (versionMatcher == null) { + versionMatcher = new ChainVersionMatcher(); + addVersionMatcher(new ExactVersionMatcher()); + } + if (versionMatcher instanceof ChainVersionMatcher) { + ChainVersionMatcher chain = (ChainVersionMatcher) versionMatcher; + chain.add(vmatcher); + } + } + + public VersionMatcher[] getVersionMatchers() { + return (VersionMatcher[]) versionMatchers.values().toArray( + new VersionMatcher[versionMatchers.size()]); + } + + public VersionMatcher getVersionMatcher() { + if (versionMatcher == null) { + configureDefaultVersionMatcher(); + } + return versionMatcher; + } + + public void configureDefaultVersionMatcher() { + addVersionMatcher(new LatestVersionMatcher()); + addVersionMatcher(new SubVersionMatcher()); + addVersionMatcher(new VersionRangeMatcher()); + } + + public CircularDependencyStrategy getCircularDependencyStrategy() { + if (circularDependencyStrategy == null) { + circularDependencyStrategy = getCircularDependencyStrategy("default"); + } + return circularDependencyStrategy; + } + + public CircularDependencyStrategy getCircularDependencyStrategy(String name) { + if ("default".equals(name)) { + name = "warn"; + } + return (CircularDependencyStrategy) circularDependencyStrategies.get(name); + } + + public void setCircularDependencyStrategy(CircularDependencyStrategy strategy) { + circularDependencyStrategy = strategy; + } + + public void addConfigured(CircularDependencyStrategy strategy) { + addCircularDependencyStrategy(strategy); + } + + private void addCircularDependencyStrategy(CircularDependencyStrategy strategy) { + circularDependencyStrategies.put(strategy.getName(), strategy); + } + + private void configureDefaultCircularDependencyStrategies() { + addCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance()); + addCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); + addCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance()); + } + + public StatusManager getStatusManager() { + if (statusManager == null) { + statusManager = StatusManager.newDefaultInstance(); + } + return statusManager; + } + + public void setStatusManager(StatusManager statusManager) { + this.statusManager = statusManager; + } + + /** + * Returns true if the name should be ignored in listing + * + * @param name + * @return + */ + public boolean listingIgnore(String name) { + return listingIgnore.contains(name); + } + + /** + * Filters the names list by removing all names that should be ignored as defined by the listing + * ignore list + * + * @param names + */ + public void filterIgnore(Collection names) { + names.removeAll(listingIgnore); + } + + public boolean isCheckUpToDate() { + return checkUpToDate; + } + + public void setCheckUpToDate(boolean checkUpToDate) { + this.checkUpToDate = checkUpToDate; + } + + public String getCacheArtifactPattern() { + return cacheArtifactPattern; + } + + public void setCacheArtifactPattern(String cacheArtifactPattern) { + this.cacheArtifactPattern = cacheArtifactPattern; + } + + public String getCacheIvyPattern() { + return cacheIvyPattern; + } + + public void setCacheIvyPattern(String cacheIvyPattern) { + this.cacheIvyPattern = cacheIvyPattern; + } + + public String getCacheDataFilePattern() { + return cacheDataFilePattern; + } + + public boolean doValidate() { + return validate; + } + + public void setValidate(boolean validate) { + this.validate = validate; + } + + public String getVariable(String name) { + return variableContainer.getVariable(name); + } + + public ConflictManager getDefaultConflictManager() { + if (defaultConflictManager == null) { + defaultConflictManager = new LatestConflictManager(getDefaultLatestStrategy()); + } + return defaultConflictManager; + } + + public void setDefaultConflictManager(ConflictManager defaultConflictManager) { + this.defaultConflictManager = defaultConflictManager; + } + + public LatestStrategy getDefaultLatestStrategy() { + if (defaultLatestStrategy == null) { + defaultLatestStrategy = new LatestRevisionStrategy(); + } + return defaultLatestStrategy; + } + + public void setDefaultLatestStrategy(LatestStrategy defaultLatestStrategy) { + this.defaultLatestStrategy = defaultLatestStrategy; + } + + public void addTrigger(Trigger trigger) { + init(trigger); + triggers.add(trigger); + } + + public List getTriggers() { + return triggers; + } + + public void addConfigured(Trigger trigger) { + addTrigger(trigger); + } + + public boolean isUseRemoteConfig() { + return useRemoteConfig; + } + + public void setUseRemoteConfig(boolean useRemoteConfig) { + this.useRemoteConfig = useRemoteConfig; + } + + public boolean logModulesInUse() { + String var = getVariable("ivy.log.modules.in.use"); + return var == null || Boolean.valueOf(var).booleanValue(); + } + + public boolean logModuleWhenFound() { + String var = getVariable("ivy.log.module.when.found"); + return var == null || Boolean.valueOf(var).booleanValue(); + } + + public boolean logResolvedRevision() { + String var = getVariable("ivy.log.resolved.revision"); + return var == null || Boolean.valueOf(var).booleanValue(); + } + + public boolean debugConflictResolution() { + if (debugConflictResolution == null) { + String var = getVariable("ivy.log.conflict.resolution"); + debugConflictResolution = Boolean.valueOf(var != null + && Boolean.valueOf(var).booleanValue()); + } + return debugConflictResolution.booleanValue(); + } + + public boolean logNotConvertedExclusionRule() { + return logNotConvertedExclusionRule; + } + + public void setLogNotConvertedExclusionRule(boolean logNotConvertedExclusionRule) { + this.logNotConvertedExclusionRule = logNotConvertedExclusionRule; + } + + private void init(Object obj) { + if (obj instanceof IvySettingsAware) { + ((IvySettingsAware) obj).setSettings(this); + } + if (obj instanceof IvyAware) { + // TODO + // ((IvyAware)obj).setIvy(this); + } + } + + private static class ModuleSettings { + private String _resolverName; + + private String _branch; + + private String _conflictManager; + + public ModuleSettings(String resolverName, String branch, String conflictManager) { + _resolverName = resolverName; + _branch = branch; + _conflictManager = conflictManager; + } + + public String toString() { + return _resolverName != null ? "resolver: " + _resolverName + : "" + _branch != null ? "branch: " + _branch : ""; + } + + public String getBranch() { + return _branch; + } + + public String getResolverName() { + return _resolverName; + } + + protected String getConflictManager() { + return _conflictManager; + } + } + + public String getCacheResolvedIvyPattern() { + return cacheResolvedIvyPattern; + } + + public String getCacheResolvedIvyPropertiesPattern() { + return cacheResolvedIvyPropertiesPattern; + } + + public long getInterruptTimeout() { + return interruptTimeout; + } + + public Collection getResolvers() { + return resolversMap.values(); + } + + public Collection getResolverNames() { + return resolversMap.keySet(); + } + + public Collection getMatcherNames() { + return matchers.keySet(); + } + + public IvyVariableContainer getVariableContainer() { + return variableContainer; + } + + /** + * Use a different variable container. + * + * @param variables + */ + public void setVariableContainer(IvyVariableContainer variables) { + variableContainer = variables; + } + +} diff --git a/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java b/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java index afd95a5b..d5057fb7 100644 --- a/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java +++ b/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java @@ -1,403 +1,403 @@ -/* - * 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.core.settings; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.ParseException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.SAXParserFactory; - -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.status.StatusManager; -import org.apache.ivy.plugins.circular.CircularDependencyStrategy; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.util.Configurator; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.url.URLHandlerRegistry; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - */ -public class XmlSettingsParser extends DefaultHandler { - private Configurator configurator; - - private List configuratorTags = Arrays.asList(new String[] {"resolvers", "namespaces", - "parsers", "latest-strategies", "conflict-managers", "outputters", "version-matchers", - "statuses", "circular-dependency-strategies", "triggers"}); - - private IvySettings ivy; - - private String defaultResolver; - - private String defaultCM; - - private String defaultLatest; - - private String defaultCircular; - - private String currentConfiguratorTag; - - private URL settings; - - private boolean deprecatedMessagePrinted = false; - - public XmlSettingsParser(IvySettings ivy) { - this.ivy = ivy; - } - - public void parse(URL settings) throws ParseException, IOException { - configurator = new Configurator(); - // put every type definition from ivy to configurator - Map typeDefs = ivy.getTypeDefs(); - for (Iterator iter = typeDefs.keySet().iterator(); iter.hasNext();) { - String name = (String) iter.next(); - configurator.typeDef(name, (Class) typeDefs.get(name)); - } - - doParse(settings); - } - - private void doParse(URL settingsUrl) throws IOException, ParseException { - this.settings = settingsUrl; - InputStream stream = null; - try { - stream = URLHandlerRegistry.getDefault().openStream(settingsUrl); - SAXParserFactory.newInstance().newSAXParser().parse(stream, this); - } catch (IOException e) { - throw e; - } catch (Exception e) { - ParseException pe = new ParseException("failed to load settings from " + settingsUrl - + ": " + e.getMessage(), 0); - pe.initCause(e); - throw pe; - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - } - } - } - } - - private void parse(Configurator configurator, URL configuration) throws IOException, - ParseException { - this.configurator = configurator; - doParse(configuration); - } - - public void startElement(String uri, String localName, String qName, Attributes att) - throws SAXException { - // we first copy attributes in a Map to be able to modify them - Map attributes = new HashMap(); - for (int i = 0; i < att.getLength(); i++) { - attributes.put(att.getQName(i), att.getValue(i)); - } - - try { - if ("ivyconf".equals(qName)) { - deprecatedMessagePrinted = true; - Message.deprecated("'ivyconf' element is deprecated, use 'ivysettings' instead (" - + settings + ")"); - } - if (configurator.getCurrent() != null) { - if ("macrodef".equals(currentConfiguratorTag) - && configurator.getTypeDef(qName) != null) { - String name = (String) attributes.get("name"); - if (name == null) { - attributes.put("name", "@{name}"); - } else if (configurator.isTopLevelMacroRecord() - && name.indexOf("@{name}") != -1) { - attributes.put("name", name); - } else { - attributes.put("name", "@{name}-" + name); - } - } - if (attributes.get("ref") != null) { - if (attributes.size() != 1) { - throw new IllegalArgumentException( - "ref attribute should be the only one ! found " + attributes.size() - + " in " + qName); - } - String name = (String) attributes.get("ref"); - Object child = null; - if ("resolvers".equals(currentConfiguratorTag)) { - child = ivy.getResolver(name); - if (child == null) { - throw new IllegalArgumentException("unknown resolver " + name - + ": resolver should be defined before being referenced"); - } - } else if ("latest-strategies".equals(currentConfiguratorTag)) { - child = ivy.getLatestStrategy(name); - if (child == null) { - throw new IllegalArgumentException("unknown latest strategy " + name - + ": latest strategy should be defined before being referenced"); - } - } else if ("conflict-managers".equals(currentConfiguratorTag)) { - child = ivy.getConflictManager(name); - if (child == null) { - throw new IllegalArgumentException( - "unknown conflict manager " - + name - + ": conflict manager should be defined before being referenced"); - } - } - if (child == null) { - throw new IllegalArgumentException("bad reference " + name); - } - configurator.addChild(qName, child); - } else { - configurator.startCreateChild(qName); - for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { - String attName = (String) iter.next(); - configurator.setAttribute(attName, ivy.substitute((String) attributes - .get(attName))); - } - } - } else if ("classpath".equals(qName)) { - String urlStr = ivy.substitute((String) attributes.get("url")); - URL url = null; - if (urlStr == null) { - String file = ivy.substitute((String) attributes.get("file")); - if (file == null) { - throw new IllegalArgumentException( - "either url or file should be given for classpath element"); - } else { - url = new File(file).toURL(); - } - } else { - url = new URL(urlStr); - } - ivy.addClasspathURL(url); - } else if ("typedef".equals(qName)) { - String name = ivy.substitute((String) attributes.get("name")); - String className = ivy.substitute((String) attributes.get("classname")); - Class clazz = ivy.typeDef(name, className); - configurator.typeDef(name, clazz); - } else if ("property".equals(qName)) { - String name = ivy.substitute((String) attributes.get("name")); - String value = ivy.substitute((String) attributes.get("value")); - String override = ivy.substitute((String) attributes.get("override")); - if (name == null) { - throw new IllegalArgumentException("missing attribute name on property tag"); - } - if (value == null) { - throw new IllegalArgumentException("missing attribute value on property tag"); - } - ivy.setVariable(name, value, override == null ? true : Boolean.valueOf(override) - .booleanValue()); - } else if ("properties".equals(qName)) { - String propFilePath = ivy.substitute((String) attributes.get("file")); - String override = ivy.substitute((String) attributes.get("override")); - try { - Message.verbose("loading properties: " + propFilePath); - ivy.loadProperties(new File(propFilePath), override == null ? true : Boolean - .valueOf(override).booleanValue()); - } catch (Exception fileEx) { - Message.verbose("failed to load properties as file: trying as url: " - + propFilePath); - try { - ivy.loadProperties(new URL(propFilePath), override == null ? true : Boolean - .valueOf(override).booleanValue()); - } catch (Exception urlEx) { - throw new IllegalArgumentException( - "unable to load properties from " - + propFilePath - + ". Tried both as an url and a file, with no success. File exception: " - + fileEx + ". URL exception: " + urlEx); - } - } - } else if ("include".equals(qName)) { - IvyVariableContainer variables = (IvyVariableContainer) ivy.getVariableContainer() - .clone(); - try { - String propFilePath = ivy.substitute((String) attributes.get("file")); - URL settingsURL = null; - if (propFilePath == null) { - propFilePath = ivy.substitute((String) attributes.get("url")); - if (propFilePath == null) { - Message.error("bad include tag: specify file or url to include"); - return; - } else { - Message.verbose("including url: " + propFilePath); - settingsURL = new URL(propFilePath); - ivy.setSettingsVariables(settingsURL); - } - } else { - File incFile = new File(propFilePath); - if (!incFile.exists()) { - Message.error("impossible to include " + incFile - + ": file does not exist"); - return; - } else { - Message.verbose("including file: " + propFilePath); - ivy.setSettingsVariables(incFile); - settingsURL = incFile.toURL(); - } - } - new XmlSettingsParser(ivy).parse(configurator, settingsURL); - } finally { - ivy.setVariableContainer(variables); - } - } else if ("settings".equals(qName) || "conf".equals(qName)) { - if ("conf".equals(qName) && !deprecatedMessagePrinted) { - Message.deprecated("'conf' is deprecated, use 'settings' instead (" + settings - + ")"); - } - String cache = (String) attributes.get("defaultCache"); - if (cache != null) { - ivy.setDefaultCache(new File(ivy.substitute(cache))); - } - String defaultBranch = (String) attributes.get("defaultBranch"); - if (defaultBranch != null) { - ivy.setDefaultBranch(ivy.substitute(defaultBranch)); - } - String validate = (String) attributes.get("validate"); - if (validate != null) { - ivy.setValidate(Boolean.valueOf(ivy.substitute(validate)).booleanValue()); - } - String up2d = (String) attributes.get("checkUpToDate"); - if (up2d != null) { - ivy.setCheckUpToDate(Boolean.valueOf(ivy.substitute(up2d)).booleanValue()); - } - String cacheIvyPattern = (String) attributes.get("cacheIvyPattern"); - if (cacheIvyPattern != null) { - ivy.setCacheIvyPattern(ivy.substitute(cacheIvyPattern)); - } - String cacheArtPattern = (String) attributes.get("cacheArtifactPattern"); - if (cacheArtPattern != null) { - ivy.setCacheArtifactPattern(ivy.substitute(cacheArtPattern)); - } - String useRemoteConfig = (String) attributes.get("useRemoteConfig"); - if (useRemoteConfig != null) { - ivy.setUseRemoteConfig(Boolean.valueOf(ivy.substitute(useRemoteConfig)) - .booleanValue()); - } - - // we do not set following defaults here since no instances has been registered yet - defaultResolver = (String) attributes.get("defaultResolver"); - defaultCM = (String) attributes.get("defaultConflictManager"); - defaultLatest = (String) attributes.get("defaultLatestStrategy"); - defaultCircular = (String) attributes.get("circularDependencyStrategy"); - - } else if ("version-matchers".equals(qName)) { - currentConfiguratorTag = qName; - configurator.setRoot(ivy); - if ("true".equals(ivy.substitute((String) attributes.get("usedefaults")))) { - ivy.configureDefaultVersionMatcher(); - } - } else if ("statuses".equals(qName)) { - currentConfiguratorTag = qName; - StatusManager m = new StatusManager(); - String defaultStatus = ivy.substitute((String) attributes.get("default")); - if (defaultStatus != null) { - m.setDefaultStatus(defaultStatus); - } - ivy.setStatusManager(m); - configurator.setRoot(m); - } else if (configuratorTags.contains(qName)) { - currentConfiguratorTag = qName; - configurator.setRoot(ivy); - } else if ("macrodef".equals(qName)) { - currentConfiguratorTag = qName; - Configurator.MacroDef macrodef = configurator.startMacroDef((String) attributes - .get("name")); - macrodef.addAttribute("name", null); - } else if ("module".equals(qName)) { - String organisation = ivy.substitute((String) attributes.get("organisation")); - String module = ivy.substitute((String) attributes.get("name")); - String resolver = ivy.substitute((String) attributes.get("resolver")); - String branch = ivy.substitute((String) attributes.get("branch")); - String cm = ivy.substitute((String) attributes.get("conflict-manager")); - String matcher = ivy.substitute((String) attributes.get("matcher")); - matcher = matcher == null ? PatternMatcher.EXACT_OR_REGEXP : matcher; - if (organisation == null) { - throw new IllegalArgumentException( - "'organisation' is mandatory in module element: check your configuration"); - } - if (module == null) { - throw new IllegalArgumentException( - "'name' is mandatory in module element: check your configuration"); - } - ivy.addModuleConfiguration(new ModuleId(organisation, module), ivy - .getMatcher(matcher), resolver, branch, cm); - } - } catch (ParseException ex) { - throw new SAXException("problem in config file: " + ex.getMessage(), ex); - } catch (IOException ex) { - throw new SAXException("io problem while parsing config file: " + ex.getMessage(), ex); - } - } - - public void endElement(String uri, String localName, String qName) throws SAXException { - if (configurator.getCurrent() != null) { - if (configuratorTags.contains(qName) && configurator.getDepth() == 1) { - configurator.clear(); - currentConfiguratorTag = null; - } else if ("macrodef".equals(qName) && configurator.getDepth() == 1) { - configurator.endMacroDef(); - currentConfiguratorTag = null; - } else { - configurator.endCreateChild(); - } - } - } - - public void endDocument() throws SAXException { - if (defaultResolver != null) { - ivy.setDefaultResolver(ivy.substitute(defaultResolver)); - } - if (defaultCM != null) { - ConflictManager conflictManager = ivy.getConflictManager(ivy.substitute(defaultCM)); - if (conflictManager == null) { - throw new IllegalArgumentException("unknown conflict manager " - + ivy.substitute(defaultCM)); - } - ivy.setDefaultConflictManager(conflictManager); - } - if (defaultLatest != null) { - LatestStrategy latestStrategy = ivy.getLatestStrategy(ivy.substitute(defaultLatest)); - if (latestStrategy == null) { - throw new IllegalArgumentException("unknown latest strategy " - + ivy.substitute(defaultLatest)); - } - ivy.setDefaultLatestStrategy(latestStrategy); - } - if (defaultCircular != null) { - CircularDependencyStrategy strategy = ivy.getCircularDependencyStrategy(ivy - .substitute(defaultCircular)); - if (strategy == null) { - throw new IllegalArgumentException("unknown circular dependency strategy " - + ivy.substitute(defaultCircular)); - } - ivy.setCircularDependencyStrategy(strategy); - } - } -} +/* + * 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.core.settings; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.text.ParseException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.SAXParserFactory; + +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.status.StatusManager; +import org.apache.ivy.plugins.circular.CircularDependencyStrategy; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.util.Configurator; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.url.URLHandlerRegistry; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + */ +public class XmlSettingsParser extends DefaultHandler { + private Configurator configurator; + + private List configuratorTags = Arrays.asList(new String[] {"resolvers", "namespaces", + "parsers", "latest-strategies", "conflict-managers", "outputters", "version-matchers", + "statuses", "circular-dependency-strategies", "triggers"}); + + private IvySettings ivy; + + private String defaultResolver; + + private String defaultCM; + + private String defaultLatest; + + private String defaultCircular; + + private String currentConfiguratorTag; + + private URL settings; + + private boolean deprecatedMessagePrinted = false; + + public XmlSettingsParser(IvySettings ivy) { + this.ivy = ivy; + } + + public void parse(URL settings) throws ParseException, IOException { + configurator = new Configurator(); + // put every type definition from ivy to configurator + Map typeDefs = ivy.getTypeDefs(); + for (Iterator iter = typeDefs.keySet().iterator(); iter.hasNext();) { + String name = (String) iter.next(); + configurator.typeDef(name, (Class) typeDefs.get(name)); + } + + doParse(settings); + } + + private void doParse(URL settingsUrl) throws IOException, ParseException { + this.settings = settingsUrl; + InputStream stream = null; + try { + stream = URLHandlerRegistry.getDefault().openStream(settingsUrl); + SAXParserFactory.newInstance().newSAXParser().parse(stream, this); + } catch (IOException e) { + throw e; + } catch (Exception e) { + ParseException pe = new ParseException("failed to load settings from " + settingsUrl + + ": " + e.getMessage(), 0); + pe.initCause(e); + throw pe; + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + } + } + } + } + + private void parse(Configurator configurator, URL configuration) throws IOException, + ParseException { + this.configurator = configurator; + doParse(configuration); + } + + public void startElement(String uri, String localName, String qName, Attributes att) + throws SAXException { + // we first copy attributes in a Map to be able to modify them + Map attributes = new HashMap(); + for (int i = 0; i < att.getLength(); i++) { + attributes.put(att.getQName(i), att.getValue(i)); + } + + try { + if ("ivyconf".equals(qName)) { + deprecatedMessagePrinted = true; + Message.deprecated("'ivyconf' element is deprecated, use 'ivysettings' instead (" + + settings + ")"); + } + if (configurator.getCurrent() != null) { + if ("macrodef".equals(currentConfiguratorTag) + && configurator.getTypeDef(qName) != null) { + String name = (String) attributes.get("name"); + if (name == null) { + attributes.put("name", "@{name}"); + } else if (configurator.isTopLevelMacroRecord() + && name.indexOf("@{name}") != -1) { + attributes.put("name", name); + } else { + attributes.put("name", "@{name}-" + name); + } + } + if (attributes.get("ref") != null) { + if (attributes.size() != 1) { + throw new IllegalArgumentException( + "ref attribute should be the only one ! found " + attributes.size() + + " in " + qName); + } + String name = (String) attributes.get("ref"); + Object child = null; + if ("resolvers".equals(currentConfiguratorTag)) { + child = ivy.getResolver(name); + if (child == null) { + throw new IllegalArgumentException("unknown resolver " + name + + ": resolver should be defined before being referenced"); + } + } else if ("latest-strategies".equals(currentConfiguratorTag)) { + child = ivy.getLatestStrategy(name); + if (child == null) { + throw new IllegalArgumentException("unknown latest strategy " + name + + ": latest strategy should be defined before being referenced"); + } + } else if ("conflict-managers".equals(currentConfiguratorTag)) { + child = ivy.getConflictManager(name); + if (child == null) { + throw new IllegalArgumentException( + "unknown conflict manager " + + name + + ": conflict manager should be defined before being referenced"); + } + } + if (child == null) { + throw new IllegalArgumentException("bad reference " + name); + } + configurator.addChild(qName, child); + } else { + configurator.startCreateChild(qName); + for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { + String attName = (String) iter.next(); + configurator.setAttribute(attName, ivy.substitute((String) attributes + .get(attName))); + } + } + } else if ("classpath".equals(qName)) { + String urlStr = ivy.substitute((String) attributes.get("url")); + URL url = null; + if (urlStr == null) { + String file = ivy.substitute((String) attributes.get("file")); + if (file == null) { + throw new IllegalArgumentException( + "either url or file should be given for classpath element"); + } else { + url = new File(file).toURL(); + } + } else { + url = new URL(urlStr); + } + ivy.addClasspathURL(url); + } else if ("typedef".equals(qName)) { + String name = ivy.substitute((String) attributes.get("name")); + String className = ivy.substitute((String) attributes.get("classname")); + Class clazz = ivy.typeDef(name, className); + configurator.typeDef(name, clazz); + } else if ("property".equals(qName)) { + String name = ivy.substitute((String) attributes.get("name")); + String value = ivy.substitute((String) attributes.get("value")); + String override = ivy.substitute((String) attributes.get("override")); + if (name == null) { + throw new IllegalArgumentException("missing attribute name on property tag"); + } + if (value == null) { + throw new IllegalArgumentException("missing attribute value on property tag"); + } + ivy.setVariable(name, value, override == null ? true : Boolean.valueOf(override) + .booleanValue()); + } else if ("properties".equals(qName)) { + String propFilePath = ivy.substitute((String) attributes.get("file")); + String override = ivy.substitute((String) attributes.get("override")); + try { + Message.verbose("loading properties: " + propFilePath); + ivy.loadProperties(new File(propFilePath), override == null ? true : Boolean + .valueOf(override).booleanValue()); + } catch (Exception fileEx) { + Message.verbose("failed to load properties as file: trying as url: " + + propFilePath); + try { + ivy.loadProperties(new URL(propFilePath), override == null ? true : Boolean + .valueOf(override).booleanValue()); + } catch (Exception urlEx) { + throw new IllegalArgumentException( + "unable to load properties from " + + propFilePath + + ". Tried both as an url and a file, with no success. File exception: " + + fileEx + ". URL exception: " + urlEx); + } + } + } else if ("include".equals(qName)) { + IvyVariableContainer variables = (IvyVariableContainer) ivy.getVariableContainer() + .clone(); + try { + String propFilePath = ivy.substitute((String) attributes.get("file")); + URL settingsURL = null; + if (propFilePath == null) { + propFilePath = ivy.substitute((String) attributes.get("url")); + if (propFilePath == null) { + Message.error("bad include tag: specify file or url to include"); + return; + } else { + Message.verbose("including url: " + propFilePath); + settingsURL = new URL(propFilePath); + ivy.setSettingsVariables(settingsURL); + } + } else { + File incFile = new File(propFilePath); + if (!incFile.exists()) { + Message.error("impossible to include " + incFile + + ": file does not exist"); + return; + } else { + Message.verbose("including file: " + propFilePath); + ivy.setSettingsVariables(incFile); + settingsURL = incFile.toURL(); + } + } + new XmlSettingsParser(ivy).parse(configurator, settingsURL); + } finally { + ivy.setVariableContainer(variables); + } + } else if ("settings".equals(qName) || "conf".equals(qName)) { + if ("conf".equals(qName) && !deprecatedMessagePrinted) { + Message.deprecated("'conf' is deprecated, use 'settings' instead (" + settings + + ")"); + } + String cache = (String) attributes.get("defaultCache"); + if (cache != null) { + ivy.setDefaultCache(new File(ivy.substitute(cache))); + } + String defaultBranch = (String) attributes.get("defaultBranch"); + if (defaultBranch != null) { + ivy.setDefaultBranch(ivy.substitute(defaultBranch)); + } + String validate = (String) attributes.get("validate"); + if (validate != null) { + ivy.setValidate(Boolean.valueOf(ivy.substitute(validate)).booleanValue()); + } + String up2d = (String) attributes.get("checkUpToDate"); + if (up2d != null) { + ivy.setCheckUpToDate(Boolean.valueOf(ivy.substitute(up2d)).booleanValue()); + } + String cacheIvyPattern = (String) attributes.get("cacheIvyPattern"); + if (cacheIvyPattern != null) { + ivy.setCacheIvyPattern(ivy.substitute(cacheIvyPattern)); + } + String cacheArtPattern = (String) attributes.get("cacheArtifactPattern"); + if (cacheArtPattern != null) { + ivy.setCacheArtifactPattern(ivy.substitute(cacheArtPattern)); + } + String useRemoteConfig = (String) attributes.get("useRemoteConfig"); + if (useRemoteConfig != null) { + ivy.setUseRemoteConfig(Boolean.valueOf(ivy.substitute(useRemoteConfig)) + .booleanValue()); + } + + // we do not set following defaults here since no instances has been registered yet + defaultResolver = (String) attributes.get("defaultResolver"); + defaultCM = (String) attributes.get("defaultConflictManager"); + defaultLatest = (String) attributes.get("defaultLatestStrategy"); + defaultCircular = (String) attributes.get("circularDependencyStrategy"); + + } else if ("version-matchers".equals(qName)) { + currentConfiguratorTag = qName; + configurator.setRoot(ivy); + if ("true".equals(ivy.substitute((String) attributes.get("usedefaults")))) { + ivy.configureDefaultVersionMatcher(); + } + } else if ("statuses".equals(qName)) { + currentConfiguratorTag = qName; + StatusManager m = new StatusManager(); + String defaultStatus = ivy.substitute((String) attributes.get("default")); + if (defaultStatus != null) { + m.setDefaultStatus(defaultStatus); + } + ivy.setStatusManager(m); + configurator.setRoot(m); + } else if (configuratorTags.contains(qName)) { + currentConfiguratorTag = qName; + configurator.setRoot(ivy); + } else if ("macrodef".equals(qName)) { + currentConfiguratorTag = qName; + Configurator.MacroDef macrodef = configurator.startMacroDef((String) attributes + .get("name")); + macrodef.addAttribute("name", null); + } else if ("module".equals(qName)) { + String organisation = ivy.substitute((String) attributes.get("organisation")); + String module = ivy.substitute((String) attributes.get("name")); + String resolver = ivy.substitute((String) attributes.get("resolver")); + String branch = ivy.substitute((String) attributes.get("branch")); + String cm = ivy.substitute((String) attributes.get("conflict-manager")); + String matcher = ivy.substitute((String) attributes.get("matcher")); + matcher = matcher == null ? PatternMatcher.EXACT_OR_REGEXP : matcher; + if (organisation == null) { + throw new IllegalArgumentException( + "'organisation' is mandatory in module element: check your configuration"); + } + if (module == null) { + throw new IllegalArgumentException( + "'name' is mandatory in module element: check your configuration"); + } + ivy.addModuleConfiguration(new ModuleId(organisation, module), ivy + .getMatcher(matcher), resolver, branch, cm); + } + } catch (ParseException ex) { + throw new SAXException("problem in config file: " + ex.getMessage(), ex); + } catch (IOException ex) { + throw new SAXException("io problem while parsing config file: " + ex.getMessage(), ex); + } + } + + public void endElement(String uri, String localName, String qName) throws SAXException { + if (configurator.getCurrent() != null) { + if (configuratorTags.contains(qName) && configurator.getDepth() == 1) { + configurator.clear(); + currentConfiguratorTag = null; + } else if ("macrodef".equals(qName) && configurator.getDepth() == 1) { + configurator.endMacroDef(); + currentConfiguratorTag = null; + } else { + configurator.endCreateChild(); + } + } + } + + public void endDocument() throws SAXException { + if (defaultResolver != null) { + ivy.setDefaultResolver(ivy.substitute(defaultResolver)); + } + if (defaultCM != null) { + ConflictManager conflictManager = ivy.getConflictManager(ivy.substitute(defaultCM)); + if (conflictManager == null) { + throw new IllegalArgumentException("unknown conflict manager " + + ivy.substitute(defaultCM)); + } + ivy.setDefaultConflictManager(conflictManager); + } + if (defaultLatest != null) { + LatestStrategy latestStrategy = ivy.getLatestStrategy(ivy.substitute(defaultLatest)); + if (latestStrategy == null) { + throw new IllegalArgumentException("unknown latest strategy " + + ivy.substitute(defaultLatest)); + } + ivy.setDefaultLatestStrategy(latestStrategy); + } + if (defaultCircular != null) { + CircularDependencyStrategy strategy = ivy.getCircularDependencyStrategy(ivy + .substitute(defaultCircular)); + if (strategy == null) { + throw new IllegalArgumentException("unknown circular dependency strategy " + + ivy.substitute(defaultCircular)); + } + ivy.setCircularDependencyStrategy(strategy); + } + } +} diff --git a/src/java/org/apache/ivy/core/settings/ivy.properties b/src/java/org/apache/ivy/core/settings/ivy.properties index f37002bc..39f6670b 100644 --- a/src/java/org/apache/ivy/core/settings/ivy.properties +++ b/src/java/org/apache/ivy/core/settings/ivy.properties @@ -1,42 +1,42 @@ -# *************************************************************** -# * 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.project.dir = ${basedir} -ivy.lib.dir = ${ivy.project.dir}/lib -ivy.build.artifacts.dir = ${ivy.project.dir}/build/artifacts -ivy.distrib.dir = ${ivy.project.dir}/distrib - -ivy.resolver.default.check.modified = false -ivy.default.always.check.exact.revision = true - -ivy.configurations = * -ivy.resolve.default.type.filter = * -ivy.status = integration -ivy.dep.file = ivy.xml -ivy.settings.file = ivysettings.xml -ivy.retrieve.pattern = ${ivy.lib.dir}/[artifact]-[revision].[ext] -ivy.deliver.ivy.pattern = ${ivy.distrib.dir}/[type]s/[artifact]-[revision].[ext] -ivy.publish.src.artifacts.pattern = ${ivy.distrib.dir}/[type]s/[artifact]-[revision].[ext] - -ivy.report.output.pattern = [organisation]-[module]-[conf].[ext] - -ivy.buildlist.ivyfilepath = ivy.xml - -ivy.checksums=sha1,md5 - -ivy.log.modules.in.use=false +# *************************************************************** +# * 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.project.dir = ${basedir} +ivy.lib.dir = ${ivy.project.dir}/lib +ivy.build.artifacts.dir = ${ivy.project.dir}/build/artifacts +ivy.distrib.dir = ${ivy.project.dir}/distrib + +ivy.resolver.default.check.modified = false +ivy.default.always.check.exact.revision = true + +ivy.configurations = * +ivy.resolve.default.type.filter = * +ivy.status = integration +ivy.dep.file = ivy.xml +ivy.settings.file = ivysettings.xml +ivy.retrieve.pattern = ${ivy.lib.dir}/[artifact]-[revision].[ext] +ivy.deliver.ivy.pattern = ${ivy.distrib.dir}/[type]s/[artifact]-[revision].[ext] +ivy.publish.src.artifacts.pattern = ${ivy.distrib.dir}/[type]s/[artifact]-[revision].[ext] + +ivy.report.output.pattern = [organisation]-[module]-[conf].[ext] + +ivy.buildlist.ivyfilepath = ivy.xml + +ivy.checksums=sha1,md5 + +ivy.log.modules.in.use=false diff --git a/src/java/org/apache/ivy/core/settings/ivysettings-1.4.xml b/src/java/org/apache/ivy/core/settings/ivysettings-1.4.xml index d6d29743..d87089b6 100644 --- a/src/java/org/apache/ivy/core/settings/ivysettings-1.4.xml +++ b/src/java/org/apache/ivy/core/settings/ivysettings-1.4.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/src/java/org/apache/ivy/core/settings/ivysettings-default-chain.xml b/src/java/org/apache/ivy/core/settings/ivysettings-default-chain.xml index 4a0bc233..4dd8f5d4 100644 --- a/src/java/org/apache/ivy/core/settings/ivysettings-default-chain.xml +++ b/src/java/org/apache/ivy/core/settings/ivysettings-default-chain.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/java/org/apache/ivy/core/settings/ivysettings-local.xml b/src/java/org/apache/ivy/core/settings/ivysettings-local.xml index 4a6a56ee..acf224d7 100644 --- a/src/java/org/apache/ivy/core/settings/ivysettings-local.xml +++ b/src/java/org/apache/ivy/core/settings/ivysettings-local.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/java/org/apache/ivy/core/settings/ivysettings-main-chain.xml b/src/java/org/apache/ivy/core/settings/ivysettings-main-chain.xml index 9a52a89e..8cb5cf51 100644 --- a/src/java/org/apache/ivy/core/settings/ivysettings-main-chain.xml +++ b/src/java/org/apache/ivy/core/settings/ivysettings-main-chain.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/java/org/apache/ivy/core/settings/ivysettings-public.xml b/src/java/org/apache/ivy/core/settings/ivysettings-public.xml index 814e3fec..09d1e581 100644 --- a/src/java/org/apache/ivy/core/settings/ivysettings-public.xml +++ b/src/java/org/apache/ivy/core/settings/ivysettings-public.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/src/java/org/apache/ivy/core/settings/ivysettings-shared.xml b/src/java/org/apache/ivy/core/settings/ivysettings-shared.xml index b82cb7d5..b5b530cb 100644 --- a/src/java/org/apache/ivy/core/settings/ivysettings-shared.xml +++ b/src/java/org/apache/ivy/core/settings/ivysettings-shared.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/java/org/apache/ivy/core/settings/ivysettings.xml b/src/java/org/apache/ivy/core/settings/ivysettings.xml index 01481d5a..6f0beb34 100644 --- a/src/java/org/apache/ivy/core/settings/ivysettings.xml +++ b/src/java/org/apache/ivy/core/settings/ivysettings.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/java/org/apache/ivy/core/settings/repository.properties b/src/java/org/apache/ivy/core/settings/repository.properties index f165160a..b28ccd39 100644 --- a/src/java/org/apache/ivy/core/settings/repository.properties +++ b/src/java/org/apache/ivy/core/settings/repository.properties @@ -1,25 +1,25 @@ -# *************************************************************** -# * 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.ibiblio.default.artifact.root = http://www.ibiblio.org/maven/ -ivy.ibiblio.default.artifact.pattern = [module]/[type]s/[artifact]-[revision].[ext] - -ivy.ivyrep.default.ivy.root = http://ivyrep.jayasoft.org/ -ivy.ivyrep.default.ivy.pattern = [organisation]/[module]/ivy-[revision].xml -ivy.ivyrep.default.artifact.root = ${ivy.ibiblio.default.artifact.root} -ivy.ivyrep.default.artifact.pattern = ${ivy.ibiblio.default.artifact.pattern} \ No newline at end of file +# *************************************************************** +# * 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.ibiblio.default.artifact.root = http://www.ibiblio.org/maven/ +ivy.ibiblio.default.artifact.pattern = [module]/[type]s/[artifact]-[revision].[ext] + +ivy.ivyrep.default.ivy.root = http://ivyrep.jayasoft.org/ +ivy.ivyrep.default.ivy.pattern = [organisation]/[module]/ivy-[revision].xml +ivy.ivyrep.default.artifact.root = ${ivy.ibiblio.default.artifact.root} +ivy.ivyrep.default.artifact.pattern = ${ivy.ibiblio.default.artifact.pattern} diff --git a/src/java/org/apache/ivy/core/settings/typedef.properties b/src/java/org/apache/ivy/core/settings/typedef.properties index a435744c..209a4a29 100644 --- a/src/java/org/apache/ivy/core/settings/typedef.properties +++ b/src/java/org/apache/ivy/core/settings/typedef.properties @@ -1,51 +1,51 @@ -# *************************************************************** -# * 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. -# *************************************************************** -filesystem = org.apache.ivy.plugins.resolver.FileSystemResolver -chain = org.apache.ivy.plugins.resolver.ChainResolver -ibiblio = org.apache.ivy.plugins.resolver.IBiblioResolver -url = org.apache.ivy.plugins.resolver.URLResolver -dual = org.apache.ivy.plugins.resolver.DualResolver -ivyrep = org.apache.ivy.plugins.resolver.IvyRepResolver -ssh = org.apache.ivy.plugins.resolver.SshResolver -sftp = org.apache.ivy.plugins.resolver.SFTPResolver -vsftp = org.apache.ivy.plugins.resolver.VsftpResolver -vfs = org.apache.ivy.plugins.resolver.VfsResolver -cache = org.apache.ivy.plugins.resolver.CacheResolver - -latest-revision = org.apache.ivy.plugins.latest.LatestRevisionStrategy -latest-lexico = org.apache.ivy.plugins.latest.LatestLexicographicStrategy -latest-time = org.apache.ivy.plugins.latest.LatestTimeStrategy - -fixed-cm = org.apache.ivy.plugins.conflict.FixedConflictManager -latest-cm = org.apache.ivy.plugins.conflict.LatestConflictManager -no-cm = org.apache.ivy.plugins.conflict.NoConflictManager -strict-cm = org.apache.ivy.plugins.conflict.StrictConflictManager -regexp-cm = org.apache.ivy.plugins.conflict.RegexpConflictManager - - -namespace = org.apache.ivy.plugins.namespace.Namespace - -exact-vm = org.apache.ivy.plugins.version.ExactVersionMatcher -chain-vm = org.apache.ivy.plugins.version.ChainVersionMatcher -latest-vm = org.apache.ivy.plugins.version.LatestVersionMatcher -sub-vm = org.apache.ivy.plugins.version.SubVersionMatcher -range-vm = org.apache.ivy.plugins.version.VersionRangeMatcher - -ant-build = org.apache.ivy.ant.AntBuildTrigger -ant-call = org.apache.ivy.ant.AntCallTrigger +# *************************************************************** +# * 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. +# *************************************************************** +filesystem = org.apache.ivy.plugins.resolver.FileSystemResolver +chain = org.apache.ivy.plugins.resolver.ChainResolver +ibiblio = org.apache.ivy.plugins.resolver.IBiblioResolver +url = org.apache.ivy.plugins.resolver.URLResolver +dual = org.apache.ivy.plugins.resolver.DualResolver +ivyrep = org.apache.ivy.plugins.resolver.IvyRepResolver +ssh = org.apache.ivy.plugins.resolver.SshResolver +sftp = org.apache.ivy.plugins.resolver.SFTPResolver +vsftp = org.apache.ivy.plugins.resolver.VsftpResolver +vfs = org.apache.ivy.plugins.resolver.VfsResolver +cache = org.apache.ivy.plugins.resolver.CacheResolver + +latest-revision = org.apache.ivy.plugins.latest.LatestRevisionStrategy +latest-lexico = org.apache.ivy.plugins.latest.LatestLexicographicStrategy +latest-time = org.apache.ivy.plugins.latest.LatestTimeStrategy + +fixed-cm = org.apache.ivy.plugins.conflict.FixedConflictManager +latest-cm = org.apache.ivy.plugins.conflict.LatestConflictManager +no-cm = org.apache.ivy.plugins.conflict.NoConflictManager +strict-cm = org.apache.ivy.plugins.conflict.StrictConflictManager +regexp-cm = org.apache.ivy.plugins.conflict.RegexpConflictManager + + +namespace = org.apache.ivy.plugins.namespace.Namespace + +exact-vm = org.apache.ivy.plugins.version.ExactVersionMatcher +chain-vm = org.apache.ivy.plugins.version.ChainVersionMatcher +latest-vm = org.apache.ivy.plugins.version.LatestVersionMatcher +sub-vm = org.apache.ivy.plugins.version.SubVersionMatcher +range-vm = org.apache.ivy.plugins.version.VersionRangeMatcher + +ant-build = org.apache.ivy.ant.AntBuildTrigger +ant-call = org.apache.ivy.ant.AntCallTrigger diff --git a/src/java/org/apache/ivy/core/sort/ModuleDescriptorSorter.java b/src/java/org/apache/ivy/core/sort/ModuleDescriptorSorter.java index 6983fe9a..5a123f43 100644 --- a/src/java/org/apache/ivy/core/sort/ModuleDescriptorSorter.java +++ b/src/java/org/apache/ivy/core/sort/ModuleDescriptorSorter.java @@ -1,107 +1,107 @@ -/* - * 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.core.sort; - -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.plugins.circular.CircularDependencyException; -import org.apache.ivy.plugins.circular.CircularDependencyStrategy; -import org.apache.ivy.plugins.version.VersionMatcher; -import org.apache.ivy.util.Message; - -/** - * Inner helper class for sorting ModuleDescriptors.
      - * ModuleDescriptorSorter use CollectionOfModulesToSort to find the dependencies of the modules, and - * use ModuleInSort to store some temporary values attached to the modules to sort. - * - * @see ModuleInSort - * @see CollectionOfModulesToSort - */ -public class ModuleDescriptorSorter { - - private final CollectionOfModulesToSort moduleDescriptors; - - private final List sorted = new LinkedList(); - - private final CircularDependencyStrategy circularDepStrategy; - - public ModuleDescriptorSorter(Collection modulesDescriptorsToSort, VersionMatcher matcher, - NonMatchingVersionReporter nonMatchingVersionReporter, - CircularDependencyStrategy circularDepStrategy) { - this.circularDepStrategy = circularDepStrategy; - moduleDescriptors = new CollectionOfModulesToSort(modulesDescriptorsToSort, matcher, - nonMatchingVersionReporter); - } - - /** - * Iterates over all modules calling sortModuleDescriptorsHelp. - * - * @return sorted module - * @throws CircularDependencyException - */ - public List sortModuleDescriptors() throws CircularDependencyException { - Message.debug("Nbr of module to sort : " + moduleDescriptors.size()); - Iterator _moduleDescriptorsIterator = moduleDescriptors.iterator(); - while (_moduleDescriptorsIterator.hasNext()) { - ModuleInSort next = (ModuleInSort) _moduleDescriptorsIterator.next(); - sortModuleDescriptorsHelp(next, next); - } - return sorted; - } - - /** - * If current module has already been added to list, returns, Otherwise invokes - * sortModuleDescriptorsHelp for all dependencies contained within set of moduleDescriptors. - * Then finally adds self to list of sorted.
      When a loop is detected by a recursive call, - * the moduleDescriptors are not added immediately added to the sorted list. They are added as - * loop dependencies of the root, and will be added to the sorted list only when the root itself - * will be added. - * - * @param current - * Current module to add to sorted list. - * @throws CircularDependencyException - */ - private void sortModuleDescriptorsHelp(ModuleInSort current, ModuleInSort caller) - throws CircularDependencyException { - // if already sorted return - if (current.isSorted()) { - return; - } - if (current.checkLoop(caller, circularDepStrategy)) { - return; - } - DependencyDescriptor[] descriptors = current.getDependencies(); - Message.debug("Sort dependencies of : " + current.toString() - + " / Number of dependencies = " + descriptors.length); - current.setCaller(caller); - for (int i = 0; i < descriptors.length; i++) { - ModuleInSort child = moduleDescriptors.getModuleDescriptorDependency(descriptors[i]); - if (child != null) { - sortModuleDescriptorsHelp(child, current); - } - } - current.endOfCall(); - Message.debug("Sort done for : " + current.toString()); - current.addToSortedListIfRequired(sorted); - } - -} \ No newline at end of file +/* + * 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.core.sort; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.plugins.circular.CircularDependencyException; +import org.apache.ivy.plugins.circular.CircularDependencyStrategy; +import org.apache.ivy.plugins.version.VersionMatcher; +import org.apache.ivy.util.Message; + +/** + * Inner helper class for sorting ModuleDescriptors.
      + * ModuleDescriptorSorter use CollectionOfModulesToSort to find the dependencies of the modules, and + * use ModuleInSort to store some temporary values attached to the modules to sort. + * + * @see ModuleInSort + * @see CollectionOfModulesToSort + */ +public class ModuleDescriptorSorter { + + private final CollectionOfModulesToSort moduleDescriptors; + + private final List sorted = new LinkedList(); + + private final CircularDependencyStrategy circularDepStrategy; + + public ModuleDescriptorSorter(Collection modulesDescriptorsToSort, VersionMatcher matcher, + NonMatchingVersionReporter nonMatchingVersionReporter, + CircularDependencyStrategy circularDepStrategy) { + this.circularDepStrategy = circularDepStrategy; + moduleDescriptors = new CollectionOfModulesToSort(modulesDescriptorsToSort, matcher, + nonMatchingVersionReporter); + } + + /** + * Iterates over all modules calling sortModuleDescriptorsHelp. + * + * @return sorted module + * @throws CircularDependencyException + */ + public List sortModuleDescriptors() throws CircularDependencyException { + Message.debug("Nbr of module to sort : " + moduleDescriptors.size()); + Iterator _moduleDescriptorsIterator = moduleDescriptors.iterator(); + while (_moduleDescriptorsIterator.hasNext()) { + ModuleInSort next = (ModuleInSort) _moduleDescriptorsIterator.next(); + sortModuleDescriptorsHelp(next, next); + } + return sorted; + } + + /** + * If current module has already been added to list, returns, Otherwise invokes + * sortModuleDescriptorsHelp for all dependencies contained within set of moduleDescriptors. + * Then finally adds self to list of sorted.
      When a loop is detected by a recursive call, + * the moduleDescriptors are not added immediately added to the sorted list. They are added as + * loop dependencies of the root, and will be added to the sorted list only when the root itself + * will be added. + * + * @param current + * Current module to add to sorted list. + * @throws CircularDependencyException + */ + private void sortModuleDescriptorsHelp(ModuleInSort current, ModuleInSort caller) + throws CircularDependencyException { + // if already sorted return + if (current.isSorted()) { + return; + } + if (current.checkLoop(caller, circularDepStrategy)) { + return; + } + DependencyDescriptor[] descriptors = current.getDependencies(); + Message.debug("Sort dependencies of : " + current.toString() + + " / Number of dependencies = " + descriptors.length); + current.setCaller(caller); + for (int i = 0; i < descriptors.length; i++) { + ModuleInSort child = moduleDescriptors.getModuleDescriptorDependency(descriptors[i]); + if (child != null) { + sortModuleDescriptorsHelp(child, current); + } + } + current.endOfCall(); + Message.debug("Sort done for : " + current.toString()); + current.addToSortedListIfRequired(sorted); + } + +} diff --git a/src/java/org/apache/ivy/core/sort/SortEngine.java b/src/java/org/apache/ivy/core/sort/SortEngine.java index 9fc262a8..edab5a74 100644 --- a/src/java/org/apache/ivy/core/sort/SortEngine.java +++ b/src/java/org/apache/ivy/core/sort/SortEngine.java @@ -1,99 +1,99 @@ -/* - * 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.core.sort; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.circular.CircularDependencyException; - -public class SortEngine { - private IvySettings settings; - - public SortEngine(IvySettings settings) { - this.settings = settings; - } - - public List sortNodes(Collection nodes) { - /* - * here we want to use the sort algorithm which work on module descriptors : so we first put - * dependencies on a map from descriptors to dependency, then we sort the keySet (i.e. a - * collection of descriptors), then we replace in the sorted list each descriptor by the - * corresponding dependency - */ - - Map dependenciesMap = new LinkedHashMap(); - List nulls = new ArrayList(); - for (Iterator iter = nodes.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - if (node.getDescriptor() == null) { - nulls.add(node); - } else { - List n = (List) dependenciesMap.get(node.getDescriptor()); - if (n == null) { - n = new ArrayList(); - dependenciesMap.put(node.getDescriptor(), n); - } - n.add(node); - } - } - List list = sortModuleDescriptors(dependenciesMap.keySet()); - List ret = new ArrayList((int) (list.size() * 1.3 + nulls.size())); // attempt to adjust the - // size to avoid too - // much list resizing - for (int i = 0; i < list.size(); i++) { - ModuleDescriptor md = (ModuleDescriptor) list.get(i); - List n = (List) dependenciesMap.get(md); - ret.addAll(n); - } - ret.addAll(0, nulls); - return ret; - } - - /** - * Sorts the given ModuleDescriptors from the less dependent to the more dependent. This sort - * ensures that a ModuleDescriptor is always found in the list before all ModuleDescriptors - * depending directly on it. - * - * @param moduleDescriptors - * a Collection of ModuleDescriptor to sort - * @return a List of sorted ModuleDescriptors - * @throws CircularDependencyException - * if a circular dependency exists - */ - public List sortModuleDescriptors(Collection moduleDescriptors) - throws CircularDependencyException { - return sortModuleDescriptors(moduleDescriptors, new DefaultNonMatchingVersionReporter()); - } - - public List sortModuleDescriptors(Collection moduleDescriptors, - NonMatchingVersionReporter nonMatchingVersionReporter) { - ModuleDescriptorSorter sorter = new ModuleDescriptorSorter(moduleDescriptors, settings - .getVersionMatcher(), nonMatchingVersionReporter, settings - .getCircularDependencyStrategy()); - return sorter.sortModuleDescriptors(); - } - -} +/* + * 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.core.sort; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.circular.CircularDependencyException; + +public class SortEngine { + private IvySettings settings; + + public SortEngine(IvySettings settings) { + this.settings = settings; + } + + public List sortNodes(Collection nodes) { + /* + * here we want to use the sort algorithm which work on module descriptors : so we first put + * dependencies on a map from descriptors to dependency, then we sort the keySet (i.e. a + * collection of descriptors), then we replace in the sorted list each descriptor by the + * corresponding dependency + */ + + Map dependenciesMap = new LinkedHashMap(); + List nulls = new ArrayList(); + for (Iterator iter = nodes.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + if (node.getDescriptor() == null) { + nulls.add(node); + } else { + List n = (List) dependenciesMap.get(node.getDescriptor()); + if (n == null) { + n = new ArrayList(); + dependenciesMap.put(node.getDescriptor(), n); + } + n.add(node); + } + } + List list = sortModuleDescriptors(dependenciesMap.keySet()); + List ret = new ArrayList((int) (list.size() * 1.3 + nulls.size())); // attempt to adjust the + // size to avoid too + // much list resizing + for (int i = 0; i < list.size(); i++) { + ModuleDescriptor md = (ModuleDescriptor) list.get(i); + List n = (List) dependenciesMap.get(md); + ret.addAll(n); + } + ret.addAll(0, nulls); + return ret; + } + + /** + * Sorts the given ModuleDescriptors from the less dependent to the more dependent. This sort + * ensures that a ModuleDescriptor is always found in the list before all ModuleDescriptors + * depending directly on it. + * + * @param moduleDescriptors + * a Collection of ModuleDescriptor to sort + * @return a List of sorted ModuleDescriptors + * @throws CircularDependencyException + * if a circular dependency exists + */ + public List sortModuleDescriptors(Collection moduleDescriptors) + throws CircularDependencyException { + return sortModuleDescriptors(moduleDescriptors, new DefaultNonMatchingVersionReporter()); + } + + public List sortModuleDescriptors(Collection moduleDescriptors, + NonMatchingVersionReporter nonMatchingVersionReporter) { + ModuleDescriptorSorter sorter = new ModuleDescriptorSorter(moduleDescriptors, settings + .getVersionMatcher(), nonMatchingVersionReporter, settings + .getCircularDependencyStrategy()); + return sorter.sortModuleDescriptors(); + } + +} diff --git a/src/java/org/apache/ivy/plugins/IvyAware.java b/src/java/org/apache/ivy/plugins/IvyAware.java index 60d1a1af..abc13688 100644 --- a/src/java/org/apache/ivy/plugins/IvyAware.java +++ b/src/java/org/apache/ivy/plugins/IvyAware.java @@ -1,24 +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. - * - */ -package org.apache.ivy.plugins; - -import org.apache.ivy.Ivy; - -public interface IvyAware { - void setIvy(Ivy ivy); -} +/* + * 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; + +import org.apache.ivy.Ivy; + +public interface IvyAware { + void setIvy(Ivy ivy); +} diff --git a/src/java/org/apache/ivy/plugins/IvySettingsAware.java b/src/java/org/apache/ivy/plugins/IvySettingsAware.java index 59cb940b..36906143 100644 --- a/src/java/org/apache/ivy/plugins/IvySettingsAware.java +++ b/src/java/org/apache/ivy/plugins/IvySettingsAware.java @@ -1,24 +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. - * - */ -package org.apache.ivy.plugins; - -import org.apache.ivy.core.settings.IvySettings; - -public interface IvySettingsAware { - void setSettings(IvySettings settings); -} +/* + * 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; + +import org.apache.ivy.core.settings.IvySettings; + +public interface IvySettingsAware { + void setSettings(IvySettings settings); +} diff --git a/src/java/org/apache/ivy/plugins/circular/AbstractCircularDependencyStrategy.java b/src/java/org/apache/ivy/plugins/circular/AbstractCircularDependencyStrategy.java index 4d0f2903..4dab673b 100644 --- a/src/java/org/apache/ivy/plugins/circular/AbstractCircularDependencyStrategy.java +++ b/src/java/org/apache/ivy/plugins/circular/AbstractCircularDependencyStrategy.java @@ -1,34 +1,34 @@ -/* - * 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.circular; - -public abstract class AbstractCircularDependencyStrategy implements CircularDependencyStrategy { - private String _name; - - protected AbstractCircularDependencyStrategy(String name) { - _name = name; - } - - public String getName() { - return _name; - } - - public String toString() { - return getName(); - } -} +/* + * 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.circular; + +public abstract class AbstractCircularDependencyStrategy implements CircularDependencyStrategy { + private String _name; + + protected AbstractCircularDependencyStrategy(String name) { + _name = name; + } + + public String getName() { + return _name; + } + + public String toString() { + return getName(); + } +} diff --git a/src/java/org/apache/ivy/plugins/circular/CircularDependencyException.java b/src/java/org/apache/ivy/plugins/circular/CircularDependencyException.java index d7438fcc..b74853a6 100644 --- a/src/java/org/apache/ivy/plugins/circular/CircularDependencyException.java +++ b/src/java/org/apache/ivy/plugins/circular/CircularDependencyException.java @@ -1,43 +1,43 @@ -/* - * 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.circular; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -/** - * Unchecked exception thrown when a circular dependency exists between projects. - */ - -public class CircularDependencyException extends RuntimeException { - - private ModuleRevisionId[] _mrids; - - /** - * @param descriptors - * module descriptors in order of circular dependency - */ - public CircularDependencyException(final ModuleRevisionId[] mrids) { - super(CircularDependencyHelper.formatMessage(mrids)); - _mrids = mrids; - } - - public ModuleRevisionId[] getPath() { - return _mrids; - } - -} \ No newline at end of file +/* + * 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.circular; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +/** + * Unchecked exception thrown when a circular dependency exists between projects. + */ + +public class CircularDependencyException extends RuntimeException { + + private ModuleRevisionId[] _mrids; + + /** + * @param descriptors + * module descriptors in order of circular dependency + */ + public CircularDependencyException(final ModuleRevisionId[] mrids) { + super(CircularDependencyHelper.formatMessage(mrids)); + _mrids = mrids; + } + + public ModuleRevisionId[] getPath() { + return _mrids; + } + +} diff --git a/src/java/org/apache/ivy/plugins/circular/CircularDependencyHelper.java b/src/java/org/apache/ivy/plugins/circular/CircularDependencyHelper.java index 0a2ea41e..4d7925bd 100644 --- a/src/java/org/apache/ivy/plugins/circular/CircularDependencyHelper.java +++ b/src/java/org/apache/ivy/plugins/circular/CircularDependencyHelper.java @@ -1,72 +1,72 @@ -/* - * 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.circular; - -import java.util.Iterator; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class CircularDependencyHelper { - - /** - * Returns a string representation of this circular dependency graph - * - * @param descriptors - * in order of circular dependency - * @return - */ - public static String formatMessage(final ModuleRevisionId[] mrids) { - StringBuffer buff = new StringBuffer(); - buff.append(mrids[0]); - for (int i = 1; i < mrids.length; i++) { - buff.append("->"); - buff.append(mrids[i]); - } - return buff.toString(); - } - - public static String formatMessage(final ModuleDescriptor[] descriptors) { - return formatMessage(toMrids(descriptors)); - } - - /** - * @param loopElements - * a List - */ - public static String formatMessageFromDescriptors(List loopElements) { - ModuleRevisionId[] mrids = new ModuleRevisionId[loopElements.size()]; - int pos = 0; - for (Iterator it = loopElements.iterator(); it.hasNext();) { - ModuleDescriptor descriptor = (ModuleDescriptor) it.next(); - mrids[pos] = descriptor.getModuleRevisionId(); - pos++; - } - return formatMessage(mrids); - } - - public static ModuleRevisionId[] toMrids(ModuleDescriptor[] descriptors) { - ModuleRevisionId[] mrids = new ModuleRevisionId[descriptors.length]; - for (int i = 0; i < descriptors.length; i++) { - mrids[i] = descriptors[i].getModuleRevisionId(); - } - return mrids; - } - -} +/* + * 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.circular; + +import java.util.Iterator; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class CircularDependencyHelper { + + /** + * Returns a string representation of this circular dependency graph + * + * @param descriptors + * in order of circular dependency + * @return + */ + public static String formatMessage(final ModuleRevisionId[] mrids) { + StringBuffer buff = new StringBuffer(); + buff.append(mrids[0]); + for (int i = 1; i < mrids.length; i++) { + buff.append("->"); + buff.append(mrids[i]); + } + return buff.toString(); + } + + public static String formatMessage(final ModuleDescriptor[] descriptors) { + return formatMessage(toMrids(descriptors)); + } + + /** + * @param loopElements + * a List + */ + public static String formatMessageFromDescriptors(List loopElements) { + ModuleRevisionId[] mrids = new ModuleRevisionId[loopElements.size()]; + int pos = 0; + for (Iterator it = loopElements.iterator(); it.hasNext();) { + ModuleDescriptor descriptor = (ModuleDescriptor) it.next(); + mrids[pos] = descriptor.getModuleRevisionId(); + pos++; + } + return formatMessage(mrids); + } + + public static ModuleRevisionId[] toMrids(ModuleDescriptor[] descriptors) { + ModuleRevisionId[] mrids = new ModuleRevisionId[descriptors.length]; + for (int i = 0; i < descriptors.length; i++) { + mrids[i] = descriptors[i].getModuleRevisionId(); + } + return mrids; + } + +} diff --git a/src/java/org/apache/ivy/plugins/circular/CircularDependencyStrategy.java b/src/java/org/apache/ivy/plugins/circular/CircularDependencyStrategy.java index 0598b60e..f70049c7 100644 --- a/src/java/org/apache/ivy/plugins/circular/CircularDependencyStrategy.java +++ b/src/java/org/apache/ivy/plugins/circular/CircularDependencyStrategy.java @@ -1,27 +1,27 @@ -/* - * 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.circular; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public interface CircularDependencyStrategy { - String getName(); - - void handleCircularDependency(ModuleRevisionId[] mrids); - -} +/* + * 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.circular; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public interface CircularDependencyStrategy { + String getName(); + + void handleCircularDependency(ModuleRevisionId[] mrids); + +} diff --git a/src/java/org/apache/ivy/plugins/circular/ErrorCircularDependencyStrategy.java b/src/java/org/apache/ivy/plugins/circular/ErrorCircularDependencyStrategy.java index b5deb305..fb0e4e3d 100644 --- a/src/java/org/apache/ivy/plugins/circular/ErrorCircularDependencyStrategy.java +++ b/src/java/org/apache/ivy/plugins/circular/ErrorCircularDependencyStrategy.java @@ -1,37 +1,37 @@ -/* - * 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.circular; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class ErrorCircularDependencyStrategy extends AbstractCircularDependencyStrategy { - - private static final CircularDependencyStrategy INSTANCE = new ErrorCircularDependencyStrategy(); - - public static CircularDependencyStrategy getInstance() { - return INSTANCE; - } - - private ErrorCircularDependencyStrategy() { - super("error"); - } - - public void handleCircularDependency(ModuleRevisionId[] mrids) { - throw new CircularDependencyException(mrids); - } -} +/* + * 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.circular; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class ErrorCircularDependencyStrategy extends AbstractCircularDependencyStrategy { + + private static final CircularDependencyStrategy INSTANCE = new ErrorCircularDependencyStrategy(); + + public static CircularDependencyStrategy getInstance() { + return INSTANCE; + } + + private ErrorCircularDependencyStrategy() { + super("error"); + } + + public void handleCircularDependency(ModuleRevisionId[] mrids) { + throw new CircularDependencyException(mrids); + } +} diff --git a/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java b/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java index b2fe2bef..4e88386d 100644 --- a/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java +++ b/src/java/org/apache/ivy/plugins/circular/IgnoreCircularDependencyStrategy.java @@ -1,39 +1,39 @@ -/* - * 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.circular; - -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.util.Message; - -public class IgnoreCircularDependencyStrategy extends AbstractCircularDependencyStrategy { - - private static final CircularDependencyStrategy INSTANCE = new IgnoreCircularDependencyStrategy(); - - public static CircularDependencyStrategy getInstance() { - return INSTANCE; - } - - private IgnoreCircularDependencyStrategy() { - super("ignore"); - } - - public void handleCircularDependency(ModuleRevisionId[] mrids) { - Message.verbose("circular dependency found: " - + CircularDependencyHelper.formatMessage(mrids)); - } -} +/* + * 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.circular; + +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.util.Message; + +public class IgnoreCircularDependencyStrategy extends AbstractCircularDependencyStrategy { + + private static final CircularDependencyStrategy INSTANCE = new IgnoreCircularDependencyStrategy(); + + public static CircularDependencyStrategy getInstance() { + return INSTANCE; + } + + private IgnoreCircularDependencyStrategy() { + super("ignore"); + } + + public void handleCircularDependency(ModuleRevisionId[] mrids) { + Message.verbose("circular dependency found: " + + CircularDependencyHelper.formatMessage(mrids)); + } +} diff --git a/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java b/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java index 565decc1..dd7a85cf 100644 --- a/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java +++ b/src/java/org/apache/ivy/plugins/circular/WarnCircularDependencyStrategy.java @@ -1,38 +1,38 @@ -/* - * 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.circular; - -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.util.Message; - -public class WarnCircularDependencyStrategy extends AbstractCircularDependencyStrategy { - - private static final CircularDependencyStrategy INSTANCE = new WarnCircularDependencyStrategy(); - - public static CircularDependencyStrategy getInstance() { - return INSTANCE; - } - - private WarnCircularDependencyStrategy() { - super("warn"); - } - - public void handleCircularDependency(ModuleRevisionId[] mrids) { - Message.warn("circular dependency found: " + CircularDependencyHelper.formatMessage(mrids)); - } -} +/* + * 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.circular; + +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.util.Message; + +public class WarnCircularDependencyStrategy extends AbstractCircularDependencyStrategy { + + private static final CircularDependencyStrategy INSTANCE = new WarnCircularDependencyStrategy(); + + public static CircularDependencyStrategy getInstance() { + return INSTANCE; + } + + private WarnCircularDependencyStrategy() { + super("warn"); + } + + public void handleCircularDependency(ModuleRevisionId[] mrids) { + Message.warn("circular dependency found: " + CircularDependencyHelper.formatMessage(mrids)); + } +} diff --git a/src/java/org/apache/ivy/plugins/conflict/AbstractConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/AbstractConflictManager.java index d6390c84..417847a4 100644 --- a/src/java/org/apache/ivy/plugins/conflict/AbstractConflictManager.java +++ b/src/java/org/apache/ivy/plugins/conflict/AbstractConflictManager.java @@ -1,47 +1,47 @@ -/* - * 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.conflict; - -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.IvySettingsAware; - -public abstract class AbstractConflictManager implements ConflictManager, IvySettingsAware { - private String _name; - - private IvySettings _settings; - - public IvySettings getSettings() { - return _settings; - } - - public void setSettings(IvySettings ivy) { - _settings = ivy; - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public String toString() { - return _name; - } -} +/* + * 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.conflict; + +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.IvySettingsAware; + +public abstract class AbstractConflictManager implements ConflictManager, IvySettingsAware { + private String _name; + + private IvySettings _settings; + + public IvySettings getSettings() { + return _settings; + } + + public void setSettings(IvySettings ivy) { + _settings = ivy; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public String toString() { + return _name; + } +} diff --git a/src/java/org/apache/ivy/plugins/conflict/ConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/ConflictManager.java index 03f90d2b..740d9572 100644 --- a/src/java/org/apache/ivy/plugins/conflict/ConflictManager.java +++ b/src/java/org/apache/ivy/plugins/conflict/ConflictManager.java @@ -1,43 +1,43 @@ -/* - * 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.conflict; - -import java.util.Collection; - -import org.apache.ivy.core.resolve.IvyNode; - -public interface ConflictManager { - /** - * Resolves the eventual conflicts found in the given collection of IvyNode. This method return - * a Collection of IvyNode which have not been evicted. The given conflicts Collection contains - * at least one IvyNode. This method can be called with IvyNodes which are not yet loaded. If - * this conflict manager is not able to resolve conflicts with the current data found in the - * IvyNodes and need them to be fully loaded, it will return null to indicate that no conflict - * resolution has been done. - * - * @param parent - * the ivy node parent for which the conflict is to be resolved - * @param conflicts - * the collection of IvyNode to check for conflicts - * @return a Collection of IvyNode which have not been evicted, or null if conflict management - * resolution is not possible yet - */ - Collection resolveConflicts(IvyNode parent, Collection conflicts); - - String getName(); -} +/* + * 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.conflict; + +import java.util.Collection; + +import org.apache.ivy.core.resolve.IvyNode; + +public interface ConflictManager { + /** + * Resolves the eventual conflicts found in the given collection of IvyNode. This method return + * a Collection of IvyNode which have not been evicted. The given conflicts Collection contains + * at least one IvyNode. This method can be called with IvyNodes which are not yet loaded. If + * this conflict manager is not able to resolve conflicts with the current data found in the + * IvyNodes and need them to be fully loaded, it will return null to indicate that no conflict + * resolution has been done. + * + * @param parent + * the ivy node parent for which the conflict is to be resolved + * @param conflicts + * the collection of IvyNode to check for conflicts + * @return a Collection of IvyNode which have not been evicted, or null if conflict management + * resolution is not possible yet + */ + Collection resolveConflicts(IvyNode parent, Collection conflicts); + + String getName(); +} diff --git a/src/java/org/apache/ivy/plugins/conflict/FixedConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/FixedConflictManager.java index d35dcd82..29ae2a3f 100644 --- a/src/java/org/apache/ivy/plugins/conflict/FixedConflictManager.java +++ b/src/java/org/apache/ivy/plugins/conflict/FixedConflictManager.java @@ -1,51 +1,51 @@ -/* - * 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.conflict; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.ivy.core.resolve.IvyNode; - -public class FixedConflictManager extends AbstractConflictManager { - private Collection _revs; - - public FixedConflictManager(String[] revs) { - _revs = Arrays.asList(revs); - setName("fixed" + _revs); - } - - public Collection resolveConflicts(IvyNode parent, Collection conflicts) { - Collection resolved = new ArrayList(conflicts.size()); - for (Iterator iter = conflicts.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - String revision = node.getResolvedId().getRevision(); - if (_revs.contains(revision)) { - resolved.add(node); - } - } - return resolved; - } - - public Collection getRevs() { - return _revs; - } - -} +/* + * 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.conflict; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.ivy.core.resolve.IvyNode; + +public class FixedConflictManager extends AbstractConflictManager { + private Collection _revs; + + public FixedConflictManager(String[] revs) { + _revs = Arrays.asList(revs); + setName("fixed" + _revs); + } + + public Collection resolveConflicts(IvyNode parent, Collection conflicts) { + Collection resolved = new ArrayList(conflicts.size()); + for (Iterator iter = conflicts.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + String revision = node.getResolvedId().getRevision(); + if (_revs.contains(revision)) { + resolved.add(node); + } + } + return resolved; + } + + public Collection getRevs() { + return _revs; + } + +} diff --git a/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java index 558bc102..5648a179 100644 --- a/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java +++ b/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java @@ -1,146 +1,146 @@ -/* - * 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.conflict; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.plugins.latest.ArtifactInfo; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.util.Message; - -public class LatestConflictManager extends AbstractConflictManager { - public static class NoConflictResolvedYetException extends RuntimeException { - } - - private static class IvyNodeArtifactInfo implements ArtifactInfo { - private final IvyNode _node; - - private IvyNodeArtifactInfo(IvyNode dep) { - _node = dep; - } - - public long getLastModified() { - long lastModified = _node.getLastModified(); - if (lastModified == 0) { - // if the last modified timestamp is unknown, we can't resolve - // the conflicts now, and trigger an exception which will be catched - // in the main resolveConflicts method - throw new NoConflictResolvedYetException(); - } else { - return lastModified; - } - } - - public String getRevision() { - return _node.getResolvedId().getRevision(); - } - - public IvyNode getNode() { - return _node; - } - } - - private LatestStrategy _strategy; - - private String _strategyName; - - public LatestConflictManager() { - } - - public LatestConflictManager(LatestStrategy strategy) { - _strategy = strategy; - } - - public LatestConflictManager(String name, LatestStrategy strategy) { - setName(name); - _strategy = strategy; - } - - public Collection resolveConflicts(IvyNode parent, Collection conflicts) { - if (conflicts.size() < 2) { - return conflicts; - } - for (Iterator iter = conflicts.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - DependencyDescriptor dd = node.getDependencyDescriptor(parent); - if (dd != null && dd.isForce() - && parent.getResolvedId().equals(dd.getParentRevisionId())) { - return Collections.singleton(node); - } - } - try { - ArtifactInfo latest = getStrategy().findLatest(toArtifactInfo(conflicts), null); - if (latest != null) { - return Collections.singleton(((IvyNodeArtifactInfo) latest).getNode()); - } else { - return conflicts; - } - } catch (NoConflictResolvedYetException ex) { - // we have not enough informations in the nodes to resolve conflict - // according to the resolveConflicts contract, we must return null - return null; - } - } - - private ArtifactInfo[] toArtifactInfo(Collection conflicts) { - List artifacts = new ArrayList(conflicts.size()); - for (Iterator iter = conflicts.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - artifacts.add(new IvyNodeArtifactInfo(node)); - } - return (ArtifactInfo[]) artifacts.toArray(new ArtifactInfo[artifacts.size()]); - } - - public LatestStrategy getStrategy() { - if (_strategy == null) { - if (_strategyName != null) { - _strategy = getSettings().getLatestStrategy(_strategyName); - if (_strategy == null) { - Message.error("unknown latest strategy: " + _strategyName); - _strategy = getSettings().getDefaultLatestStrategy(); - } - } else { - _strategy = getSettings().getDefaultLatestStrategy(); - } - } - return _strategy; - } - - /** - * To conform to configurator API - * - * @param latestStrategy - */ - public void setLatest(String strategyName) { - _strategyName = strategyName; - } - - public void setStrategy(LatestStrategy strategy) { - _strategy = strategy; - } - - public String toString() { - return _strategy != null ? String.valueOf(_strategy) : _strategyName; - } -} +/* + * 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.conflict; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.plugins.latest.ArtifactInfo; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.util.Message; + +public class LatestConflictManager extends AbstractConflictManager { + public static class NoConflictResolvedYetException extends RuntimeException { + } + + private static class IvyNodeArtifactInfo implements ArtifactInfo { + private final IvyNode _node; + + private IvyNodeArtifactInfo(IvyNode dep) { + _node = dep; + } + + public long getLastModified() { + long lastModified = _node.getLastModified(); + if (lastModified == 0) { + // if the last modified timestamp is unknown, we can't resolve + // the conflicts now, and trigger an exception which will be catched + // in the main resolveConflicts method + throw new NoConflictResolvedYetException(); + } else { + return lastModified; + } + } + + public String getRevision() { + return _node.getResolvedId().getRevision(); + } + + public IvyNode getNode() { + return _node; + } + } + + private LatestStrategy _strategy; + + private String _strategyName; + + public LatestConflictManager() { + } + + public LatestConflictManager(LatestStrategy strategy) { + _strategy = strategy; + } + + public LatestConflictManager(String name, LatestStrategy strategy) { + setName(name); + _strategy = strategy; + } + + public Collection resolveConflicts(IvyNode parent, Collection conflicts) { + if (conflicts.size() < 2) { + return conflicts; + } + for (Iterator iter = conflicts.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + DependencyDescriptor dd = node.getDependencyDescriptor(parent); + if (dd != null && dd.isForce() + && parent.getResolvedId().equals(dd.getParentRevisionId())) { + return Collections.singleton(node); + } + } + try { + ArtifactInfo latest = getStrategy().findLatest(toArtifactInfo(conflicts), null); + if (latest != null) { + return Collections.singleton(((IvyNodeArtifactInfo) latest).getNode()); + } else { + return conflicts; + } + } catch (NoConflictResolvedYetException ex) { + // we have not enough informations in the nodes to resolve conflict + // according to the resolveConflicts contract, we must return null + return null; + } + } + + private ArtifactInfo[] toArtifactInfo(Collection conflicts) { + List artifacts = new ArrayList(conflicts.size()); + for (Iterator iter = conflicts.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + artifacts.add(new IvyNodeArtifactInfo(node)); + } + return (ArtifactInfo[]) artifacts.toArray(new ArtifactInfo[artifacts.size()]); + } + + public LatestStrategy getStrategy() { + if (_strategy == null) { + if (_strategyName != null) { + _strategy = getSettings().getLatestStrategy(_strategyName); + if (_strategy == null) { + Message.error("unknown latest strategy: " + _strategyName); + _strategy = getSettings().getDefaultLatestStrategy(); + } + } else { + _strategy = getSettings().getDefaultLatestStrategy(); + } + } + return _strategy; + } + + /** + * To conform to configurator API + * + * @param latestStrategy + */ + public void setLatest(String strategyName) { + _strategyName = strategyName; + } + + public void setStrategy(LatestStrategy strategy) { + _strategy = strategy; + } + + public String toString() { + return _strategy != null ? String.valueOf(_strategy) : _strategyName; + } +} diff --git a/src/java/org/apache/ivy/plugins/conflict/NoConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/NoConflictManager.java index 77ccf451..cd6f5cee 100644 --- a/src/java/org/apache/ivy/plugins/conflict/NoConflictManager.java +++ b/src/java/org/apache/ivy/plugins/conflict/NoConflictManager.java @@ -1,32 +1,32 @@ -/* - * 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.conflict; - -import java.util.Collection; - -import org.apache.ivy.core.resolve.IvyNode; - -public class NoConflictManager extends AbstractConflictManager { - public NoConflictManager() { - setName("all"); - } - - public Collection resolveConflicts(IvyNode parent, Collection conflicts) { - return conflicts; - } -} +/* + * 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.conflict; + +import java.util.Collection; + +import org.apache.ivy.core.resolve.IvyNode; + +public class NoConflictManager extends AbstractConflictManager { + public NoConflictManager() { + setName("all"); + } + + public Collection resolveConflicts(IvyNode parent, Collection conflicts) { + return conflicts; + } +} diff --git a/src/java/org/apache/ivy/plugins/conflict/RegexpConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/RegexpConflictManager.java index 58ff24d2..dc3f5ce0 100644 --- a/src/java/org/apache/ivy/plugins/conflict/RegexpConflictManager.java +++ b/src/java/org/apache/ivy/plugins/conflict/RegexpConflictManager.java @@ -1,121 +1,121 @@ -/* - * 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.conflict; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.util.Message; - -/** - * A ConflictManager that can be used to resolve conflicts based on regular expressions of the - * revision of the module. The conflict manager is added like this: - * - *
      - *    <!-- Match all revisions, but ignore the last dot(.) and the character after it.
      - *        Used to match api changes in out milestones. -->
      - *    <conflict-managers>
      - *        <regexp-cm name="regexp" regexp="(.*)\..$" ignoreNonMatching="true"/>
      - *    </conflict-managers>
      - * 
      - * - * The regular expression must contain a capturing group. The group will be used to resolve the - * conflicts by an String.equals() test. If ignoreNonMatching is false non matching modules will - * result in an exception. If it is true they will be compaired by their full revision. - */ -public class RegexpConflictManager extends AbstractConflictManager { - private Pattern pattern = Pattern.compile("(.*)"); - - private boolean mIgnoreNonMatching; - - public RegexpConflictManager() { - } - - public void setRegexp(String regexp) { - pattern = Pattern.compile(regexp); - Matcher matcher = pattern.matcher("abcdef"); - if (matcher.groupCount() != 1) { - String message = "Pattern does not contain ONE (capturing group): '" + pattern + "'"; - Message.error(message); - throw new IllegalArgumentException(message); - } - } - - public void setIgnoreNonMatching(boolean ignoreNonMatching) { - mIgnoreNonMatching = ignoreNonMatching; - } - - public Collection resolveConflicts(IvyNode parent, Collection conflicts) { - IvyNode lastNode = null; - for (Iterator iter = conflicts.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - - if (lastNode != null && !matchEquals(node, lastNode)) { - String msg = lastNode + ":" + getMatch(lastNode) + " (needed by " - + Arrays.asList(lastNode.getAllCallers()) + ") conflicts with " + node - + ":" + getMatch(node) + " (needed by " - + Arrays.asList(node.getAllCallers()) + ")"; - Message.error(msg); - Message.sumupProblems(); - throw new StrictConflictException(msg); - } - if (lastNode == null || nodeIsGreater(node, lastNode)) { - lastNode = node; - } - } - - return Collections.singleton(lastNode); - } - - private boolean nodeIsGreater(IvyNode node, IvyNode lastNode) { - return getMatch(node).compareTo(getMatch(lastNode)) > 0; - } - - private boolean matchEquals(IvyNode lastNode, IvyNode node) { - return getMatch(lastNode).equals(getMatch(node)); - } - - private String getMatch(IvyNode node) { - String revision = node.getId().getRevision(); - Matcher matcher = pattern.matcher(revision); - if (matcher.matches()) { - String match = matcher.group(1); - if (match != null) { - return match; - } - warnOrThrow("First group of pattern: '" + pattern + "' does not match: " + revision - + " " + node); - } else { - warnOrThrow("Pattern: '" + pattern + "' does not match: " + revision + " " + node); - } - return revision; - } - - private void warnOrThrow(String message) { - if (mIgnoreNonMatching) { - Message.warn(message); - } else { - throw new StrictConflictException(message); - } - } -} +/* + * 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.conflict; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.util.Message; + +/** + * A ConflictManager that can be used to resolve conflicts based on regular expressions of the + * revision of the module. The conflict manager is added like this: + * + *
      + *    <!-- Match all revisions, but ignore the last dot(.) and the character after it.
      + *        Used to match api changes in out milestones. -->
      + *    <conflict-managers>
      + *        <regexp-cm name="regexp" regexp="(.*)\..$" ignoreNonMatching="true"/>
      + *    </conflict-managers>
      + * 
      + * + * The regular expression must contain a capturing group. The group will be used to resolve the + * conflicts by an String.equals() test. If ignoreNonMatching is false non matching modules will + * result in an exception. If it is true they will be compaired by their full revision. + */ +public class RegexpConflictManager extends AbstractConflictManager { + private Pattern pattern = Pattern.compile("(.*)"); + + private boolean mIgnoreNonMatching; + + public RegexpConflictManager() { + } + + public void setRegexp(String regexp) { + pattern = Pattern.compile(regexp); + Matcher matcher = pattern.matcher("abcdef"); + if (matcher.groupCount() != 1) { + String message = "Pattern does not contain ONE (capturing group): '" + pattern + "'"; + Message.error(message); + throw new IllegalArgumentException(message); + } + } + + public void setIgnoreNonMatching(boolean ignoreNonMatching) { + mIgnoreNonMatching = ignoreNonMatching; + } + + public Collection resolveConflicts(IvyNode parent, Collection conflicts) { + IvyNode lastNode = null; + for (Iterator iter = conflicts.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + + if (lastNode != null && !matchEquals(node, lastNode)) { + String msg = lastNode + ":" + getMatch(lastNode) + " (needed by " + + Arrays.asList(lastNode.getAllCallers()) + ") conflicts with " + node + + ":" + getMatch(node) + " (needed by " + + Arrays.asList(node.getAllCallers()) + ")"; + Message.error(msg); + Message.sumupProblems(); + throw new StrictConflictException(msg); + } + if (lastNode == null || nodeIsGreater(node, lastNode)) { + lastNode = node; + } + } + + return Collections.singleton(lastNode); + } + + private boolean nodeIsGreater(IvyNode node, IvyNode lastNode) { + return getMatch(node).compareTo(getMatch(lastNode)) > 0; + } + + private boolean matchEquals(IvyNode lastNode, IvyNode node) { + return getMatch(lastNode).equals(getMatch(node)); + } + + private String getMatch(IvyNode node) { + String revision = node.getId().getRevision(); + Matcher matcher = pattern.matcher(revision); + if (matcher.matches()) { + String match = matcher.group(1); + if (match != null) { + return match; + } + warnOrThrow("First group of pattern: '" + pattern + "' does not match: " + revision + + " " + node); + } else { + warnOrThrow("Pattern: '" + pattern + "' does not match: " + revision + " " + node); + } + return revision; + } + + private void warnOrThrow(String message) { + if (mIgnoreNonMatching) { + Message.warn(message); + } else { + throw new StrictConflictException(message); + } + } +} diff --git a/src/java/org/apache/ivy/plugins/conflict/StrictConflictException.java b/src/java/org/apache/ivy/plugins/conflict/StrictConflictException.java index e78e1dac..ada3654d 100644 --- a/src/java/org/apache/ivy/plugins/conflict/StrictConflictException.java +++ b/src/java/org/apache/ivy/plugins/conflict/StrictConflictException.java @@ -1,38 +1,38 @@ -/* - * 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.conflict; - -public class StrictConflictException extends RuntimeException { - - public StrictConflictException() { - super(); - } - - public StrictConflictException(String msg) { - super(msg); - } - - public StrictConflictException(Throwable t) { - super(t); - } - - public StrictConflictException(String msg, Throwable t) { - super(msg, t); - } - -} +/* + * 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.conflict; + +public class StrictConflictException extends RuntimeException { + + public StrictConflictException() { + super(); + } + + public StrictConflictException(String msg) { + super(msg); + } + + public StrictConflictException(Throwable t) { + super(t); + } + + public StrictConflictException(String msg, Throwable t) { + super(msg, t); + } + +} diff --git a/src/java/org/apache/ivy/plugins/conflict/StrictConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/StrictConflictManager.java index fc172536..01836855 100644 --- a/src/java/org/apache/ivy/plugins/conflict/StrictConflictManager.java +++ b/src/java/org/apache/ivy/plugins/conflict/StrictConflictManager.java @@ -1,52 +1,52 @@ -/* - * 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.conflict; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.util.Message; - -public class StrictConflictManager extends AbstractConflictManager { - - public StrictConflictManager() { - } - - public Collection resolveConflicts(IvyNode parent, Collection conflicts) { - IvyNode lastNode = null; - for (Iterator iter = conflicts.iterator(); iter.hasNext();) { - IvyNode node = (IvyNode) iter.next(); - - if (lastNode != null && !lastNode.equals(node)) { - String msg = lastNode + " (needed by " + Arrays.asList(lastNode.getAllCallers()) - + ") conflicts with " + node + " (needed by " - + Arrays.asList(node.getAllCallers()) + ")"; - Message.error(msg); - Message.sumupProblems(); - throw new StrictConflictException(msg); - } - lastNode = node; - } - - return Collections.singleton(lastNode); - } - -} +/* + * 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.conflict; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; + +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.util.Message; + +public class StrictConflictManager extends AbstractConflictManager { + + public StrictConflictManager() { + } + + public Collection resolveConflicts(IvyNode parent, Collection conflicts) { + IvyNode lastNode = null; + for (Iterator iter = conflicts.iterator(); iter.hasNext();) { + IvyNode node = (IvyNode) iter.next(); + + if (lastNode != null && !lastNode.equals(node)) { + String msg = lastNode + " (needed by " + Arrays.asList(lastNode.getAllCallers()) + + ") conflicts with " + node + " (needed by " + + Arrays.asList(node.getAllCallers()) + ")"; + Message.error(msg); + Message.sumupProblems(); + throw new StrictConflictException(msg); + } + lastNode = node; + } + + return Collections.singleton(lastNode); + } + +} diff --git a/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java b/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java index 67d5170f..d2c03777 100644 --- a/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java +++ b/src/java/org/apache/ivy/plugins/latest/AbstractLatestStrategy.java @@ -1,65 +1,65 @@ -/* - * 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.latest; - -import java.util.Date; -import java.util.List; -import java.util.ListIterator; - -import org.apache.ivy.Ivy; -import org.apache.ivy.plugins.IvyAware; - -public abstract class AbstractLatestStrategy implements LatestStrategy, IvyAware { - private String _name; - - private Ivy _ivy; - - public Ivy getIvy() { - return _ivy; - } - - public void setIvy(Ivy ivy) { - _ivy = ivy; - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public String toString() { - return _name; - } - - public ArtifactInfo findLatest(ArtifactInfo[] infos, Date date) { - List l = sort(infos); - - // the latest revision comes last, use a ListIterator to iterate the - // sorted list in the reverse direction. - for (ListIterator iter = l.listIterator(l.size()); iter.hasPrevious();) { - ArtifactInfo info = (ArtifactInfo) iter.previous(); - if (date == null || info.getLastModified() < date.getTime()) { - return info; - } - } - return null; - } -} +/* + * 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.latest; + +import java.util.Date; +import java.util.List; +import java.util.ListIterator; + +import org.apache.ivy.Ivy; +import org.apache.ivy.plugins.IvyAware; + +public abstract class AbstractLatestStrategy implements LatestStrategy, IvyAware { + private String _name; + + private Ivy _ivy; + + public Ivy getIvy() { + return _ivy; + } + + public void setIvy(Ivy ivy) { + _ivy = ivy; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public String toString() { + return _name; + } + + public ArtifactInfo findLatest(ArtifactInfo[] infos, Date date) { + List l = sort(infos); + + // the latest revision comes last, use a ListIterator to iterate the + // sorted list in the reverse direction. + for (ListIterator iter = l.listIterator(l.size()); iter.hasPrevious();) { + ArtifactInfo info = (ArtifactInfo) iter.previous(); + if (date == null || info.getLastModified() < date.getTime()) { + return info; + } + } + return null; + } +} diff --git a/src/java/org/apache/ivy/plugins/latest/ArtifactInfo.java b/src/java/org/apache/ivy/plugins/latest/ArtifactInfo.java index 6ae4cc41..f76bc133 100644 --- a/src/java/org/apache/ivy/plugins/latest/ArtifactInfo.java +++ b/src/java/org/apache/ivy/plugins/latest/ArtifactInfo.java @@ -1,24 +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. - * - */ -package org.apache.ivy.plugins.latest; - -public interface ArtifactInfo { - String getRevision(); - - long getLastModified(); -} +/* + * 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.latest; + +public interface ArtifactInfo { + String getRevision(); + + long getLastModified(); +} diff --git a/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java b/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java index a43dc65a..9ebe296f 100644 --- a/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java +++ b/src/java/org/apache/ivy/plugins/latest/ComparatorLatestStrategy.java @@ -1,51 +1,51 @@ -/* - * 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.latest; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -public class ComparatorLatestStrategy extends AbstractLatestStrategy { - - private Comparator _comparator; - - public ComparatorLatestStrategy() { - } - - public ComparatorLatestStrategy(Comparator comparator) { - _comparator = comparator; - } - - public List sort(ArtifactInfo[] infos) { - List ret = new ArrayList(Arrays.asList(infos)); - Collections.sort(ret, _comparator); - return ret; - } - - public Comparator getComparator() { - return _comparator; - } - - public void setComparator(Comparator comparator) { - _comparator = comparator; - } - -} +/* + * 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.latest; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class ComparatorLatestStrategy extends AbstractLatestStrategy { + + private Comparator _comparator; + + public ComparatorLatestStrategy() { + } + + public ComparatorLatestStrategy(Comparator comparator) { + _comparator = comparator; + } + + public List sort(ArtifactInfo[] infos) { + List ret = new ArrayList(Arrays.asList(infos)); + Collections.sort(ret, _comparator); + return ret; + } + + public Comparator getComparator() { + return _comparator; + } + + public void setComparator(Comparator comparator) { + _comparator = comparator; + } + +} diff --git a/src/java/org/apache/ivy/plugins/latest/LatestLexicographicStrategy.java b/src/java/org/apache/ivy/plugins/latest/LatestLexicographicStrategy.java index 4c9bbf66..ada0d015 100644 --- a/src/java/org/apache/ivy/plugins/latest/LatestLexicographicStrategy.java +++ b/src/java/org/apache/ivy/plugins/latest/LatestLexicographicStrategy.java @@ -1,55 +1,55 @@ -/* - * 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.latest; - -import java.util.Comparator; - -public class LatestLexicographicStrategy extends ComparatorLatestStrategy { - /** - * Compares two revisions. Revisions are compared lexicographically unless a 'latest' revision - * is found. If the latest revision found is an absolute latest (latest. like), then it is - * assumed to be the greater. If a partial latest is found, then it is assumed to be greater - * than any matching fixed revision. - */ - private static Comparator COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - String rev1 = ((ArtifactInfo) o1).getRevision(); - String rev2 = ((ArtifactInfo) o2).getRevision(); - if (rev1.startsWith("latest")) { - return 1; - } - if (rev1.endsWith("+") && rev2.startsWith(rev1.substring(0, rev1.length() - 1))) { - return 1; - } - if (rev2.startsWith("latest")) { - return -1; - } - if (rev2.endsWith("+") && rev1.startsWith(rev2.substring(0, rev2.length() - 1))) { - return -1; - } - return rev1.compareTo(rev2); - } - - }; - - public LatestLexicographicStrategy() { - super(COMPARATOR); - setName("latest-lexico"); - } - -} +/* + * 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.latest; + +import java.util.Comparator; + +public class LatestLexicographicStrategy extends ComparatorLatestStrategy { + /** + * Compares two revisions. Revisions are compared lexicographically unless a 'latest' revision + * is found. If the latest revision found is an absolute latest (latest. like), then it is + * assumed to be the greater. If a partial latest is found, then it is assumed to be greater + * than any matching fixed revision. + */ + private static Comparator COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + String rev1 = ((ArtifactInfo) o1).getRevision(); + String rev2 = ((ArtifactInfo) o2).getRevision(); + if (rev1.startsWith("latest")) { + return 1; + } + if (rev1.endsWith("+") && rev2.startsWith(rev1.substring(0, rev1.length() - 1))) { + return 1; + } + if (rev2.startsWith("latest")) { + return -1; + } + if (rev2.endsWith("+") && rev1.startsWith(rev2.substring(0, rev2.length() - 1))) { + return -1; + } + return rev1.compareTo(rev2); + } + + }; + + public LatestLexicographicStrategy() { + super(COMPARATOR); + setName("latest-lexico"); + } + +} diff --git a/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java b/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java index 5e66a1b5..ec7acc7d 100644 --- a/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java +++ b/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java @@ -1,194 +1,194 @@ -/* - * 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.latest; - -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.version.VersionMatcher; - -public class LatestRevisionStrategy extends ComparatorLatestStrategy { - public static class SpecialMeaning { - private String _name; - - private Integer _value; - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public Integer getValue() { - return _value; - } - - public void setValue(Integer value) { - _value = value; - } - - public void validate() { - if (_name == null) { - throw new IllegalStateException("a special meaning should have a name"); - } - if (_value == null) { - throw new IllegalStateException("a special meaning should have a value"); - } - } - } - - private static final Map DEFAULT_SPECIAL_MEANINGS; - static { - DEFAULT_SPECIAL_MEANINGS = new HashMap(); - DEFAULT_SPECIAL_MEANINGS.put("dev", new Integer(-1)); - DEFAULT_SPECIAL_MEANINGS.put("rc", new Integer(1)); - DEFAULT_SPECIAL_MEANINGS.put("final", new Integer(2)); - } - - /** - * Compares two ModuleRevisionId by their revision. Revisions are compared using an algorithm - * inspired by PHP version_compare one. - */ - public final Comparator STATIC_COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - String rev1 = ((ModuleRevisionId) o1).getRevision(); - String rev2 = ((ModuleRevisionId) o2).getRevision(); - - rev1 = rev1.replaceAll("([a-zA-Z])(\\d)", "$1.$2"); - rev1 = rev1.replaceAll("(\\d)([a-zA-Z])", "$1.$2"); - rev2 = rev2.replaceAll("([a-zA-Z])(\\d)", "$1.$2"); - rev2 = rev2.replaceAll("(\\d)([a-zA-Z])", "$1.$2"); - - String[] parts1 = rev1.split("[\\._\\-\\+]"); - String[] parts2 = rev2.split("[\\._\\-\\+]"); - - int i = 0; - for (; i < parts1.length && i < parts2.length; i++) { - if (parts1[i].equals(parts2[i])) { - continue; - } - boolean is1Number = isNumber(parts1[i]); - boolean is2Number = isNumber(parts2[i]); - if (is1Number && !is2Number) { - return 1; - } - if (is2Number && !is1Number) { - return -1; - } - if (is1Number && is2Number) { - return Long.valueOf(parts1[i]).compareTo(Long.valueOf(parts2[i])); - } - // both are strings, we compare them taking into account special meaning - Map specialMeanings = getSpecialMeanings(); - Integer sm1 = (Integer) specialMeanings.get(parts1[i].toLowerCase()); - Integer sm2 = (Integer) specialMeanings.get(parts2[i].toLowerCase()); - if (sm1 != null) { - sm2 = sm2 == null ? new Integer(0) : sm2; - return sm1.compareTo(sm2); - } - if (sm2 != null) { - return new Integer(0).compareTo(sm2); - } - return parts1[i].compareTo(parts2[i]); - } - if (i < parts1.length) { - return isNumber(parts1[i]) ? 1 : -1; - } - if (i < parts2.length) { - return isNumber(parts2[i]) ? -1 : 1; - } - return 0; - } - - private boolean isNumber(String str) { - return str.matches("\\d+"); - } - }; - - /** - * Compares two ArtifactInfo by their revision. Revisions are compared using an algorithm - * inspired by PHP version_compare one, unless a dynamic revision is given, in which case the - * version matcher is used to perform the comparison. - */ - public Comparator COMPARATOR = new Comparator() { - - public int compare(Object o1, Object o2) { - String rev1 = ((ArtifactInfo) o1).getRevision(); - String rev2 = ((ArtifactInfo) o2).getRevision(); - - /* - * The revisions can still be not resolved, so we use the current version matcher to - * know if one revision is dynamic, and in this case if it should be considered greater - * or lower than the other one. Note that if the version matcher compare method returns - * 0, it's because it's not possible to know which revision is greater. In this case we - * consider the dynamic one to be greater, because most of the time it will then be - * actually resolved and a real comparison will occur. - */ - VersionMatcher vmatcher = IvyContext.getContext().getSettings().getVersionMatcher(); - ModuleRevisionId mrid1 = ModuleRevisionId.newInstance("", "", rev1); - ModuleRevisionId mrid2 = ModuleRevisionId.newInstance("", "", rev2); - if (vmatcher.isDynamic(mrid1)) { - int c = vmatcher.compare(mrid1, mrid2, STATIC_COMPARATOR); - return c >= 0 ? 1 : -1; - } else if (vmatcher.isDynamic(mrid2)) { - int c = vmatcher.compare(mrid2, mrid1, STATIC_COMPARATOR); - return c >= 0 ? -1 : 1; - } - - return STATIC_COMPARATOR.compare(mrid1, mrid2); - } - - }; - - private Map _specialMeanings = null; - - private boolean _usedefaultspecialmeanings = true; - - public LatestRevisionStrategy() { - setComparator(COMPARATOR); - setName("latest-revision"); - } - - public void addConfiguredSpecialMeaning(SpecialMeaning meaning) { - meaning.validate(); - getSpecialMeanings().put(meaning.getName().toLowerCase(), meaning.getValue()); - } - - public synchronized Map getSpecialMeanings() { - if (_specialMeanings == null) { - _specialMeanings = new HashMap(); - if (isUsedefaultspecialmeanings()) { - _specialMeanings.putAll(DEFAULT_SPECIAL_MEANINGS); - } - } - return _specialMeanings; - } - - public boolean isUsedefaultspecialmeanings() { - return _usedefaultspecialmeanings; - } - - public void setUsedefaultspecialmeanings(boolean usedefaultspecialmeanings) { - _usedefaultspecialmeanings = usedefaultspecialmeanings; - } -} +/* + * 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.latest; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.version.VersionMatcher; + +public class LatestRevisionStrategy extends ComparatorLatestStrategy { + public static class SpecialMeaning { + private String _name; + + private Integer _value; + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public Integer getValue() { + return _value; + } + + public void setValue(Integer value) { + _value = value; + } + + public void validate() { + if (_name == null) { + throw new IllegalStateException("a special meaning should have a name"); + } + if (_value == null) { + throw new IllegalStateException("a special meaning should have a value"); + } + } + } + + private static final Map DEFAULT_SPECIAL_MEANINGS; + static { + DEFAULT_SPECIAL_MEANINGS = new HashMap(); + DEFAULT_SPECIAL_MEANINGS.put("dev", new Integer(-1)); + DEFAULT_SPECIAL_MEANINGS.put("rc", new Integer(1)); + DEFAULT_SPECIAL_MEANINGS.put("final", new Integer(2)); + } + + /** + * Compares two ModuleRevisionId by their revision. Revisions are compared using an algorithm + * inspired by PHP version_compare one. + */ + public final Comparator STATIC_COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + String rev1 = ((ModuleRevisionId) o1).getRevision(); + String rev2 = ((ModuleRevisionId) o2).getRevision(); + + rev1 = rev1.replaceAll("([a-zA-Z])(\\d)", "$1.$2"); + rev1 = rev1.replaceAll("(\\d)([a-zA-Z])", "$1.$2"); + rev2 = rev2.replaceAll("([a-zA-Z])(\\d)", "$1.$2"); + rev2 = rev2.replaceAll("(\\d)([a-zA-Z])", "$1.$2"); + + String[] parts1 = rev1.split("[\\._\\-\\+]"); + String[] parts2 = rev2.split("[\\._\\-\\+]"); + + int i = 0; + for (; i < parts1.length && i < parts2.length; i++) { + if (parts1[i].equals(parts2[i])) { + continue; + } + boolean is1Number = isNumber(parts1[i]); + boolean is2Number = isNumber(parts2[i]); + if (is1Number && !is2Number) { + return 1; + } + if (is2Number && !is1Number) { + return -1; + } + if (is1Number && is2Number) { + return Long.valueOf(parts1[i]).compareTo(Long.valueOf(parts2[i])); + } + // both are strings, we compare them taking into account special meaning + Map specialMeanings = getSpecialMeanings(); + Integer sm1 = (Integer) specialMeanings.get(parts1[i].toLowerCase()); + Integer sm2 = (Integer) specialMeanings.get(parts2[i].toLowerCase()); + if (sm1 != null) { + sm2 = sm2 == null ? new Integer(0) : sm2; + return sm1.compareTo(sm2); + } + if (sm2 != null) { + return new Integer(0).compareTo(sm2); + } + return parts1[i].compareTo(parts2[i]); + } + if (i < parts1.length) { + return isNumber(parts1[i]) ? 1 : -1; + } + if (i < parts2.length) { + return isNumber(parts2[i]) ? -1 : 1; + } + return 0; + } + + private boolean isNumber(String str) { + return str.matches("\\d+"); + } + }; + + /** + * Compares two ArtifactInfo by their revision. Revisions are compared using an algorithm + * inspired by PHP version_compare one, unless a dynamic revision is given, in which case the + * version matcher is used to perform the comparison. + */ + public Comparator COMPARATOR = new Comparator() { + + public int compare(Object o1, Object o2) { + String rev1 = ((ArtifactInfo) o1).getRevision(); + String rev2 = ((ArtifactInfo) o2).getRevision(); + + /* + * The revisions can still be not resolved, so we use the current version matcher to + * know if one revision is dynamic, and in this case if it should be considered greater + * or lower than the other one. Note that if the version matcher compare method returns + * 0, it's because it's not possible to know which revision is greater. In this case we + * consider the dynamic one to be greater, because most of the time it will then be + * actually resolved and a real comparison will occur. + */ + VersionMatcher vmatcher = IvyContext.getContext().getSettings().getVersionMatcher(); + ModuleRevisionId mrid1 = ModuleRevisionId.newInstance("", "", rev1); + ModuleRevisionId mrid2 = ModuleRevisionId.newInstance("", "", rev2); + if (vmatcher.isDynamic(mrid1)) { + int c = vmatcher.compare(mrid1, mrid2, STATIC_COMPARATOR); + return c >= 0 ? 1 : -1; + } else if (vmatcher.isDynamic(mrid2)) { + int c = vmatcher.compare(mrid2, mrid1, STATIC_COMPARATOR); + return c >= 0 ? -1 : 1; + } + + return STATIC_COMPARATOR.compare(mrid1, mrid2); + } + + }; + + private Map _specialMeanings = null; + + private boolean _usedefaultspecialmeanings = true; + + public LatestRevisionStrategy() { + setComparator(COMPARATOR); + setName("latest-revision"); + } + + public void addConfiguredSpecialMeaning(SpecialMeaning meaning) { + meaning.validate(); + getSpecialMeanings().put(meaning.getName().toLowerCase(), meaning.getValue()); + } + + public synchronized Map getSpecialMeanings() { + if (_specialMeanings == null) { + _specialMeanings = new HashMap(); + if (isUsedefaultspecialmeanings()) { + _specialMeanings.putAll(DEFAULT_SPECIAL_MEANINGS); + } + } + return _specialMeanings; + } + + public boolean isUsedefaultspecialmeanings() { + return _usedefaultspecialmeanings; + } + + public void setUsedefaultspecialmeanings(boolean usedefaultspecialmeanings) { + _usedefaultspecialmeanings = usedefaultspecialmeanings; + } +} diff --git a/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java b/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java index f06ef9c7..3666d6a6 100644 --- a/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java +++ b/src/java/org/apache/ivy/plugins/latest/LatestStrategy.java @@ -1,45 +1,45 @@ -/* - * 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.latest; - -import java.util.Date; -import java.util.List; - -public interface LatestStrategy { - /** - * Finds the latest artifact among the given artifacts info. The definition of 'latest' depends - * on the strategy itself. Given artifacts info are all good candidate. If the given date is not - * null, then found artifact should not be later than this date. - * - * @param infos - * @param date - * @return the latest artifact among the given ones. - */ - ArtifactInfo findLatest(ArtifactInfo[] infos, Date date); - - /** - * Sorts the given artifacts info from the oldest one to the latest one. The definition of - * 'latest' depends on the strategy itself. Given artifacts info are all good candidate. - * - * @param infos - * @return - */ - List sort(ArtifactInfo[] infos); - - String getName(); -} +/* + * 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.latest; + +import java.util.Date; +import java.util.List; + +public interface LatestStrategy { + /** + * Finds the latest artifact among the given artifacts info. The definition of 'latest' depends + * on the strategy itself. Given artifacts info are all good candidate. If the given date is not + * null, then found artifact should not be later than this date. + * + * @param infos + * @param date + * @return the latest artifact among the given ones. + */ + ArtifactInfo findLatest(ArtifactInfo[] infos, Date date); + + /** + * Sorts the given artifacts info from the oldest one to the latest one. The definition of + * 'latest' depends on the strategy itself. Given artifacts info are all good candidate. + * + * @param infos + * @return + */ + List sort(ArtifactInfo[] infos); + + String getName(); +} diff --git a/src/java/org/apache/ivy/plugins/latest/LatestTimeStrategy.java b/src/java/org/apache/ivy/plugins/latest/LatestTimeStrategy.java index 4d652011..d431790a 100644 --- a/src/java/org/apache/ivy/plugins/latest/LatestTimeStrategy.java +++ b/src/java/org/apache/ivy/plugins/latest/LatestTimeStrategy.java @@ -1,36 +1,36 @@ -/* - * 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.latest; - -import java.util.Comparator; - -public class LatestTimeStrategy extends ComparatorLatestStrategy { - private static Comparator COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - long d1 = ((ArtifactInfo) o1).getLastModified(); - long d2 = ((ArtifactInfo) o2).getLastModified(); - return new Long(d1).compareTo(new Long(d2)); - } - - }; - - public LatestTimeStrategy() { - super(COMPARATOR); - setName("latest-time"); - } -} +/* + * 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.latest; + +import java.util.Comparator; + +public class LatestTimeStrategy extends ComparatorLatestStrategy { + private static Comparator COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + long d1 = ((ArtifactInfo) o1).getLastModified(); + long d2 = ((ArtifactInfo) o2).getLastModified(); + return new Long(d1).compareTo(new Long(d2)); + } + + }; + + public LatestTimeStrategy() { + super(COMPARATOR); + setName("latest-time"); + } +} diff --git a/src/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcher.java b/src/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcher.java index efb8f515..cf90573b 100644 --- a/src/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcher.java @@ -1,63 +1,63 @@ -/* - * 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.matcher; - -/** - * An abstract implementation of the pattern matcher providing base template methods - */ -public abstract class AbstractPatternMatcher implements PatternMatcher { - private final String name; - - /** - * Create a new instance of a pattern matcher - * - * @param name - * the name of the pattern matcher. Never null. - */ - public AbstractPatternMatcher(/* @NotNull */String name) { - this.name = name; - } - - public/* @NotNull */Matcher getMatcher(/* @NotNull */String expression) { - if (expression == null) { - throw new NullPointerException(); - } - if (ANY_EXPRESSION.equals(expression)) { - return AnyMatcher.INSTANCE; - } - return newMatcher(expression); - } - - public/* @NotNull */String getName() { - return name; - } - - /** - * Returns an instance of the implementation specific matcher. - * - * @param expression - * the string to be matched. - * @return the instance of the related matcher. Never null. - */ - protected abstract/* @NotNull */Matcher newMatcher(/* @NotNull */String expression); - - public String toString() { - return getName(); - } -} +/* + * 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.matcher; + +/** + * An abstract implementation of the pattern matcher providing base template methods + */ +public abstract class AbstractPatternMatcher implements PatternMatcher { + private final String name; + + /** + * Create a new instance of a pattern matcher + * + * @param name + * the name of the pattern matcher. Never null. + */ + public AbstractPatternMatcher(/* @NotNull */String name) { + this.name = name; + } + + public/* @NotNull */Matcher getMatcher(/* @NotNull */String expression) { + if (expression == null) { + throw new NullPointerException(); + } + if (ANY_EXPRESSION.equals(expression)) { + return AnyMatcher.INSTANCE; + } + return newMatcher(expression); + } + + public/* @NotNull */String getName() { + return name; + } + + /** + * Returns an instance of the implementation specific matcher. + * + * @param expression + * the string to be matched. + * @return the instance of the related matcher. Never null. + */ + protected abstract/* @NotNull */Matcher newMatcher(/* @NotNull */String expression); + + public String toString() { + return getName(); + } +} diff --git a/src/java/org/apache/ivy/plugins/matcher/AnyMatcher.java b/src/java/org/apache/ivy/plugins/matcher/AnyMatcher.java index c3e16d31..c49454e1 100644 --- a/src/java/org/apache/ivy/plugins/matcher/AnyMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/AnyMatcher.java @@ -1,40 +1,40 @@ -/* - * 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.matcher; - -/** - * A matcher that will match everything. - */ -public/* @Immutable */class AnyMatcher implements Matcher { - public final static Matcher INSTANCE = new AnyMatcher(); - - public AnyMatcher() { - } - - public boolean matches(String input) { - if (input == null) { - throw new NullPointerException(); - } - return true; - } - - public boolean isExact() { - return false; - } - -} +/* + * 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.matcher; + +/** + * A matcher that will match everything. + */ +public/* @Immutable */class AnyMatcher implements Matcher { + public final static Matcher INSTANCE = new AnyMatcher(); + + public AnyMatcher() { + } + + public boolean matches(String input) { + if (input == null) { + throw new NullPointerException(); + } + return true; + } + + public boolean isExact() { + return false; + } + +} diff --git a/src/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcher.java b/src/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcher.java index 6a38fd4d..35e67001 100644 --- a/src/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcher.java @@ -1,62 +1,62 @@ -/* - * 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.matcher; - -/** - * A pattern matcher that tries to match exactly the input with the expression, or match it as a - * pattern.

      The evaluation for matching is perform first by checking if expression and input - * are equals (via equals method) else it attempts to do it by trying to match the input using the - * expression as a regexp. - * - * @see ExactPatternMatcher - * @see RegexpPatternMatcher - */ -public/* @Immutable */final class ExactOrRegexpPatternMatcher extends AbstractPatternMatcher { - - public static final ExactOrRegexpPatternMatcher INSTANCE = new ExactOrRegexpPatternMatcher(); - - public ExactOrRegexpPatternMatcher() { - super(EXACT_OR_REGEXP); - } - - protected Matcher newMatcher(String expression) { - return new ExactOrRegexpMatcher(expression); - } - - private static final class ExactOrRegexpMatcher implements Matcher { - private Matcher _exact; - - private Matcher _regexp; - - public ExactOrRegexpMatcher(String expression) { - _exact = ExactPatternMatcher.INSTANCE.getMatcher(expression); - _regexp = RegexpPatternMatcher.INSTANCE.getMatcher(expression); - } - - public boolean matches(String input) { - if (input == null) { - throw new NullPointerException(); - } - return _exact.matches(input) || _regexp.matches(input); - } - - public boolean isExact() { - return false; - } - } -} +/* + * 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.matcher; + +/** + * A pattern matcher that tries to match exactly the input with the expression, or match it as a + * pattern.

      The evaluation for matching is perform first by checking if expression and input + * are equals (via equals method) else it attempts to do it by trying to match the input using the + * expression as a regexp. + * + * @see ExactPatternMatcher + * @see RegexpPatternMatcher + */ +public/* @Immutable */final class ExactOrRegexpPatternMatcher extends AbstractPatternMatcher { + + public static final ExactOrRegexpPatternMatcher INSTANCE = new ExactOrRegexpPatternMatcher(); + + public ExactOrRegexpPatternMatcher() { + super(EXACT_OR_REGEXP); + } + + protected Matcher newMatcher(String expression) { + return new ExactOrRegexpMatcher(expression); + } + + private static final class ExactOrRegexpMatcher implements Matcher { + private Matcher _exact; + + private Matcher _regexp; + + public ExactOrRegexpMatcher(String expression) { + _exact = ExactPatternMatcher.INSTANCE.getMatcher(expression); + _regexp = RegexpPatternMatcher.INSTANCE.getMatcher(expression); + } + + public boolean matches(String input) { + if (input == null) { + throw new NullPointerException(); + } + return _exact.matches(input) || _regexp.matches(input); + } + + public boolean isExact() { + return false; + } + } +} diff --git a/src/java/org/apache/ivy/plugins/matcher/ExactPatternMatcher.java b/src/java/org/apache/ivy/plugins/matcher/ExactPatternMatcher.java index 8dd606fb..dcb47335 100644 --- a/src/java/org/apache/ivy/plugins/matcher/ExactPatternMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/ExactPatternMatcher.java @@ -1,55 +1,55 @@ -/* - * 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.matcher; - -/** - * Implementation of an exact matcher.

      The matching will be performed against an expression - * being a string. It will only matches if both strings are equal (per equals()) rule or if both - * strings are null. - */ -public/* @Immutable */final class ExactPatternMatcher extends AbstractPatternMatcher { - - public static final ExactPatternMatcher INSTANCE = new ExactPatternMatcher(); - - public ExactPatternMatcher() { - super(EXACT); - } - - protected Matcher newMatcher(String expression) { - return new ExactMatcher(expression); - } - - private static/* @Immutable */class ExactMatcher implements Matcher { - protected String _expression; - - public ExactMatcher(String expression) { - _expression = expression; - } - - public boolean matches(String input) { - if (input == null) { - throw new NullPointerException(); - } - return input.equals(_expression); - } - - public boolean isExact() { - return true; - } - } -} +/* + * 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.matcher; + +/** + * Implementation of an exact matcher.

      The matching will be performed against an expression + * being a string. It will only matches if both strings are equal (per equals()) rule or if both + * strings are null. + */ +public/* @Immutable */final class ExactPatternMatcher extends AbstractPatternMatcher { + + public static final ExactPatternMatcher INSTANCE = new ExactPatternMatcher(); + + public ExactPatternMatcher() { + super(EXACT); + } + + protected Matcher newMatcher(String expression) { + return new ExactMatcher(expression); + } + + private static/* @Immutable */class ExactMatcher implements Matcher { + protected String _expression; + + public ExactMatcher(String expression) { + _expression = expression; + } + + public boolean matches(String input) { + if (input == null) { + throw new NullPointerException(); + } + return input.equals(_expression); + } + + public boolean isExact() { + return true; + } + } +} diff --git a/src/java/org/apache/ivy/plugins/matcher/GlobPatternMatcher.java b/src/java/org/apache/ivy/plugins/matcher/GlobPatternMatcher.java index bbf1f25f..1dfffcaa 100644 --- a/src/java/org/apache/ivy/plugins/matcher/GlobPatternMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/GlobPatternMatcher.java @@ -1,80 +1,80 @@ -/* - * 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.matcher; - -import java.util.regex.PatternSyntaxException; - -import org.apache.oro.text.GlobCompiler; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.Perl5Matcher; - -/** - * A pattern matcher matching input using unix-like glob matcher expressions. Meta characters are: - *

        - *
      • * - Matches zero or more characters
      • - *
      • ? - Matches exactly one character.
      • - *
      - *

      Note that this matcher is available only with in your classpath. - * - * @see GlobCompiler - */ -public/* @Immutable */final class GlobPatternMatcher extends AbstractPatternMatcher { - - public static final GlobPatternMatcher INSTANCE = new GlobPatternMatcher(); - - /* - * NOTE: GlobCompiler does ~100K compilation/s - If necessary look into using ThreadLocal for - * GlobCompiler/Perl5Matcher to cut on useless object creation - If expression are reused over - * and over a LRU cache could make sense - */ - - public GlobPatternMatcher() { - super(GLOB); - } - - protected Matcher newMatcher(String expression) { - return new GlobMatcher(expression); - } - - private static class GlobMatcher implements Matcher { - private Pattern _pattern; - - public GlobMatcher(String expression) throws PatternSyntaxException { - try { - _pattern = new GlobCompiler().compile(expression); - } catch (MalformedPatternException e) { - throw new PatternSyntaxException(e.getMessage(), expression, 0); - } - } - - public boolean matches(String input) { - if (input == null) { - throw new NullPointerException(); - } - return new Perl5Matcher().matches(input, _pattern); - } - - public boolean isExact() { - return false; - } - } - -} +/* + * 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.matcher; + +import java.util.regex.PatternSyntaxException; + +import org.apache.oro.text.GlobCompiler; +import org.apache.oro.text.regex.MalformedPatternException; +import org.apache.oro.text.regex.Pattern; +import org.apache.oro.text.regex.Perl5Matcher; + +/** + * A pattern matcher matching input using unix-like glob matcher expressions. Meta characters are: + *

        + *
      • * - Matches zero or more characters
      • + *
      • ? - Matches exactly one character.
      • + *
      + *

      Note that this matcher is available only with in your classpath. + * + * @see GlobCompiler + */ +public/* @Immutable */final class GlobPatternMatcher extends AbstractPatternMatcher { + + public static final GlobPatternMatcher INSTANCE = new GlobPatternMatcher(); + + /* + * NOTE: GlobCompiler does ~100K compilation/s - If necessary look into using ThreadLocal for + * GlobCompiler/Perl5Matcher to cut on useless object creation - If expression are reused over + * and over a LRU cache could make sense + */ + + public GlobPatternMatcher() { + super(GLOB); + } + + protected Matcher newMatcher(String expression) { + return new GlobMatcher(expression); + } + + private static class GlobMatcher implements Matcher { + private Pattern _pattern; + + public GlobMatcher(String expression) throws PatternSyntaxException { + try { + _pattern = new GlobCompiler().compile(expression); + } catch (MalformedPatternException e) { + throw new PatternSyntaxException(e.getMessage(), expression, 0); + } + } + + public boolean matches(String input) { + if (input == null) { + throw new NullPointerException(); + } + return new Perl5Matcher().matches(input, _pattern); + } + + public boolean isExact() { + return false; + } + } + +} diff --git a/src/java/org/apache/ivy/plugins/matcher/Matcher.java b/src/java/org/apache/ivy/plugins/matcher/Matcher.java index cd86123a..0a2cf770 100644 --- a/src/java/org/apache/ivy/plugins/matcher/Matcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/Matcher.java @@ -1,44 +1,44 @@ -/* - * 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.matcher; - -/** - * An interface that defines a string matcher. - */ -public interface Matcher { - - /** - * Check whether a given string is matched by this matcher. - * - * @param input - * the string to be matched. Cannot be null. - * @return true if the input string is matched, false otherwise. - */ - public boolean matches(/* @NotNull */String input); - - /** - * Return if the matcher will match *only* if the expression equals the input. WARN: This is - * used only as a performance trick, to avoid scanning for things when you already know exactly - * what you want. In the install task where it used it avoid scanning the repository to list all - * modules to find that only one matches, and that it has the name requested. - * - * @return true if the matcher only matches when the expression is equals to the input, false - * otherwise. - */ - public boolean isExact(); -} +/* + * 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.matcher; + +/** + * An interface that defines a string matcher. + */ +public interface Matcher { + + /** + * Check whether a given string is matched by this matcher. + * + * @param input + * the string to be matched. Cannot be null. + * @return true if the input string is matched, false otherwise. + */ + public boolean matches(/* @NotNull */String input); + + /** + * Return if the matcher will match *only* if the expression equals the input. WARN: This is + * used only as a performance trick, to avoid scanning for things when you already know exactly + * what you want. In the install task where it used it avoid scanning the repository to list all + * modules to find that only one matches, and that it has the name requested. + * + * @return true if the matcher only matches when the expression is equals to the input, false + * otherwise. + */ + public boolean isExact(); +} diff --git a/src/java/org/apache/ivy/plugins/matcher/MatcherHelper.java b/src/java/org/apache/ivy/plugins/matcher/MatcherHelper.java index 8012cc40..3b875dde 100644 --- a/src/java/org/apache/ivy/plugins/matcher/MatcherHelper.java +++ b/src/java/org/apache/ivy/plugins/matcher/MatcherHelper.java @@ -1,65 +1,65 @@ -/* - * 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.matcher; - -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -/** - * Set of helper methods to match ModuleId, ModuleRevisionId, ArtifactId - */ -public class MatcherHelper { - // TODO this class might be better off as MatcherUtils in util package - - public static boolean matches(PatternMatcher m, String expression, String input) { - return m.getMatcher(expression).matches(input); - } - - public static boolean matches(PatternMatcher m, ModuleId exp, ModuleId mid) { - return matches(m, exp.getOrganisation(), mid.getOrganisation()) - && matches(m, exp.getName(), mid.getName()); - } - - public static boolean matches(PatternMatcher m, ModuleRevisionId exp, ModuleRevisionId mrid) { - return matches(m, exp.getOrganisation(), mrid.getOrganisation()) - && matches(m, exp.getName(), mrid.getName()) - && matches(m, exp.getRevision(), mrid.getRevision()); - } - - public static boolean matches(PatternMatcher m, ArtifactId exp, ArtifactId aid) { - return matches(m, exp.getModuleId(), aid.getModuleId()) - && matches(m, exp.getName(), aid.getName()) - && matches(m, exp.getExt(), aid.getExt()) - && matches(m, exp.getType(), aid.getType()); - } - - public static boolean isExact(PatternMatcher m, ModuleRevisionId exp) { - return isExact(m, exp.getOrganisation()) && isExact(m, exp.getName()) - && isExact(m, exp.getRevision()); - } - - // unused - public static boolean isExact(PatternMatcher m, ModuleId exp) { - return isExact(m, exp.getOrganisation()) && isExact(m, exp.getName()); - } - - public static boolean isExact(PatternMatcher m, String exp) { - return m.getMatcher(exp).isExact(); - } -} +/* + * 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.matcher; + +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +/** + * Set of helper methods to match ModuleId, ModuleRevisionId, ArtifactId + */ +public class MatcherHelper { + // TODO this class might be better off as MatcherUtils in util package + + public static boolean matches(PatternMatcher m, String expression, String input) { + return m.getMatcher(expression).matches(input); + } + + public static boolean matches(PatternMatcher m, ModuleId exp, ModuleId mid) { + return matches(m, exp.getOrganisation(), mid.getOrganisation()) + && matches(m, exp.getName(), mid.getName()); + } + + public static boolean matches(PatternMatcher m, ModuleRevisionId exp, ModuleRevisionId mrid) { + return matches(m, exp.getOrganisation(), mrid.getOrganisation()) + && matches(m, exp.getName(), mrid.getName()) + && matches(m, exp.getRevision(), mrid.getRevision()); + } + + public static boolean matches(PatternMatcher m, ArtifactId exp, ArtifactId aid) { + return matches(m, exp.getModuleId(), aid.getModuleId()) + && matches(m, exp.getName(), aid.getName()) + && matches(m, exp.getExt(), aid.getExt()) + && matches(m, exp.getType(), aid.getType()); + } + + public static boolean isExact(PatternMatcher m, ModuleRevisionId exp) { + return isExact(m, exp.getOrganisation()) && isExact(m, exp.getName()) + && isExact(m, exp.getRevision()); + } + + // unused + public static boolean isExact(PatternMatcher m, ModuleId exp) { + return isExact(m, exp.getOrganisation()) && isExact(m, exp.getName()); + } + + public static boolean isExact(PatternMatcher m, String exp) { + return m.getMatcher(exp).isExact(); + } +} diff --git a/src/java/org/apache/ivy/plugins/matcher/ModuleIdMatcher.java b/src/java/org/apache/ivy/plugins/matcher/ModuleIdMatcher.java index f2be6421..ea83d6dc 100644 --- a/src/java/org/apache/ivy/plugins/matcher/ModuleIdMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/ModuleIdMatcher.java @@ -1,47 +1,47 @@ -/* - * 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.matcher; - -import org.apache.ivy.core.module.id.ModuleId; - -public class ModuleIdMatcher { - // TODO this class should be moved out of this package - private Matcher _orgMatcher; - - private Matcher _moduleMatcher; - - private ModuleId _mid; - - private PatternMatcher _pm; - - public ModuleIdMatcher(ModuleId mid, PatternMatcher pm) { - _mid = mid; - _pm = pm; - _orgMatcher = pm.getMatcher(mid.getOrganisation() == null ? PatternMatcher.ANY_EXPRESSION - : mid.getOrganisation()); - _moduleMatcher = pm.getMatcher(mid.getName()); - } - - public boolean matches(ModuleId mid) { - return _orgMatcher.matches(mid.getOrganisation()) && _moduleMatcher.matches(mid.getName()); - } - - public String toString() { - return _mid + " (" + _pm.getName() + ")"; - } -} +/* + * 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.matcher; + +import org.apache.ivy.core.module.id.ModuleId; + +public class ModuleIdMatcher { + // TODO this class should be moved out of this package + private Matcher _orgMatcher; + + private Matcher _moduleMatcher; + + private ModuleId _mid; + + private PatternMatcher _pm; + + public ModuleIdMatcher(ModuleId mid, PatternMatcher pm) { + _mid = mid; + _pm = pm; + _orgMatcher = pm.getMatcher(mid.getOrganisation() == null ? PatternMatcher.ANY_EXPRESSION + : mid.getOrganisation()); + _moduleMatcher = pm.getMatcher(mid.getName()); + } + + public boolean matches(ModuleId mid) { + return _orgMatcher.matches(mid.getOrganisation()) && _moduleMatcher.matches(mid.getName()); + } + + public String toString() { + return _mid + " (" + _pm.getName() + ")"; + } +} diff --git a/src/java/org/apache/ivy/plugins/matcher/NoMatcher.java b/src/java/org/apache/ivy/plugins/matcher/NoMatcher.java index 2f0c308a..54c10f04 100644 --- a/src/java/org/apache/ivy/plugins/matcher/NoMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/NoMatcher.java @@ -1,41 +1,41 @@ -/* - * 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.matcher; - -/** - * A matcher that matches nothing. - */ -public final/* @Immutable */class NoMatcher implements Matcher { - - public final static Matcher INSTANCE = new NoMatcher(); - - public NoMatcher() { - } - - public boolean matches(String input) { - if (input == null) { - throw new NullPointerException(); - } - return false; - } - - public boolean isExact() { - return true; - } - -} +/* + * 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.matcher; + +/** + * A matcher that matches nothing. + */ +public final/* @Immutable */class NoMatcher implements Matcher { + + public final static Matcher INSTANCE = new NoMatcher(); + + public NoMatcher() { + } + + public boolean matches(String input) { + if (input == null) { + throw new NullPointerException(); + } + return false; + } + + public boolean isExact() { + return true; + } + +} diff --git a/src/java/org/apache/ivy/plugins/matcher/PatternMatcher.java b/src/java/org/apache/ivy/plugins/matcher/PatternMatcher.java index 780ec4ed..4b8fe337 100644 --- a/src/java/org/apache/ivy/plugins/matcher/PatternMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/PatternMatcher.java @@ -1,71 +1,71 @@ -/* - * 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.matcher; - -/** - * Interface for a pattern matcher.

      The pattern matcher is the main abstraction regarding the - * matching of an expression. Implementation may vary depending on the expression syntax handling - * that is desired. - */ -public interface PatternMatcher { - - /** - * 'exact' pattern matcher name - */ - public static final String EXACT = "exact"; - - /** - * pattern matcher name 'regexp' - */ - public static final String REGEXP = "regexp"; - - /** - * pattern matcher 'glob' - */ - public static final String GLOB = "glob"; - - /** - * pattern matcher name 'exactOrRegexp' - */ - public static final String EXACT_OR_REGEXP = "exactOrRegexp"; - - /** - * Any expression string: '*' - */ - public static final String ANY_EXPRESSION = "*"; - - /** - * Return the matcher for the given expression. - * - * @param expression - * the expression to be matched. Cannot be null ? - * @return the matcher instance for the given expression. Never null. - */ - public/* @NotNull */Matcher getMatcher(/* @NotNull */String expression); - - /** - * return the name of this pattern matcher - * - * @return the name of this pattern matcher. Never null. - * @see #EXACT - * @see #REGEXP - * @see #GLOB - * @see #EXACT_OR_REGEXP - */ - public/* @NotNull */String getName(); -} +/* + * 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.matcher; + +/** + * Interface for a pattern matcher.

      The pattern matcher is the main abstraction regarding the + * matching of an expression. Implementation may vary depending on the expression syntax handling + * that is desired. + */ +public interface PatternMatcher { + + /** + * 'exact' pattern matcher name + */ + public static final String EXACT = "exact"; + + /** + * pattern matcher name 'regexp' + */ + public static final String REGEXP = "regexp"; + + /** + * pattern matcher 'glob' + */ + public static final String GLOB = "glob"; + + /** + * pattern matcher name 'exactOrRegexp' + */ + public static final String EXACT_OR_REGEXP = "exactOrRegexp"; + + /** + * Any expression string: '*' + */ + public static final String ANY_EXPRESSION = "*"; + + /** + * Return the matcher for the given expression. + * + * @param expression + * the expression to be matched. Cannot be null ? + * @return the matcher instance for the given expression. Never null. + */ + public/* @NotNull */Matcher getMatcher(/* @NotNull */String expression); + + /** + * return the name of this pattern matcher + * + * @return the name of this pattern matcher. Never null. + * @see #EXACT + * @see #REGEXP + * @see #GLOB + * @see #EXACT_OR_REGEXP + */ + public/* @NotNull */String getName(); +} diff --git a/src/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcher.java b/src/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcher.java index ca69dc48..77129a6c 100644 --- a/src/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcher.java @@ -1,66 +1,66 @@ -/* - * 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.matcher; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -/** - * A pattern matcher matching input using regular expressions. - * - * @see Pattern - */ -public final/* @Immutable */class RegexpPatternMatcher extends AbstractPatternMatcher { - public static final RegexpPatternMatcher INSTANCE = new RegexpPatternMatcher(); - - /* - * NOTE: Regexp compiler does ~200K compilation/s - If necessary look into using ThreadLocal - * Pattern to cut on useless object creation - If expression are reused over and over a LRU - * cache could make sense - */ - - public RegexpPatternMatcher() { - super(REGEXP); - } - - protected Matcher newMatcher(String expression) { - return new RegexpMatcher(expression); - } - - private static/* @Immutable */class RegexpMatcher implements Matcher { - private Pattern _pattern; - - public RegexpMatcher(String expression) throws PatternSyntaxException { - if (expression == null) { - throw new NullPointerException(); - } - _pattern = Pattern.compile(expression); - } - - public boolean matches(String input) { - if (input == null) { - throw new NullPointerException(); - } - return _pattern.matcher(input).matches(); - } - - public boolean isExact() { - return false; - } - } -} +/* + * 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.matcher; + +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +/** + * A pattern matcher matching input using regular expressions. + * + * @see Pattern + */ +public final/* @Immutable */class RegexpPatternMatcher extends AbstractPatternMatcher { + public static final RegexpPatternMatcher INSTANCE = new RegexpPatternMatcher(); + + /* + * NOTE: Regexp compiler does ~200K compilation/s - If necessary look into using ThreadLocal + * Pattern to cut on useless object creation - If expression are reused over and over a LRU + * cache could make sense + */ + + public RegexpPatternMatcher() { + super(REGEXP); + } + + protected Matcher newMatcher(String expression) { + return new RegexpMatcher(expression); + } + + private static/* @Immutable */class RegexpMatcher implements Matcher { + private Pattern _pattern; + + public RegexpMatcher(String expression) throws PatternSyntaxException { + if (expression == null) { + throw new NullPointerException(); + } + _pattern = Pattern.compile(expression); + } + + public boolean matches(String input) { + if (input == null) { + throw new NullPointerException(); + } + return _pattern.matcher(input).matches(); + } + + public boolean isExact() { + return false; + } + } +} diff --git a/src/java/org/apache/ivy/plugins/namespace/MRIDRule.java b/src/java/org/apache/ivy/plugins/namespace/MRIDRule.java index c263c128..09850c35 100644 --- a/src/java/org/apache/ivy/plugins/namespace/MRIDRule.java +++ b/src/java/org/apache/ivy/plugins/namespace/MRIDRule.java @@ -1,74 +1,74 @@ -/* - * 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.namespace; - -public class MRIDRule { - private String _org; - - private String _module; - - private String _branch; - - private String _rev; - - public MRIDRule(String org, String mod, String rev) { - _org = org; - _module = mod; - _rev = rev; - } - - public MRIDRule() { - } - - public String getModule() { - return _module; - } - - public void setModule(String module) { - _module = module; - } - - public String getOrg() { - return _org; - } - - public void setOrg(String org) { - _org = org; - } - - public String getRev() { - return _rev; - } - - public void setRev(String rev) { - _rev = rev; - } - - public String toString() { - return "[ " + _org + " " + _module + (_branch != null ? " " + _branch : "") + " " + _rev - + " ]"; - } - - public String getBranch() { - return _branch; - } - - public void setBranch(String branch) { - _branch = branch; - } -} +/* + * 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.namespace; + +public class MRIDRule { + private String _org; + + private String _module; + + private String _branch; + + private String _rev; + + public MRIDRule(String org, String mod, String rev) { + _org = org; + _module = mod; + _rev = rev; + } + + public MRIDRule() { + } + + public String getModule() { + return _module; + } + + public void setModule(String module) { + _module = module; + } + + public String getOrg() { + return _org; + } + + public void setOrg(String org) { + _org = org; + } + + public String getRev() { + return _rev; + } + + public void setRev(String rev) { + _rev = rev; + } + + public String toString() { + return "[ " + _org + " " + _module + (_branch != null ? " " + _branch : "") + " " + _rev + + " ]"; + } + + public String getBranch() { + return _branch; + } + + public void setBranch(String branch) { + _branch = branch; + } +} diff --git a/src/java/org/apache/ivy/plugins/namespace/MRIDTransformationRule.java b/src/java/org/apache/ivy/plugins/namespace/MRIDTransformationRule.java index 22d5d243..5b5890a9 100644 --- a/src/java/org/apache/ivy/plugins/namespace/MRIDTransformationRule.java +++ b/src/java/org/apache/ivy/plugins/namespace/MRIDTransformationRule.java @@ -1,145 +1,145 @@ -/* - * 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.namespace; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.util.Message; - -public class MRIDTransformationRule implements NamespaceTransformer { - private static class MridRuleMatcher { - private static final String[] TYPES = new String[] {"o", "m", "b", "r"}; - - private Matcher[] _matchers = new Matcher[4]; - - public boolean match(MRIDRule src, ModuleRevisionId mrid) { - _matchers[0] = Pattern.compile(getPattern(src.getOrg())) - .matcher(mrid.getOrganisation()); - if (!_matchers[0].matches()) { - return false; - } - _matchers[1] = Pattern.compile(getPattern(src.getModule())).matcher(mrid.getName()); - if (!_matchers[1].matches()) { - return false; - } - if (mrid.getBranch() == null) { - _matchers[2] = null; - } else { - _matchers[2] = Pattern.compile(getPattern(src.getBranch())).matcher( - mrid.getBranch()); - if (!_matchers[2].matches()) { - return false; - } - } - _matchers[3] = Pattern.compile(getPattern(src.getRev())).matcher(mrid.getRevision()); - if (!_matchers[3].matches()) { - return false; - } - - return true; - } - - public ModuleRevisionId apply(MRIDRule dest, ModuleRevisionId mrid) { - String org = applyRules(dest.getOrg(), "o"); - String mod = applyRules(dest.getModule(), "m"); - String branch = applyRules(dest.getBranch(), "b"); - String rev = applyRules(dest.getRev(), "r"); - - return ModuleRevisionId.newInstance(org, mod, branch, rev, mrid.getExtraAttributes()); - } - - private String applyRules(String str, String type) { - for (int i = 0; i < TYPES.length; i++) { - str = applyTypeRule(str, TYPES[i], type, _matchers[i]); - } - return str; - } - - private String applyTypeRule(String rule, String type, String ruleType, Matcher m) { - if (m == null) { - return rule; - } - String res = rule == null ? "$" + ruleType + "0" : rule; - for (int i = 0; i < TYPES.length; i++) { - if (TYPES[i].equals(type)) { - res = res.replaceAll("([^\\\\])\\$" + type, "$1\\$"); - res = res.replaceAll("^\\$" + type, "\\$"); - } else { - res = res.replaceAll("([^\\\\])\\$" + TYPES[i], "$1\\\\\\$" + TYPES[i]); - res = res.replaceAll("^\\$" + TYPES[i], "\\\\\\$" + TYPES[i]); - } - } - - StringBuffer sb = new StringBuffer(); - m.reset(); - m.find(); - m.appendReplacement(sb, res); - - String str = sb.toString(); - // null rule not replaced, let it be null - if (rule == null && ("$" + ruleType + "0").equals(str)) { - return null; - } - - return str; - } - - private String getPattern(String p) { - return p == null ? ".*" : p; - } - } - - private List _src = new ArrayList(); - - private MRIDRule _dest; - - public void addSrc(MRIDRule src) { - _src.add(src); - } - - public void addDest(MRIDRule dest) { - if (_dest != null) { - throw new IllegalArgumentException("only one dest is allowed per mapping"); - } - _dest = dest; - } - - public ModuleRevisionId transform(ModuleRevisionId mrid) { - MridRuleMatcher matcher = new MridRuleMatcher(); - for (Iterator iter = _src.iterator(); iter.hasNext();) { - MRIDRule rule = (MRIDRule) iter.next(); - if (matcher.match(rule, mrid)) { - ModuleRevisionId destMrid = matcher.apply(_dest, mrid); - Message.debug("found matching namespace rule: " + rule + ". Applied " + _dest - + " on " + mrid + ". Transformed to " + destMrid); - return destMrid; - } - } - return mrid; - } - - public boolean isIdentity() { - return false; - } - -} +/* + * 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.namespace; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.util.Message; + +public class MRIDTransformationRule implements NamespaceTransformer { + private static class MridRuleMatcher { + private static final String[] TYPES = new String[] {"o", "m", "b", "r"}; + + private Matcher[] _matchers = new Matcher[4]; + + public boolean match(MRIDRule src, ModuleRevisionId mrid) { + _matchers[0] = Pattern.compile(getPattern(src.getOrg())) + .matcher(mrid.getOrganisation()); + if (!_matchers[0].matches()) { + return false; + } + _matchers[1] = Pattern.compile(getPattern(src.getModule())).matcher(mrid.getName()); + if (!_matchers[1].matches()) { + return false; + } + if (mrid.getBranch() == null) { + _matchers[2] = null; + } else { + _matchers[2] = Pattern.compile(getPattern(src.getBranch())).matcher( + mrid.getBranch()); + if (!_matchers[2].matches()) { + return false; + } + } + _matchers[3] = Pattern.compile(getPattern(src.getRev())).matcher(mrid.getRevision()); + if (!_matchers[3].matches()) { + return false; + } + + return true; + } + + public ModuleRevisionId apply(MRIDRule dest, ModuleRevisionId mrid) { + String org = applyRules(dest.getOrg(), "o"); + String mod = applyRules(dest.getModule(), "m"); + String branch = applyRules(dest.getBranch(), "b"); + String rev = applyRules(dest.getRev(), "r"); + + return ModuleRevisionId.newInstance(org, mod, branch, rev, mrid.getExtraAttributes()); + } + + private String applyRules(String str, String type) { + for (int i = 0; i < TYPES.length; i++) { + str = applyTypeRule(str, TYPES[i], type, _matchers[i]); + } + return str; + } + + private String applyTypeRule(String rule, String type, String ruleType, Matcher m) { + if (m == null) { + return rule; + } + String res = rule == null ? "$" + ruleType + "0" : rule; + for (int i = 0; i < TYPES.length; i++) { + if (TYPES[i].equals(type)) { + res = res.replaceAll("([^\\\\])\\$" + type, "$1\\$"); + res = res.replaceAll("^\\$" + type, "\\$"); + } else { + res = res.replaceAll("([^\\\\])\\$" + TYPES[i], "$1\\\\\\$" + TYPES[i]); + res = res.replaceAll("^\\$" + TYPES[i], "\\\\\\$" + TYPES[i]); + } + } + + StringBuffer sb = new StringBuffer(); + m.reset(); + m.find(); + m.appendReplacement(sb, res); + + String str = sb.toString(); + // null rule not replaced, let it be null + if (rule == null && ("$" + ruleType + "0").equals(str)) { + return null; + } + + return str; + } + + private String getPattern(String p) { + return p == null ? ".*" : p; + } + } + + private List _src = new ArrayList(); + + private MRIDRule _dest; + + public void addSrc(MRIDRule src) { + _src.add(src); + } + + public void addDest(MRIDRule dest) { + if (_dest != null) { + throw new IllegalArgumentException("only one dest is allowed per mapping"); + } + _dest = dest; + } + + public ModuleRevisionId transform(ModuleRevisionId mrid) { + MridRuleMatcher matcher = new MridRuleMatcher(); + for (Iterator iter = _src.iterator(); iter.hasNext();) { + MRIDRule rule = (MRIDRule) iter.next(); + if (matcher.match(rule, mrid)) { + ModuleRevisionId destMrid = matcher.apply(_dest, mrid); + Message.debug("found matching namespace rule: " + rule + ". Applied " + _dest + + " on " + mrid + ". Transformed to " + destMrid); + return destMrid; + } + } + return mrid; + } + + public boolean isIdentity() { + return false; + } + +} diff --git a/src/java/org/apache/ivy/plugins/namespace/NameSpaceHelper.java b/src/java/org/apache/ivy/plugins/namespace/NameSpaceHelper.java index 68977434..24c7b26c 100644 --- a/src/java/org/apache/ivy/plugins/namespace/NameSpaceHelper.java +++ b/src/java/org/apache/ivy/plugins/namespace/NameSpaceHelper.java @@ -1,93 +1,93 @@ -/* - * 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.namespace; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.DefaultModuleRevision; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; - -public class NameSpaceHelper { - - public static DependencyDescriptor toSystem(DependencyDescriptor dd, Namespace ns) { - return DefaultDependencyDescriptor.transformInstance(dd, ns); - } - - public static DependencyDescriptor transform(DependencyDescriptor dd, NamespaceTransformer t, - boolean fromSystem) { - return DefaultDependencyDescriptor.transformInstance(dd, t, fromSystem); - } - - public static ModuleDescriptor toSystem(ModuleDescriptor md, Namespace ns) { - return DefaultModuleDescriptor.transformInstance(md, ns); - } - - public static ResolvedModuleRevision toSystem(ResolvedModuleRevision rmr, Namespace ns) { - if (ns.getToSystemTransformer().isIdentity()) { - return rmr; - } - ModuleDescriptor md = toSystem(rmr.getDescriptor(), ns); - if (md.equals(rmr.getDescriptor())) { - return rmr; - } - return new DefaultModuleRevision(rmr.getResolver(), rmr.getArtifactResolver(), md, rmr - .isSearched(), rmr.isDownloaded(), rmr.getLocalMDUrl()); - } - - public static Artifact transform(Artifact artifact, NamespaceTransformer t) { - if (t.isIdentity()) { - return artifact; - } - ModuleRevisionId mrid = t.transform(artifact.getModuleRevisionId()); - if (artifact.getModuleRevisionId().equals(mrid)) { - return artifact; - } - return new DefaultArtifact(mrid, artifact.getPublicationDate(), artifact.getName(), - artifact.getType(), artifact.getExt(), artifact.getUrl(), artifact - .getExtraAttributes()); - } - - public static ArtifactId transform(ArtifactId artifactId, NamespaceTransformer t) { - if (t.isIdentity()) { - return artifactId; - } - ModuleId mid = transform(artifactId.getModuleId(), t); - if (mid.equals(artifactId.getModuleId())) { - return artifactId; - } - return new ArtifactId(mid, artifactId.getName(), artifactId.getType(), artifactId.getExt()); - } - - public static ModuleId transform(ModuleId mid, NamespaceTransformer t) { - if (t.isIdentity()) { - return mid; - } - return t.transform(new ModuleRevisionId(mid, "")).getModuleId(); - } - - public static String transformOrganisation(String org, NamespaceTransformer t) { - return transform(new ModuleId(org, ""), t).getOrganisation(); - } -} +/* + * 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.namespace; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.DefaultModuleRevision; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; + +public class NameSpaceHelper { + + public static DependencyDescriptor toSystem(DependencyDescriptor dd, Namespace ns) { + return DefaultDependencyDescriptor.transformInstance(dd, ns); + } + + public static DependencyDescriptor transform(DependencyDescriptor dd, NamespaceTransformer t, + boolean fromSystem) { + return DefaultDependencyDescriptor.transformInstance(dd, t, fromSystem); + } + + public static ModuleDescriptor toSystem(ModuleDescriptor md, Namespace ns) { + return DefaultModuleDescriptor.transformInstance(md, ns); + } + + public static ResolvedModuleRevision toSystem(ResolvedModuleRevision rmr, Namespace ns) { + if (ns.getToSystemTransformer().isIdentity()) { + return rmr; + } + ModuleDescriptor md = toSystem(rmr.getDescriptor(), ns); + if (md.equals(rmr.getDescriptor())) { + return rmr; + } + return new DefaultModuleRevision(rmr.getResolver(), rmr.getArtifactResolver(), md, rmr + .isSearched(), rmr.isDownloaded(), rmr.getLocalMDUrl()); + } + + public static Artifact transform(Artifact artifact, NamespaceTransformer t) { + if (t.isIdentity()) { + return artifact; + } + ModuleRevisionId mrid = t.transform(artifact.getModuleRevisionId()); + if (artifact.getModuleRevisionId().equals(mrid)) { + return artifact; + } + return new DefaultArtifact(mrid, artifact.getPublicationDate(), artifact.getName(), + artifact.getType(), artifact.getExt(), artifact.getUrl(), artifact + .getExtraAttributes()); + } + + public static ArtifactId transform(ArtifactId artifactId, NamespaceTransformer t) { + if (t.isIdentity()) { + return artifactId; + } + ModuleId mid = transform(artifactId.getModuleId(), t); + if (mid.equals(artifactId.getModuleId())) { + return artifactId; + } + return new ArtifactId(mid, artifactId.getName(), artifactId.getType(), artifactId.getExt()); + } + + public static ModuleId transform(ModuleId mid, NamespaceTransformer t) { + if (t.isIdentity()) { + return mid; + } + return t.transform(new ModuleRevisionId(mid, "")).getModuleId(); + } + + public static String transformOrganisation(String org, NamespaceTransformer t) { + return transform(new ModuleId(org, ""), t).getOrganisation(); + } +} diff --git a/src/java/org/apache/ivy/plugins/namespace/Namespace.java b/src/java/org/apache/ivy/plugins/namespace/Namespace.java index b620ce2e..e0b1f0d0 100644 --- a/src/java/org/apache/ivy/plugins/namespace/Namespace.java +++ b/src/java/org/apache/ivy/plugins/namespace/Namespace.java @@ -1,103 +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.plugins.namespace; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class Namespace { - public static final Namespace SYSTEM_NAMESPACE; - static { - SYSTEM_NAMESPACE = new Namespace(); - } - - private List _rules = new ArrayList(); - - private String _name; - - private boolean _chainRules = false; - - private NamespaceTransformer _fromSystemTransformer = new NamespaceTransformer() { - public ModuleRevisionId transform(ModuleRevisionId mrid) { - for (Iterator iter = _rules.iterator(); iter.hasNext();) { - NamespaceRule rule = (NamespaceRule) iter.next(); - ModuleRevisionId nmrid = rule.getFromSystem().transform(mrid); - if (_chainRules) { - mrid = nmrid; - } else if (!nmrid.equals(mrid)) { - return nmrid; - } - } - return mrid; - } - - public boolean isIdentity() { - return _rules.isEmpty(); - } - }; - - private NamespaceTransformer _toSystemTransformer = new NamespaceTransformer() { - public ModuleRevisionId transform(ModuleRevisionId mrid) { - for (Iterator iter = _rules.iterator(); iter.hasNext();) { - NamespaceRule rule = (NamespaceRule) iter.next(); - ModuleRevisionId nmrid = rule.getToSystem().transform(mrid); - if (_chainRules) { - mrid = nmrid; - } else if (!nmrid.equals(mrid)) { - return nmrid; - } - } - return mrid; - } - - public boolean isIdentity() { - return _rules.isEmpty(); - } - }; - - public void addRule(NamespaceRule rule) { - _rules.add(rule); - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public NamespaceTransformer getFromSystemTransformer() { - return _fromSystemTransformer; - } - - public NamespaceTransformer getToSystemTransformer() { - return _toSystemTransformer; - } - - public boolean isChainrules() { - return _chainRules; - } - - public void setChainrules(boolean chainRules) { - _chainRules = chainRules; - } -} +/* + * 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.namespace; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class Namespace { + public static final Namespace SYSTEM_NAMESPACE; + static { + SYSTEM_NAMESPACE = new Namespace(); + } + + private List _rules = new ArrayList(); + + private String _name; + + private boolean _chainRules = false; + + private NamespaceTransformer _fromSystemTransformer = new NamespaceTransformer() { + public ModuleRevisionId transform(ModuleRevisionId mrid) { + for (Iterator iter = _rules.iterator(); iter.hasNext();) { + NamespaceRule rule = (NamespaceRule) iter.next(); + ModuleRevisionId nmrid = rule.getFromSystem().transform(mrid); + if (_chainRules) { + mrid = nmrid; + } else if (!nmrid.equals(mrid)) { + return nmrid; + } + } + return mrid; + } + + public boolean isIdentity() { + return _rules.isEmpty(); + } + }; + + private NamespaceTransformer _toSystemTransformer = new NamespaceTransformer() { + public ModuleRevisionId transform(ModuleRevisionId mrid) { + for (Iterator iter = _rules.iterator(); iter.hasNext();) { + NamespaceRule rule = (NamespaceRule) iter.next(); + ModuleRevisionId nmrid = rule.getToSystem().transform(mrid); + if (_chainRules) { + mrid = nmrid; + } else if (!nmrid.equals(mrid)) { + return nmrid; + } + } + return mrid; + } + + public boolean isIdentity() { + return _rules.isEmpty(); + } + }; + + public void addRule(NamespaceRule rule) { + _rules.add(rule); + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public NamespaceTransformer getFromSystemTransformer() { + return _fromSystemTransformer; + } + + public NamespaceTransformer getToSystemTransformer() { + return _toSystemTransformer; + } + + public boolean isChainrules() { + return _chainRules; + } + + public void setChainrules(boolean chainRules) { + _chainRules = chainRules; + } +} diff --git a/src/java/org/apache/ivy/plugins/namespace/NamespaceRule.java b/src/java/org/apache/ivy/plugins/namespace/NamespaceRule.java index 91d603ae..38f19b94 100644 --- a/src/java/org/apache/ivy/plugins/namespace/NamespaceRule.java +++ b/src/java/org/apache/ivy/plugins/namespace/NamespaceRule.java @@ -1,66 +1,66 @@ -/* - * 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.namespace; - -public class NamespaceRule { - private String _name; - - private String _description; - - private MRIDTransformationRule _fromSystem; - - private MRIDTransformationRule _toSystem; - - public MRIDTransformationRule getFromSystem() { - return _fromSystem; - } - - public void addFromsystem(MRIDTransformationRule fromSystem) { - if (_fromSystem != null) { - throw new IllegalArgumentException("only one fromsystem is allowed per rule"); - } - _fromSystem = fromSystem; - } - - public MRIDTransformationRule getToSystem() { - return _toSystem; - } - - public void addTosystem(MRIDTransformationRule toSystem) { - if (_toSystem != null) { - throw new IllegalArgumentException("only one tosystem is allowed per rule"); - } - _toSystem = toSystem; - } - - public String getDescription() { - return _description; - } - - public void setDescription(String description) { - _description = description; - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } -} +/* + * 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.namespace; + +public class NamespaceRule { + private String _name; + + private String _description; + + private MRIDTransformationRule _fromSystem; + + private MRIDTransformationRule _toSystem; + + public MRIDTransformationRule getFromSystem() { + return _fromSystem; + } + + public void addFromsystem(MRIDTransformationRule fromSystem) { + if (_fromSystem != null) { + throw new IllegalArgumentException("only one fromsystem is allowed per rule"); + } + _fromSystem = fromSystem; + } + + public MRIDTransformationRule getToSystem() { + return _toSystem; + } + + public void addTosystem(MRIDTransformationRule toSystem) { + if (_toSystem != null) { + throw new IllegalArgumentException("only one tosystem is allowed per rule"); + } + _toSystem = toSystem; + } + + public String getDescription() { + return _description; + } + + public void setDescription(String description) { + _description = description; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } +} diff --git a/src/java/org/apache/ivy/plugins/namespace/NamespaceTransformer.java b/src/java/org/apache/ivy/plugins/namespace/NamespaceTransformer.java index 13eb211c..75148b20 100644 --- a/src/java/org/apache/ivy/plugins/namespace/NamespaceTransformer.java +++ b/src/java/org/apache/ivy/plugins/namespace/NamespaceTransformer.java @@ -1,26 +1,26 @@ -/* - * 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.namespace; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public interface NamespaceTransformer { - public ModuleRevisionId transform(ModuleRevisionId mrid); - - public boolean isIdentity(); -} +/* + * 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.namespace; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public interface NamespaceTransformer { + public ModuleRevisionId transform(ModuleRevisionId mrid); + + public boolean isIdentity(); +} diff --git a/src/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParser.java index 5348cb01..ca6d8765 100644 --- a/src/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParser.java +++ b/src/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParser.java @@ -1,361 +1,361 @@ -/* - * 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.parser; - -import java.io.IOException; -import java.net.URL; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.repository.url.URLResource; -import org.apache.ivy.util.Message; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; - -public abstract class AbstractModuleDescriptorParser implements ModuleDescriptorParser { - public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL descriptorURL, - boolean validate) throws ParseException, IOException { - return parseDescriptor(ivySettings, descriptorURL, new URLResource(descriptorURL), validate); - } - - protected abstract static class AbstractParser extends DefaultHandler { - private static final String DEFAULT_CONF_MAPPING = "*->*"; - - private String _defaultConf; // used only as defaultconf, not used for - - // guesssing right side part of a mapping - private String _defaultConfMapping; // same as default conf but is used - - // for guesssing right side part of a mapping - private DefaultDependencyDescriptor _defaultConfMappingDescriptor; - - private Resource _res; - - private List _errors = new ArrayList(); - - protected DefaultModuleDescriptor _md; - - private ModuleDescriptorParser _parser; - - protected AbstractParser(ModuleDescriptorParser parser) { - _parser = parser; - } - - public ModuleDescriptorParser getModuleDescriptorParser() { - return _parser; - } - - protected void checkErrors() throws ParseException { - if (!_errors.isEmpty()) { - throw new ParseException(_errors.toString(), 0); - } - } - - protected void setResource(Resource res) { - _res = res; // used for log and date only - _md = new DefaultModuleDescriptor(_parser, res); - _md.setLastModified(getLastModified()); - } - - protected Resource getResource() { - return _res; - } - - protected String getDefaultConfMapping() { - return _defaultConfMapping; - } - - protected void setDefaultConfMapping(String defaultConf) { - _defaultConfMapping = defaultConf; - } - - protected void parseDepsConfs(String confs, DefaultDependencyDescriptor dd) { - parseDepsConfs(confs, dd, _defaultConfMapping != null); - } - - protected void parseDepsConfs(String confs, DefaultDependencyDescriptor dd, - boolean useDefaultMappingToGuessRightOperande) { - parseDepsConfs(confs, dd, useDefaultMappingToGuessRightOperande, true); - } - - protected void parseDepsConfs(String confs, DefaultDependencyDescriptor dd, - boolean useDefaultMappingToGuessRightOperande, boolean evaluateConditions) { - if (confs == null) { - return; - } - - String[] conf = confs.split(";"); - parseDepsConfs(conf, dd, useDefaultMappingToGuessRightOperande, evaluateConditions); - } - - protected void parseDepsConfs(String[] conf, DefaultDependencyDescriptor dd, - boolean useDefaultMappingToGuessRightOperande) { - parseDepsConfs(conf, dd, useDefaultMappingToGuessRightOperande, true); - } - - protected void parseDepsConfs(String[] conf, DefaultDependencyDescriptor dd, - boolean useDefaultMappingToGuessRightOperande, boolean evaluateConditions) { - replaceConfigurationWildcards(_md); - for (int i = 0; i < conf.length; i++) { - String[] ops = conf[i].split("->"); - if (ops.length == 1) { - String[] modConfs = ops[0].split(","); - if (!useDefaultMappingToGuessRightOperande) { - for (int j = 0; j < modConfs.length; j++) { - dd.addDependencyConfiguration(modConfs[j].trim(), modConfs[j].trim()); - } - } else { - for (int j = 0; j < modConfs.length; j++) { - String[] depConfs = getDefaultConfMappingDescriptor() - .getDependencyConfigurations(modConfs[j]); - if (depConfs.length > 0) { - for (int k = 0; k < depConfs.length; k++) { - String mappedDependency = evaluateConditions ? evaluateCondition( - depConfs[k].trim(), dd) - : depConfs[k].trim(); - if (mappedDependency != null) { - dd.addDependencyConfiguration(modConfs[j].trim(), - mappedDependency); - } - } - } else { - // no default mapping found for this configuration, map - // configuration to itself - dd.addDependencyConfiguration(modConfs[j].trim(), modConfs[j] - .trim()); - } - } - } - } else if (ops.length == 2) { - String[] modConfs = ops[0].split(","); - String[] depConfs = ops[1].split(","); - for (int j = 0; j < modConfs.length; j++) { - for (int k = 0; k < depConfs.length; k++) { - String mappedDependency = evaluateConditions ? evaluateCondition( - depConfs[k].trim(), dd) : depConfs[k].trim(); - if (mappedDependency != null) { - dd.addDependencyConfiguration(modConfs[j].trim(), mappedDependency); - } - } - } - } else { - addError("invalid conf " + conf[i] + " for " + dd.getDependencyRevisionId()); - } - } - - if (_md.isMappingOverride()) { - addExtendingConfigurations(conf, dd, useDefaultMappingToGuessRightOperande); - } - } - - /** - * Evaluate the optional condition in the given configuration, like "[org=MYORG]confX". If - * the condition evaluates to true, the configuration is returned, if the condition - * evaluatate to false, null is returned. If there are no conditions, the configuration - * itself is returned. - * - * @param conf - * the configuration to evaluate - * @param dd - * the dependencydescriptor to which the configuration will be added - * @return the evaluated condition - */ - private String evaluateCondition(String conf, DefaultDependencyDescriptor dd) { - if (conf.charAt(0) != '[') { - return conf; - } - - int endConditionIndex = conf.indexOf(']'); - if (endConditionIndex == -1) { - addError("invalid conf " + conf + " for " + dd.getDependencyRevisionId()); - return null; - } - - String condition = conf.substring(1, endConditionIndex); - - int notEqualIndex = condition.indexOf("!="); - if (notEqualIndex == -1) { - int equalIndex = condition.indexOf('='); - if (equalIndex == -1) { - addError("invalid conf " + conf + " for " + dd.getDependencyRevisionId()); - return null; - } - - String leftOp = condition.substring(0, equalIndex).trim(); - String rightOp = condition.substring(equalIndex + 1).trim(); - - // allow organisation synonyms, like 'org' or 'organization' - if (leftOp.equals("org") || leftOp.equals("organization")) { - leftOp = "organisation"; - } - - String attrValue = dd.getAttribute(leftOp); - if (!rightOp.equals(attrValue)) { - return null; - } - } else { - String leftOp = condition.substring(0, notEqualIndex).trim(); - String rightOp = condition.substring(notEqualIndex + 2).trim(); - - // allow organisation synonyms, like 'org' or 'organization' - if (leftOp.equals("org") || leftOp.equals("organization")) { - leftOp = "organisation"; - } - - String attrValue = dd.getAttribute(leftOp); - if (rightOp.equals(attrValue)) { - return null; - } - } - - return conf.substring(endConditionIndex + 1); - } - - private void addExtendingConfigurations(String[] confs, DefaultDependencyDescriptor dd, - boolean useDefaultMappingToGuessRightOperande) { - for (int i = 0; i < confs.length; i++) { - addExtendingConfigurations(confs[i], dd, useDefaultMappingToGuessRightOperande); - } - } - - private void addExtendingConfigurations(String conf, DefaultDependencyDescriptor dd, - boolean useDefaultMappingToGuessRightOperande) { - Set configsToAdd = new HashSet(); - Configuration[] configs = _md.getConfigurations(); - for (int i = 0; i < configs.length; i++) { - String[] ext = configs[i].getExtends(); - for (int j = 0; j < ext.length; j++) { - if (conf.equals(ext[j])) { - String configName = configs[i].getName(); - // if - // (getDefaultConfMappingDescriptor().getDependencyConfigurations(configName).length - // > 0) { - configsToAdd.add(configName); - // } else { - addExtendingConfigurations(configName, dd, - useDefaultMappingToGuessRightOperande); - // } - } - } - } - - String[] confs = (String[]) configsToAdd.toArray(new String[configsToAdd.size()]); - parseDepsConfs(confs, dd, useDefaultMappingToGuessRightOperande); - } - - protected DependencyDescriptor getDefaultConfMappingDescriptor() { - if (_defaultConfMappingDescriptor == null) { - _defaultConfMappingDescriptor = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("", "", ""), false); - parseDepsConfs(_defaultConfMapping, _defaultConfMappingDescriptor, false, false); - } - return _defaultConfMappingDescriptor; - } - - protected void addError(String msg) { - if (_res != null) { - _errors.add(msg + " in " + _res + "\n"); - } else { - _errors.add(msg + "\n"); - } - } - - public void warning(SAXParseException ex) { - Message.warn("xml parsing: " + getLocationString(ex) + ": " + ex.getMessage()); - } - - public void error(SAXParseException ex) { - addError("xml parsing: " + getLocationString(ex) + ": " + ex.getMessage()); - } - - public void fatalError(SAXParseException ex) throws SAXException { - addError("[Fatal Error] " + getLocationString(ex) + ": " + ex.getMessage()); - } - - /** Returns a string of the location. */ - private String getLocationString(SAXParseException ex) { - StringBuffer str = new StringBuffer(); - - String systemId = ex.getSystemId(); - if (systemId != null) { - int index = systemId.lastIndexOf('/'); - if (index != -1) - systemId = systemId.substring(index + 1); - str.append(systemId); - } else if (getResource() != null) { - str.append(getResource().toString()); - } - str.append(':'); - str.append(ex.getLineNumber()); - str.append(':'); - str.append(ex.getColumnNumber()); - - return str.toString(); - - } // getLocationString(SAXParseException):String - - protected String getDefaultConf() { - return _defaultConfMapping != null ? _defaultConfMapping - : (_defaultConf != null ? _defaultConf : DEFAULT_CONF_MAPPING); - } - - protected void setDefaultConf(String defaultConf) { - _defaultConf = defaultConf; - } - - public ModuleDescriptor getModuleDescriptor() throws ParseException { - checkErrors(); - return _md; - } - - protected Date getDefaultPubDate() { - return new Date(_md.getLastModified()); - } - - protected long getLastModified() { - long last = getResource().getLastModified(); - if (last > 0) { - return last; - } else { - Message.debug("impossible to get date for " + getResource() + ": using 'now'"); - return System.currentTimeMillis(); - } - } - - private void replaceConfigurationWildcards(ModuleDescriptor md) { - Configuration[] configs = md.getConfigurations(); - for (int i = 0; i < configs.length; i++) { - configs[i].replaceWildcards(md); - } - } - - } -} +/* + * 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.parser; + +import java.io.IOException; +import java.net.URL; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.url.URLResource; +import org.apache.ivy.util.Message; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +public abstract class AbstractModuleDescriptorParser implements ModuleDescriptorParser { + public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL descriptorURL, + boolean validate) throws ParseException, IOException { + return parseDescriptor(ivySettings, descriptorURL, new URLResource(descriptorURL), validate); + } + + protected abstract static class AbstractParser extends DefaultHandler { + private static final String DEFAULT_CONF_MAPPING = "*->*"; + + private String _defaultConf; // used only as defaultconf, not used for + + // guesssing right side part of a mapping + private String _defaultConfMapping; // same as default conf but is used + + // for guesssing right side part of a mapping + private DefaultDependencyDescriptor _defaultConfMappingDescriptor; + + private Resource _res; + + private List _errors = new ArrayList(); + + protected DefaultModuleDescriptor _md; + + private ModuleDescriptorParser _parser; + + protected AbstractParser(ModuleDescriptorParser parser) { + _parser = parser; + } + + public ModuleDescriptorParser getModuleDescriptorParser() { + return _parser; + } + + protected void checkErrors() throws ParseException { + if (!_errors.isEmpty()) { + throw new ParseException(_errors.toString(), 0); + } + } + + protected void setResource(Resource res) { + _res = res; // used for log and date only + _md = new DefaultModuleDescriptor(_parser, res); + _md.setLastModified(getLastModified()); + } + + protected Resource getResource() { + return _res; + } + + protected String getDefaultConfMapping() { + return _defaultConfMapping; + } + + protected void setDefaultConfMapping(String defaultConf) { + _defaultConfMapping = defaultConf; + } + + protected void parseDepsConfs(String confs, DefaultDependencyDescriptor dd) { + parseDepsConfs(confs, dd, _defaultConfMapping != null); + } + + protected void parseDepsConfs(String confs, DefaultDependencyDescriptor dd, + boolean useDefaultMappingToGuessRightOperande) { + parseDepsConfs(confs, dd, useDefaultMappingToGuessRightOperande, true); + } + + protected void parseDepsConfs(String confs, DefaultDependencyDescriptor dd, + boolean useDefaultMappingToGuessRightOperande, boolean evaluateConditions) { + if (confs == null) { + return; + } + + String[] conf = confs.split(";"); + parseDepsConfs(conf, dd, useDefaultMappingToGuessRightOperande, evaluateConditions); + } + + protected void parseDepsConfs(String[] conf, DefaultDependencyDescriptor dd, + boolean useDefaultMappingToGuessRightOperande) { + parseDepsConfs(conf, dd, useDefaultMappingToGuessRightOperande, true); + } + + protected void parseDepsConfs(String[] conf, DefaultDependencyDescriptor dd, + boolean useDefaultMappingToGuessRightOperande, boolean evaluateConditions) { + replaceConfigurationWildcards(_md); + for (int i = 0; i < conf.length; i++) { + String[] ops = conf[i].split("->"); + if (ops.length == 1) { + String[] modConfs = ops[0].split(","); + if (!useDefaultMappingToGuessRightOperande) { + for (int j = 0; j < modConfs.length; j++) { + dd.addDependencyConfiguration(modConfs[j].trim(), modConfs[j].trim()); + } + } else { + for (int j = 0; j < modConfs.length; j++) { + String[] depConfs = getDefaultConfMappingDescriptor() + .getDependencyConfigurations(modConfs[j]); + if (depConfs.length > 0) { + for (int k = 0; k < depConfs.length; k++) { + String mappedDependency = evaluateConditions ? evaluateCondition( + depConfs[k].trim(), dd) + : depConfs[k].trim(); + if (mappedDependency != null) { + dd.addDependencyConfiguration(modConfs[j].trim(), + mappedDependency); + } + } + } else { + // no default mapping found for this configuration, map + // configuration to itself + dd.addDependencyConfiguration(modConfs[j].trim(), modConfs[j] + .trim()); + } + } + } + } else if (ops.length == 2) { + String[] modConfs = ops[0].split(","); + String[] depConfs = ops[1].split(","); + for (int j = 0; j < modConfs.length; j++) { + for (int k = 0; k < depConfs.length; k++) { + String mappedDependency = evaluateConditions ? evaluateCondition( + depConfs[k].trim(), dd) : depConfs[k].trim(); + if (mappedDependency != null) { + dd.addDependencyConfiguration(modConfs[j].trim(), mappedDependency); + } + } + } + } else { + addError("invalid conf " + conf[i] + " for " + dd.getDependencyRevisionId()); + } + } + + if (_md.isMappingOverride()) { + addExtendingConfigurations(conf, dd, useDefaultMappingToGuessRightOperande); + } + } + + /** + * Evaluate the optional condition in the given configuration, like "[org=MYORG]confX". If + * the condition evaluates to true, the configuration is returned, if the condition + * evaluatate to false, null is returned. If there are no conditions, the configuration + * itself is returned. + * + * @param conf + * the configuration to evaluate + * @param dd + * the dependencydescriptor to which the configuration will be added + * @return the evaluated condition + */ + private String evaluateCondition(String conf, DefaultDependencyDescriptor dd) { + if (conf.charAt(0) != '[') { + return conf; + } + + int endConditionIndex = conf.indexOf(']'); + if (endConditionIndex == -1) { + addError("invalid conf " + conf + " for " + dd.getDependencyRevisionId()); + return null; + } + + String condition = conf.substring(1, endConditionIndex); + + int notEqualIndex = condition.indexOf("!="); + if (notEqualIndex == -1) { + int equalIndex = condition.indexOf('='); + if (equalIndex == -1) { + addError("invalid conf " + conf + " for " + dd.getDependencyRevisionId()); + return null; + } + + String leftOp = condition.substring(0, equalIndex).trim(); + String rightOp = condition.substring(equalIndex + 1).trim(); + + // allow organisation synonyms, like 'org' or 'organization' + if (leftOp.equals("org") || leftOp.equals("organization")) { + leftOp = "organisation"; + } + + String attrValue = dd.getAttribute(leftOp); + if (!rightOp.equals(attrValue)) { + return null; + } + } else { + String leftOp = condition.substring(0, notEqualIndex).trim(); + String rightOp = condition.substring(notEqualIndex + 2).trim(); + + // allow organisation synonyms, like 'org' or 'organization' + if (leftOp.equals("org") || leftOp.equals("organization")) { + leftOp = "organisation"; + } + + String attrValue = dd.getAttribute(leftOp); + if (rightOp.equals(attrValue)) { + return null; + } + } + + return conf.substring(endConditionIndex + 1); + } + + private void addExtendingConfigurations(String[] confs, DefaultDependencyDescriptor dd, + boolean useDefaultMappingToGuessRightOperande) { + for (int i = 0; i < confs.length; i++) { + addExtendingConfigurations(confs[i], dd, useDefaultMappingToGuessRightOperande); + } + } + + private void addExtendingConfigurations(String conf, DefaultDependencyDescriptor dd, + boolean useDefaultMappingToGuessRightOperande) { + Set configsToAdd = new HashSet(); + Configuration[] configs = _md.getConfigurations(); + for (int i = 0; i < configs.length; i++) { + String[] ext = configs[i].getExtends(); + for (int j = 0; j < ext.length; j++) { + if (conf.equals(ext[j])) { + String configName = configs[i].getName(); + // if + // (getDefaultConfMappingDescriptor().getDependencyConfigurations(configName).length + // > 0) { + configsToAdd.add(configName); + // } else { + addExtendingConfigurations(configName, dd, + useDefaultMappingToGuessRightOperande); + // } + } + } + } + + String[] confs = (String[]) configsToAdd.toArray(new String[configsToAdd.size()]); + parseDepsConfs(confs, dd, useDefaultMappingToGuessRightOperande); + } + + protected DependencyDescriptor getDefaultConfMappingDescriptor() { + if (_defaultConfMappingDescriptor == null) { + _defaultConfMappingDescriptor = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("", "", ""), false); + parseDepsConfs(_defaultConfMapping, _defaultConfMappingDescriptor, false, false); + } + return _defaultConfMappingDescriptor; + } + + protected void addError(String msg) { + if (_res != null) { + _errors.add(msg + " in " + _res + "\n"); + } else { + _errors.add(msg + "\n"); + } + } + + public void warning(SAXParseException ex) { + Message.warn("xml parsing: " + getLocationString(ex) + ": " + ex.getMessage()); + } + + public void error(SAXParseException ex) { + addError("xml parsing: " + getLocationString(ex) + ": " + ex.getMessage()); + } + + public void fatalError(SAXParseException ex) throws SAXException { + addError("[Fatal Error] " + getLocationString(ex) + ": " + ex.getMessage()); + } + + /** Returns a string of the location. */ + private String getLocationString(SAXParseException ex) { + StringBuffer str = new StringBuffer(); + + String systemId = ex.getSystemId(); + if (systemId != null) { + int index = systemId.lastIndexOf('/'); + if (index != -1) + systemId = systemId.substring(index + 1); + str.append(systemId); + } else if (getResource() != null) { + str.append(getResource().toString()); + } + str.append(':'); + str.append(ex.getLineNumber()); + str.append(':'); + str.append(ex.getColumnNumber()); + + return str.toString(); + + } // getLocationString(SAXParseException):String + + protected String getDefaultConf() { + return _defaultConfMapping != null ? _defaultConfMapping + : (_defaultConf != null ? _defaultConf : DEFAULT_CONF_MAPPING); + } + + protected void setDefaultConf(String defaultConf) { + _defaultConf = defaultConf; + } + + public ModuleDescriptor getModuleDescriptor() throws ParseException { + checkErrors(); + return _md; + } + + protected Date getDefaultPubDate() { + return new Date(_md.getLastModified()); + } + + protected long getLastModified() { + long last = getResource().getLastModified(); + if (last > 0) { + return last; + } else { + Message.debug("impossible to get date for " + getResource() + ": using 'now'"); + return System.currentTimeMillis(); + } + } + + private void replaceConfigurationWildcards(ModuleDescriptor md) { + Configuration[] configs = md.getConfigurations(); + for (int i = 0; i < configs.length; i++) { + configs[i].replaceWildcards(md); + } + } + + } +} diff --git a/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParser.java index 2bc7b910..ccacb04f 100644 --- a/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParser.java +++ b/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParser.java @@ -1,48 +1,48 @@ -/* - * 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.parser; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.ParseException; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.repository.Resource; - -public interface ModuleDescriptorParser { - public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL descriptorURL, - boolean validate) throws ParseException, IOException; - - public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL descriptorURL, - Resource res, boolean validate) throws ParseException, IOException; - - /** - * Convert a module descriptor to an ivy file. This method MUST close the given input stream - * when job is finished - * - * @param is - * input stream with opened on original module descriptor resource - */ - public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) - throws ParseException, IOException; - - public boolean accept(Resource res); -} +/* + * 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.parser; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.text.ParseException; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.repository.Resource; + +public interface ModuleDescriptorParser { + public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL descriptorURL, + boolean validate) throws ParseException, IOException; + + public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL descriptorURL, + Resource res, boolean validate) throws ParseException, IOException; + + /** + * Convert a module descriptor to an ivy file. This method MUST close the given input stream + * when job is finished + * + * @param is + * input stream with opened on original module descriptor resource + */ + public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) + throws ParseException, IOException; + + public boolean accept(Resource res); +} diff --git a/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistry.java b/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistry.java index 59973af2..cd747cff 100644 --- a/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistry.java +++ b/src/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistry.java @@ -1,103 +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.plugins.parser; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.ParseException; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.util.Message; - -public class ModuleDescriptorParserRegistry extends AbstractModuleDescriptorParser { - private static ModuleDescriptorParserRegistry INSTANCE = new ModuleDescriptorParserRegistry(); - - public static ModuleDescriptorParserRegistry getInstance() { - return INSTANCE; - } - - private List _parsers = new LinkedList(); - - private ModuleDescriptorParserRegistry() { - _parsers.add(PomModuleDescriptorParser.getInstance()); - _parsers.add(XmlModuleDescriptorParser.getInstance()); - } - - /** - * Adds a the given parser to this registry. - * - * @param parser - * the parser to add - */ - public void addParser(ModuleDescriptorParser parser) { - /* - * The parser is added in the front of the list of parsers. This is necessary because the - * XmlModuleDescriptorParser accepts all resources! - */ - _parsers.add(0, parser); - } - - public ModuleDescriptorParser[] getParsers() { - return (ModuleDescriptorParser[]) _parsers.toArray(new ModuleDescriptorParser[_parsers - .size()]); - } - - public ModuleDescriptorParser getParser(Resource res) { - for (Iterator iter = _parsers.iterator(); iter.hasNext();) { - ModuleDescriptorParser parser = (ModuleDescriptorParser) iter.next(); - if (parser.accept(res)) { - return parser; - } - } - return null; - } - - public ModuleDescriptor parseDescriptor(IvySettings settings, URL descriptorURL, Resource res, - boolean validate) throws ParseException, IOException { - ModuleDescriptorParser parser = getParser(res); - if (parser == null) { - Message.warn("no module descriptor parser found for " + res); - return null; - } - return parser.parseDescriptor(settings, descriptorURL, res, validate); - } - - public boolean accept(Resource res) { - return getParser(res) != null; - } - - public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) - throws ParseException, IOException { - ModuleDescriptorParser parser = getParser(res); - if (parser == null) { - Message.warn("no module descriptor parser found for " + res); - } else { - parser.toIvyFile(is, res, destFile, md); - } - } - -} +/* + * 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.parser; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.text.ParseException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParser; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.util.Message; + +public class ModuleDescriptorParserRegistry extends AbstractModuleDescriptorParser { + private static ModuleDescriptorParserRegistry INSTANCE = new ModuleDescriptorParserRegistry(); + + public static ModuleDescriptorParserRegistry getInstance() { + return INSTANCE; + } + + private List _parsers = new LinkedList(); + + private ModuleDescriptorParserRegistry() { + _parsers.add(PomModuleDescriptorParser.getInstance()); + _parsers.add(XmlModuleDescriptorParser.getInstance()); + } + + /** + * Adds a the given parser to this registry. + * + * @param parser + * the parser to add + */ + public void addParser(ModuleDescriptorParser parser) { + /* + * The parser is added in the front of the list of parsers. This is necessary because the + * XmlModuleDescriptorParser accepts all resources! + */ + _parsers.add(0, parser); + } + + public ModuleDescriptorParser[] getParsers() { + return (ModuleDescriptorParser[]) _parsers.toArray(new ModuleDescriptorParser[_parsers + .size()]); + } + + public ModuleDescriptorParser getParser(Resource res) { + for (Iterator iter = _parsers.iterator(); iter.hasNext();) { + ModuleDescriptorParser parser = (ModuleDescriptorParser) iter.next(); + if (parser.accept(res)) { + return parser; + } + } + return null; + } + + public ModuleDescriptor parseDescriptor(IvySettings settings, URL descriptorURL, Resource res, + boolean validate) throws ParseException, IOException { + ModuleDescriptorParser parser = getParser(res); + if (parser == null) { + Message.warn("no module descriptor parser found for " + res); + return null; + } + return parser.parseDescriptor(settings, descriptorURL, res, validate); + } + + public boolean accept(Resource res) { + return getParser(res) != null; + } + + public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) + throws ParseException, IOException { + ModuleDescriptorParser parser = getParser(res); + if (parser == null) { + Message.warn("no module descriptor parser found for " + res); + } else { + parser.toIvyFile(is, res, destFile, md); + } + } + +} diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java index 67638ab4..3b2d3a6d 100644 --- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java +++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java @@ -1,386 +1,386 @@ -/* - * 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.parser.m2; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Stack; - -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultExcludeRule; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.descriptor.Configuration.Visibility; -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.matcher.ExactPatternMatcher; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.XMLHelper; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -public class PomModuleDescriptorParser extends AbstractModuleDescriptorParser { - public static final Configuration[] MAVEN2_CONFIGURATIONS = new Configuration[] { - new Configuration("default", Visibility.PUBLIC, - "runtime dependencies and master artifact can be used with this conf", - new String[] {"runtime", "master"}), - new Configuration( - "master", - Visibility.PUBLIC, - "contains only the artifact published by this module itself, with no transitive dependencies", - new String[0]), - new Configuration( - "compile", - Visibility.PUBLIC, - "this is the default scope, used if none is specified. Compile dependencies are available in all classpaths.", - new String[0]), - new Configuration( - "provided", - Visibility.PUBLIC, - "this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive.", - new String[0]), - new Configuration( - "runtime", - Visibility.PUBLIC, - "this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.", - new String[] {"compile"}), - new Configuration( - "test", - Visibility.PRIVATE, - "this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.", - new String[0]), - new Configuration( - "system", - Visibility.PUBLIC, - "this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.", - new String[0]),}; - - private static final Configuration OPTIONAL_CONFIGURATION = new Configuration("optional", - Visibility.PUBLIC, "contains all optional dependencies", new String[0]); - - private static final Map MAVEN2_CONF_MAPPING = new HashMap(); - - static { - MAVEN2_CONF_MAPPING.put("compile", "compile->@(*),master(*);runtime->@(*)"); - MAVEN2_CONF_MAPPING - .put("provided", "provided->compile(*),provided(*),runtime(*),master(*)"); - MAVEN2_CONF_MAPPING.put("runtime", "runtime->compile(*),runtime(*),master(*)"); - MAVEN2_CONF_MAPPING.put("test", "test->compile(*),runtime(*),master(*)"); - MAVEN2_CONF_MAPPING.put("system", "system->master(*)"); - } - - private static final class Parser extends AbstractParser { - private IvySettings _settings; - - private Stack _contextStack = new Stack(); - - private String _organisation; - - private String _module; - - private String _revision; - - private String _scope; - - private String _classifier; - - private String _type; - - private String _ext; - - private boolean _optional = false; - - private List _exclusions = new ArrayList(); - - private DefaultDependencyDescriptor _dd; - - private Map _properties = new HashMap(); - - public Parser(ModuleDescriptorParser parser, IvySettings settings, Resource res) { - super(parser); - _settings = settings; - setResource(res); - _md.setResolvedPublicationDate(new Date(res.getLastModified())); - for (int i = 0; i < MAVEN2_CONFIGURATIONS.length; i++) { - _md.addConfiguration(MAVEN2_CONFIGURATIONS[i]); - } - } - - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - _contextStack.push(qName); - String context = getContext(); - if ("optional".equals(qName)) { - _optional = true; - } else if ("project/dependencies/dependency/exclusions".equals(context)) { - if (_dd == null) { - // stores dd now cause exclusions will override org and module - _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance( - _organisation, _module, _revision), true, false, true); - _organisation = null; - _module = null; - _revision = null; - } - } else if (_md.getModuleRevisionId() == null) { - if ("project/dependencies".equals(context) || "project/profiles".equals(context) - || "project/build".equals(context)) { - fillMrid(); - } - } - } - - private void fillMrid() throws SAXException { - if (_organisation == null) { - throw new SAXException("no groupId found in pom"); - } - if (_module == null) { - throw new SAXException("no artifactId found in pom"); - } - if (_revision == null) { - _revision = "SNAPSHOT"; - } - ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); - _properties.put("project.groupId", _organisation); - _properties.put("project.artifactId", _module); - _properties.put("project.version", _revision); - _properties.put("pom.version", _revision); - _properties.put("version", _revision); - _md.setModuleRevisionId(mrid); - if (_type == null) { - _type = _ext = "jar"; - } - _md.addArtifact("master", new DefaultArtifact(mrid, getDefaultPubDate(), _module, - _type, _ext)); - _organisation = null; - _module = null; - _revision = null; - } - - public void endElement(String uri, String localName, String qName) throws SAXException { - if (_md.getModuleRevisionId() == null && ("project".equals(getContext()))) { - fillMrid(); - } else if (((_organisation != null && _module != null && _revision != null) || _dd != null) - && "project/dependencies/dependency".equals(getContext())) { - if (_dd == null) { - _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance( - _organisation, _module, _revision), true, false, true); - } - _scope = _scope == null ? "compile" : _scope; - if (_optional && "compile".equals(_scope)) { - _scope = "runtime"; - } - String mapping = (String) MAVEN2_CONF_MAPPING.get(_scope); - if (mapping == null) { - Message.verbose("unknown scope " + _scope + " in " + getResource()); - mapping = (String) MAVEN2_CONF_MAPPING.get("compile"); - } - if (_optional) { - mapping = mapping.replaceAll(_scope + "\\-\\>", "optional->"); - if (_md.getConfiguration("optional") == null) { - _md.addConfiguration(OPTIONAL_CONFIGURATION); - } - } - parseDepsConfs(mapping, _dd); - - if (_classifier != null) { - // we deal with classifiers by setting an extra attribute and forcing the - // dependency to assume such an artifact is published - Map extraAtt = new HashMap(); - extraAtt.put("classifier", _classifier); - String[] confs = _dd.getModuleConfigurations(); - for (int i = 0; i < confs.length; i++) { - _dd.addDependencyArtifact(confs[i], - new DefaultDependencyArtifactDescriptor( - _dd.getDependencyId().getName(), "jar", "jar", // here we have - // to assume a - // type - // and ext for the artifact, so - // this is a limitation compared - // to how m2 behave with - // classifiers - null, extraAtt)); - } - } - for (Iterator iter = _exclusions.iterator(); iter.hasNext();) { - ModuleId mid = (ModuleId) iter.next(); - String[] confs = _dd.getModuleConfigurations(); - for (int i = 0; i < confs.length; i++) { - _dd - .addExcludeRule(confs[i], new DefaultExcludeRule(new ArtifactId( - mid, PatternMatcher.ANY_EXPRESSION, - PatternMatcher.ANY_EXPRESSION, - PatternMatcher.ANY_EXPRESSION), - ExactPatternMatcher.INSTANCE, null)); - } - } - _md.addDependency(_dd); - _dd = null; - } else if ((_organisation != null && _module != null) - && "project/dependencies/dependency/exclusions/exclusion".equals(getContext())) { - _exclusions.add(new ModuleId(_organisation, _module)); - _organisation = null; - _module = null; - } - if ("project/dependencies/dependency".equals(getContext())) { - _organisation = null; - _module = null; - _revision = null; - _scope = null; - _classifier = null; - _optional = false; - _exclusions.clear(); - } - _contextStack.pop(); - } - - public void characters(char[] ch, int start, int length) throws SAXException { - String txt = IvyPatternHelper.substituteVariables(new String(ch, start, length).trim(), - _properties); - if (txt.trim().length() == 0) { - return; - } - String context = getContext(); - if (context.equals("project/parent/groupId") && _organisation == null) { - _organisation = txt; - return; - } - if (context.equals("project/parent/version") && _revision == null) { - _revision = txt; - return; - } - if (context.equals("project/parent/packaging") && _type == null) { - _type = txt; - _ext = txt; - return; - } - if (context.startsWith("project/parent")) { - return; - } - if (_md.getModuleRevisionId() == null - || context.startsWith("project/dependencies/dependency")) { - if (context.equals("project/groupId")) { - _organisation = txt; - } else if (_organisation == null && context.endsWith("groupId")) { - _organisation = txt; - } else if (_module == null && context.endsWith("artifactId")) { - _module = txt; - } else if (context.equals("project/version") - || (_revision == null && context.endsWith("version"))) { - _revision = txt; - } else if (_revision == null && context.endsWith("version")) { - _revision = txt; - } else if (_type == null && context.endsWith("packaging")) { - _type = txt; - _ext = txt; - } else if (_scope == null && context.endsWith("scope")) { - _scope = txt; - } else if (_classifier == null && context.endsWith("dependency/classifier")) { - _classifier = txt; - } - } - } - - private String getContext() { - StringBuffer buf = new StringBuffer(); - for (Iterator iter = _contextStack.iterator(); iter.hasNext();) { - String ctx = (String) iter.next(); - buf.append(ctx).append("/"); - } - if (buf.length() > 0) { - buf.setLength(buf.length() - 1); - } - return buf.toString(); - } - - public ModuleDescriptor getDescriptor() { - if (_md.getModuleRevisionId() == null) { - return null; - } - return _md; - } - } - - private static PomModuleDescriptorParser INSTANCE = new PomModuleDescriptorParser(); - - public static PomModuleDescriptorParser getInstance() { - return INSTANCE; - } - - private PomModuleDescriptorParser() { - - } - - public ModuleDescriptor parseDescriptor(IvySettings settings, URL descriptorURL, Resource res, - boolean validate) throws ParseException, IOException { - Parser parser = new Parser(this, settings, res); - try { - XMLHelper.parse(descriptorURL, null, parser); - } catch (SAXException ex) { - ParseException pe = new ParseException(ex.getMessage() + " in " + descriptorURL, 0); - pe.initCause(ex); - throw pe; - } catch (ParserConfigurationException ex) { - IllegalStateException ise = new IllegalStateException(ex.getMessage() + " in " - + descriptorURL); - ise.initCause(ex); - throw ise; - } - return parser.getDescriptor(); - } - - public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) - throws ParseException, IOException { - try { - XmlModuleDescriptorWriter.write(md, destFile); - } finally { - if (is != null) { - is.close(); - } - } - } - - public boolean accept(Resource res) { - return res.getName().endsWith(".pom") || res.getName().endsWith("pom.xml") - || res.getName().endsWith("project.xml"); - } - - public String toString() { - return "pom parser"; - } -} +/* + * 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.parser.m2; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultExcludeRule; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.descriptor.Configuration.Visibility; +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.matcher.ExactPatternMatcher; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.XMLHelper; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +public class PomModuleDescriptorParser extends AbstractModuleDescriptorParser { + public static final Configuration[] MAVEN2_CONFIGURATIONS = new Configuration[] { + new Configuration("default", Visibility.PUBLIC, + "runtime dependencies and master artifact can be used with this conf", + new String[] {"runtime", "master"}), + new Configuration( + "master", + Visibility.PUBLIC, + "contains only the artifact published by this module itself, with no transitive dependencies", + new String[0]), + new Configuration( + "compile", + Visibility.PUBLIC, + "this is the default scope, used if none is specified. Compile dependencies are available in all classpaths.", + new String[0]), + new Configuration( + "provided", + Visibility.PUBLIC, + "this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive.", + new String[0]), + new Configuration( + "runtime", + Visibility.PUBLIC, + "this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.", + new String[] {"compile"}), + new Configuration( + "test", + Visibility.PRIVATE, + "this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.", + new String[0]), + new Configuration( + "system", + Visibility.PUBLIC, + "this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.", + new String[0]),}; + + private static final Configuration OPTIONAL_CONFIGURATION = new Configuration("optional", + Visibility.PUBLIC, "contains all optional dependencies", new String[0]); + + private static final Map MAVEN2_CONF_MAPPING = new HashMap(); + + static { + MAVEN2_CONF_MAPPING.put("compile", "compile->@(*),master(*);runtime->@(*)"); + MAVEN2_CONF_MAPPING + .put("provided", "provided->compile(*),provided(*),runtime(*),master(*)"); + MAVEN2_CONF_MAPPING.put("runtime", "runtime->compile(*),runtime(*),master(*)"); + MAVEN2_CONF_MAPPING.put("test", "test->compile(*),runtime(*),master(*)"); + MAVEN2_CONF_MAPPING.put("system", "system->master(*)"); + } + + private static final class Parser extends AbstractParser { + private IvySettings _settings; + + private Stack _contextStack = new Stack(); + + private String _organisation; + + private String _module; + + private String _revision; + + private String _scope; + + private String _classifier; + + private String _type; + + private String _ext; + + private boolean _optional = false; + + private List _exclusions = new ArrayList(); + + private DefaultDependencyDescriptor _dd; + + private Map _properties = new HashMap(); + + public Parser(ModuleDescriptorParser parser, IvySettings settings, Resource res) { + super(parser); + _settings = settings; + setResource(res); + _md.setResolvedPublicationDate(new Date(res.getLastModified())); + for (int i = 0; i < MAVEN2_CONFIGURATIONS.length; i++) { + _md.addConfiguration(MAVEN2_CONFIGURATIONS[i]); + } + } + + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + _contextStack.push(qName); + String context = getContext(); + if ("optional".equals(qName)) { + _optional = true; + } else if ("project/dependencies/dependency/exclusions".equals(context)) { + if (_dd == null) { + // stores dd now cause exclusions will override org and module + _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance( + _organisation, _module, _revision), true, false, true); + _organisation = null; + _module = null; + _revision = null; + } + } else if (_md.getModuleRevisionId() == null) { + if ("project/dependencies".equals(context) || "project/profiles".equals(context) + || "project/build".equals(context)) { + fillMrid(); + } + } + } + + private void fillMrid() throws SAXException { + if (_organisation == null) { + throw new SAXException("no groupId found in pom"); + } + if (_module == null) { + throw new SAXException("no artifactId found in pom"); + } + if (_revision == null) { + _revision = "SNAPSHOT"; + } + ModuleRevisionId mrid = ModuleRevisionId.newInstance(_organisation, _module, _revision); + _properties.put("project.groupId", _organisation); + _properties.put("project.artifactId", _module); + _properties.put("project.version", _revision); + _properties.put("pom.version", _revision); + _properties.put("version", _revision); + _md.setModuleRevisionId(mrid); + if (_type == null) { + _type = _ext = "jar"; + } + _md.addArtifact("master", new DefaultArtifact(mrid, getDefaultPubDate(), _module, + _type, _ext)); + _organisation = null; + _module = null; + _revision = null; + } + + public void endElement(String uri, String localName, String qName) throws SAXException { + if (_md.getModuleRevisionId() == null && ("project".equals(getContext()))) { + fillMrid(); + } else if (((_organisation != null && _module != null && _revision != null) || _dd != null) + && "project/dependencies/dependency".equals(getContext())) { + if (_dd == null) { + _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance( + _organisation, _module, _revision), true, false, true); + } + _scope = _scope == null ? "compile" : _scope; + if (_optional && "compile".equals(_scope)) { + _scope = "runtime"; + } + String mapping = (String) MAVEN2_CONF_MAPPING.get(_scope); + if (mapping == null) { + Message.verbose("unknown scope " + _scope + " in " + getResource()); + mapping = (String) MAVEN2_CONF_MAPPING.get("compile"); + } + if (_optional) { + mapping = mapping.replaceAll(_scope + "\\-\\>", "optional->"); + if (_md.getConfiguration("optional") == null) { + _md.addConfiguration(OPTIONAL_CONFIGURATION); + } + } + parseDepsConfs(mapping, _dd); + + if (_classifier != null) { + // we deal with classifiers by setting an extra attribute and forcing the + // dependency to assume such an artifact is published + Map extraAtt = new HashMap(); + extraAtt.put("classifier", _classifier); + String[] confs = _dd.getModuleConfigurations(); + for (int i = 0; i < confs.length; i++) { + _dd.addDependencyArtifact(confs[i], + new DefaultDependencyArtifactDescriptor( + _dd.getDependencyId().getName(), "jar", "jar", // here we have + // to assume a + // type + // and ext for the artifact, so + // this is a limitation compared + // to how m2 behave with + // classifiers + null, extraAtt)); + } + } + for (Iterator iter = _exclusions.iterator(); iter.hasNext();) { + ModuleId mid = (ModuleId) iter.next(); + String[] confs = _dd.getModuleConfigurations(); + for (int i = 0; i < confs.length; i++) { + _dd + .addExcludeRule(confs[i], new DefaultExcludeRule(new ArtifactId( + mid, PatternMatcher.ANY_EXPRESSION, + PatternMatcher.ANY_EXPRESSION, + PatternMatcher.ANY_EXPRESSION), + ExactPatternMatcher.INSTANCE, null)); + } + } + _md.addDependency(_dd); + _dd = null; + } else if ((_organisation != null && _module != null) + && "project/dependencies/dependency/exclusions/exclusion".equals(getContext())) { + _exclusions.add(new ModuleId(_organisation, _module)); + _organisation = null; + _module = null; + } + if ("project/dependencies/dependency".equals(getContext())) { + _organisation = null; + _module = null; + _revision = null; + _scope = null; + _classifier = null; + _optional = false; + _exclusions.clear(); + } + _contextStack.pop(); + } + + public void characters(char[] ch, int start, int length) throws SAXException { + String txt = IvyPatternHelper.substituteVariables(new String(ch, start, length).trim(), + _properties); + if (txt.trim().length() == 0) { + return; + } + String context = getContext(); + if (context.equals("project/parent/groupId") && _organisation == null) { + _organisation = txt; + return; + } + if (context.equals("project/parent/version") && _revision == null) { + _revision = txt; + return; + } + if (context.equals("project/parent/packaging") && _type == null) { + _type = txt; + _ext = txt; + return; + } + if (context.startsWith("project/parent")) { + return; + } + if (_md.getModuleRevisionId() == null + || context.startsWith("project/dependencies/dependency")) { + if (context.equals("project/groupId")) { + _organisation = txt; + } else if (_organisation == null && context.endsWith("groupId")) { + _organisation = txt; + } else if (_module == null && context.endsWith("artifactId")) { + _module = txt; + } else if (context.equals("project/version") + || (_revision == null && context.endsWith("version"))) { + _revision = txt; + } else if (_revision == null && context.endsWith("version")) { + _revision = txt; + } else if (_type == null && context.endsWith("packaging")) { + _type = txt; + _ext = txt; + } else if (_scope == null && context.endsWith("scope")) { + _scope = txt; + } else if (_classifier == null && context.endsWith("dependency/classifier")) { + _classifier = txt; + } + } + } + + private String getContext() { + StringBuffer buf = new StringBuffer(); + for (Iterator iter = _contextStack.iterator(); iter.hasNext();) { + String ctx = (String) iter.next(); + buf.append(ctx).append("/"); + } + if (buf.length() > 0) { + buf.setLength(buf.length() - 1); + } + return buf.toString(); + } + + public ModuleDescriptor getDescriptor() { + if (_md.getModuleRevisionId() == null) { + return null; + } + return _md; + } + } + + private static PomModuleDescriptorParser INSTANCE = new PomModuleDescriptorParser(); + + public static PomModuleDescriptorParser getInstance() { + return INSTANCE; + } + + private PomModuleDescriptorParser() { + + } + + public ModuleDescriptor parseDescriptor(IvySettings settings, URL descriptorURL, Resource res, + boolean validate) throws ParseException, IOException { + Parser parser = new Parser(this, settings, res); + try { + XMLHelper.parse(descriptorURL, null, parser); + } catch (SAXException ex) { + ParseException pe = new ParseException(ex.getMessage() + " in " + descriptorURL, 0); + pe.initCause(ex); + throw pe; + } catch (ParserConfigurationException ex) { + IllegalStateException ise = new IllegalStateException(ex.getMessage() + " in " + + descriptorURL); + ise.initCause(ex); + throw ise; + } + return parser.getDescriptor(); + } + + public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) + throws ParseException, IOException { + try { + XmlModuleDescriptorWriter.write(md, destFile); + } finally { + if (is != null) { + is.close(); + } + } + } + + public boolean accept(Resource res) { + return res.getName().endsWith(".pom") || res.getName().endsWith("pom.xml") + || res.getName().endsWith("project.xml"); + } + + public String toString() { + return "pom parser"; + } +} diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java index 7d003e4b..5cfc0a6b 100644 --- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java +++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java @@ -1,696 +1,696 @@ -/* - * 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.parser.xml; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.text.ParseException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.ConfigurationAware; -import org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultExcludeRule; -import org.apache.ivy.core.module.descriptor.DefaultIncludeRule; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; -import org.apache.ivy.core.module.descriptor.ExcludeRule; -import org.apache.ivy.core.module.descriptor.IncludeRule; -import org.apache.ivy.core.module.descriptor.License; -import org.apache.ivy.core.module.descriptor.MDArtifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.conflict.FixedConflictManager; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.repository.url.URLResource; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.XMLHelper; -import org.apache.ivy.util.extendable.ExtendableItemHelper; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * Parses an xml ivy file and output a ModuleDescriptor. For dependency and performance reasons, it - * uses only the SAX API, which makes the parsing code harder to understand. - */ -public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { - static final String[] DEPENDENCY_REGULAR_ATTRIBUTES = new String[] {"org", "name", "branch", - "rev", "force", "transitive", "changing", "conf"}; - - private static XmlModuleDescriptorParser INSTANCE = new XmlModuleDescriptorParser(); - - public static XmlModuleDescriptorParser getInstance() { - return INSTANCE; - } - - private XmlModuleDescriptorParser() { - - } - - /** - * @param ivy - * @param xmlURL - * the url pointing to the file to parse - * @param res - * the real resource to parse, used for log only - * @param validate - * @return - * @throws ParseException - * @throws IOException - */ - public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL xmlURL, Resource res, - boolean validate) throws ParseException, IOException { - Parser parser = new Parser(this, ivySettings, validate); - parser.parse(xmlURL, res, validate); - return parser.getModuleDescriptor(); - } - - public ModuleDescriptor parseDescriptor(IvySettings ivySettings, InputStream descriptor, - Resource res, boolean validate) throws ParseException, IOException { - Parser parser = new Parser(this, ivySettings, validate); - parser.parse(descriptor, res, validate); - return parser.getModuleDescriptor(); - } - - public boolean accept(Resource res) { - return true; // this the default parser, it thus accepts all resources - } - - public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) - throws IOException, ParseException { - try { - Namespace ns = null; - if (md instanceof DefaultModuleDescriptor) { - DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md; - ns = dmd.getNamespace(); - } - XmlModuleDescriptorUpdater.update(null, is, destFile, Collections.EMPTY_MAP, md - .getStatus(), md.getResolvedModuleRevisionId().getRevision(), md - .getResolvedPublicationDate(), ns, false, null); - } catch (SAXException e) { - ParseException ex = new ParseException("exception occured while parsing " + res, 0); - ex.initCause(e); - throw ex; - } finally { - if (is != null) { - is.close(); - } - } - } - - private static class Parser extends AbstractParser { - - private static final List ALLOWED_VERSIONS = Arrays.asList(new String[] {"1.0", "1.1", - "1.2", "1.3", "1.4", "2.0"}); - - private DefaultDependencyDescriptor _dd; - - private ConfigurationAware _confAware; - - private MDArtifact _artifact; - - private String _conf; - - private boolean _validate = true; - - private IvySettings _ivy; - - private boolean _artifactsDeclared = false; - - private PatternMatcher _defaultMatcher; - - private static final int NONE = 0; - - private static final int INFO = 1; - - private static final int CONF = 2; - - private static final int PUB = 3; - - private static final int DEP = 4; - - private static final int DEP_ARTIFACT = 5; - - private static final int ARTIFACT_INCLUDE = 6; - - private static final int ARTIFACT_EXCLUDE = 7; - - private static final int CONFLICT = 8; - - private static final int EXCLUDE = 9; - - private int _state = NONE; - - public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate) { - super(parser); - _ivy = ivySettings; - _validate = validate; - } - - private void parse(URL xmlURL, Resource res, boolean validate) throws ParseException, - IOException { - try { - setResource(res); - URL schemaURL = validate ? getClass().getResource("ivy.xsd") : null; - XMLHelper.parse(xmlURL, schemaURL, this); - checkConfigurations(); - replaceConfigurationWildcards(); - if (!_artifactsDeclared) { - String[] confs = _md.getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - _md.addArtifact(confs[i], new MDArtifact(_md, _md.getModuleRevisionId() - .getName(), "jar", "jar")); - } - } - _md.check(); - } catch (ParserConfigurationException ex) { - IllegalStateException ise = new IllegalStateException(ex.getMessage() + " in " - + xmlURL); - ise.initCause(ex); - throw ise; - } catch (Exception ex) { - checkErrors(); - ParseException pe = new ParseException(ex.getMessage() + " in " + xmlURL, 0); - pe.initCause(ex); - throw pe; - } - } - - private void parse(InputStream descriptor, Resource res, boolean validate) - throws ParseException, IOException { - try { - setResource(res); - URL schemaURL = validate ? getClass().getResource("ivy.xsd") : null; - XMLHelper.parse(descriptor, schemaURL, this, null); - checkConfigurations(); - replaceConfigurationWildcards(); - if (!_artifactsDeclared) { - String[] confs = _md.getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - _md.addArtifact(confs[i], new MDArtifact(_md, _md.getModuleRevisionId() - .getName(), "jar", "jar")); - } - } - _md.check(); - } catch (ParserConfigurationException ex) { - IllegalStateException ise = new IllegalStateException(ex.getMessage()); - ise.initCause(ex); - throw ise; - } catch (Exception ex) { - checkErrors(); - ParseException pe = new ParseException(ex.getMessage(), 0); - pe.initCause(ex); - throw pe; - } - } - - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - try { - if ("ivy-module".equals(qName)) { - String version = attributes.getValue("version"); - int versionIndex = ALLOWED_VERSIONS.indexOf(version); - if (versionIndex == -1) { - addError("invalid version " + version); - throw new SAXException("invalid version " + version); - } - if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) { - Message.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT - + " as default matcher"); - _defaultMatcher = _ivy.getMatcher(PatternMatcher.EXACT); - } else { - Message.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP - + " as default matcher"); - _defaultMatcher = _ivy.getMatcher(PatternMatcher.EXACT_OR_REGEXP); - } - } else if ("info".equals(qName)) { - _state = INFO; - String org = _ivy.substitute(attributes.getValue("organisation")); - String module = _ivy.substitute(attributes.getValue("module")); - String revision = _ivy.substitute(attributes.getValue("revision")); - String branch = _ivy.substitute(attributes.getValue("branch")); - _md.setModuleRevisionId(ModuleRevisionId.newInstance(org, module, branch, - revision, ExtendableItemHelper.getExtraAttributes(attributes, new String[] { - "organisation", "module", "revision", "status", "publication", - "namespace", "default", "resolver"}))); - - String namespace = _ivy.substitute(attributes.getValue("namespace")); - if (namespace != null) { - Namespace ns = _ivy.getNamespace(namespace); - if (ns == null) { - Message.warn("namespace not found for " + _md.getModuleRevisionId() - + ": " + namespace); - } else { - _md.setNamespace(ns); - } - } - - String status = _ivy.substitute(attributes.getValue("status")); - _md.setStatus(status == null ? _ivy.getStatusManager().getDefaultStatus() - : status); - _md.setDefault(Boolean.valueOf(_ivy.substitute(attributes.getValue("default"))) - .booleanValue()); - String pubDate = _ivy.substitute(attributes.getValue("publication")); - if (pubDate != null && pubDate.length() > 0) { - try { - _md.setPublicationDate(Ivy.DATE_FORMAT.parse(pubDate)); - } catch (ParseException e) { - addError("invalid publication date format: " + pubDate); - _md.setPublicationDate(getDefaultPubDate()); - } - } else { - _md.setPublicationDate(getDefaultPubDate()); - } - - } else if ("license".equals(qName)) { - _md.addLicense(new License(_ivy.substitute(attributes.getValue("name")), _ivy - .substitute(attributes.getValue("url")))); - } else if ("description".equals(qName)) { - _md.setHomePage(_ivy.substitute(attributes.getValue("homepage"))); - } else if ("configurations".equals(qName)) { - _state = CONF; - setDefaultConfMapping(_ivy - .substitute(attributes.getValue("defaultconfmapping"))); - _md - .setMappingOverride(Boolean.valueOf( - _ivy.substitute(attributes.getValue("confmappingoverride"))) - .booleanValue()); - } else if ("publications".equals(qName)) { - _state = PUB; - _artifactsDeclared = true; - checkConfigurations(); - } else if ("dependencies".equals(qName)) { - _state = DEP; - String defaultConf = _ivy.substitute(attributes.getValue("defaultconf")); - if (defaultConf != null) { - setDefaultConf(defaultConf); - } - defaultConf = _ivy.substitute(attributes.getValue("defaultconfmapping")); - if (defaultConf != null) { - setDefaultConfMapping(defaultConf); - } - String confMappingOverride = _ivy.substitute(attributes - .getValue("confmappingoverride")); - if (confMappingOverride != null) { - _md.setMappingOverride(Boolean.valueOf(confMappingOverride).booleanValue()); - } - checkConfigurations(); - } else if ("conflicts".equals(qName)) { - _state = CONFLICT; - checkConfigurations(); - } else if ("exclude".equals(qName) && _state != DEP) { - _state = EXCLUDE; - checkConfigurations(); - } else if ("artifact".equals(qName)) { - if (_state == PUB) { - // this is a published artifact - String artName = _ivy.substitute(attributes.getValue("name")); - artName = artName == null ? _md.getModuleRevisionId().getName() : artName; - String type = _ivy.substitute(attributes.getValue("type")); - type = type == null ? "jar" : type; - String ext = _ivy.substitute(attributes.getValue("ext")); - ext = ext != null ? ext : type; - String url = _ivy.substitute(attributes.getValue("url")); - _artifact = new MDArtifact(_md, artName, type, ext, url == null ? null - : new URL(url), ExtendableItemHelper.getExtraAttributes(attributes, - new String[] {"ext", "type", "name", "conf"})); - String confs = _ivy.substitute(attributes.getValue("conf")); - // only add confs if they are specified. if they aren't, endElement will - // handle this - // only if there are no conf defined in sub elements - if (confs != null && confs.length() > 0) { - String[] conf; - if ("*".equals(confs)) { - conf = _md.getConfigurationsNames(); - } else { - conf = confs.split(","); - } - for (int i = 0; i < conf.length; i++) { - _artifact.addConfiguration(conf[i].trim()); - _md.addArtifact(conf[i].trim(), _artifact); - } - } - } else if (_state == DEP) { - // this is an artifact asked for a particular dependency - addDependencyArtifacts(qName, attributes); - } else if (_validate) { - addError("artifact tag found in invalid tag: " + _state); - } - } else if ("include".equals(qName) && _state == DEP) { - addIncludeRule(qName, attributes); - } else if ("exclude".equals(qName) && _state == DEP) { - addExcludeRule(qName, attributes); - } else if ("dependency".equals(qName)) { - String org = _ivy.substitute(attributes.getValue("org")); - if (org == null) { - org = _md.getModuleRevisionId().getOrganisation(); - } - boolean force = Boolean.valueOf(_ivy.substitute(attributes.getValue("force"))) - .booleanValue(); - boolean changing = Boolean.valueOf( - _ivy.substitute(attributes.getValue("changing"))).booleanValue(); - - String transitiveValue = _ivy.substitute(attributes.getValue("transitive")); - boolean transitive = (transitiveValue == null) ? true : Boolean.valueOf( - attributes.getValue("transitive")).booleanValue(); - - String name = _ivy.substitute(attributes.getValue("name")); - String branch = _ivy.substitute(attributes.getValue("branch")); - String rev = _ivy.substitute(attributes.getValue("rev")); - _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance(org, - name, branch, rev, ExtendableItemHelper.getExtraAttributes(attributes, - DEPENDENCY_REGULAR_ATTRIBUTES)), force, changing, transitive); - _md.addDependency(_dd); - String confs = _ivy.substitute(attributes.getValue("conf")); - if (confs != null && confs.length() > 0) { - parseDepsConfs(confs, _dd); - } - } else if ("conf".equals(qName)) { - String conf = _ivy.substitute(attributes.getValue("name")); - switch (_state) { - case CONF: - String visibility = _ivy.substitute(attributes.getValue("visibility")); - String ext = _ivy.substitute(attributes.getValue("extends")); - String transitiveValue = attributes.getValue("transitive"); - boolean transitive = (transitiveValue == null) ? true : Boolean - .valueOf(attributes.getValue("transitive")).booleanValue(); - Configuration configuration = new Configuration(conf, - Configuration.Visibility - .getVisibility(visibility == null ? "public" - : visibility), _ivy.substitute(attributes - .getValue("description")), ext == null ? null : ext - .split(","), transitive); - ExtendableItemHelper.fillExtraAttributes(configuration, attributes, - new String[] {"name", "visibility", "extends", "transitive", - "description"}); - _md.addConfiguration(configuration); - break; - case PUB: - if ("*".equals(conf)) { - String[] confs = _md.getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - _artifact.addConfiguration(confs[i]); - _md.addArtifact(confs[i], _artifact); - } - } else { - _artifact.addConfiguration(conf); - _md.addArtifact(conf, _artifact); - } - break; - case DEP: - _conf = conf; - String mappeds = _ivy.substitute(attributes.getValue("mapped")); - if (mappeds != null) { - String[] mapped = mappeds.split(","); - for (int i = 0; i < mapped.length; i++) { - _dd.addDependencyConfiguration(_conf, mapped[i].trim()); - } - } - break; - case DEP_ARTIFACT: - case ARTIFACT_INCLUDE: - case ARTIFACT_EXCLUDE: - addConfiguration(conf); - break; - default: - if (_validate) { - addError("conf tag found in invalid tag: " + _state); - } - break; - } - } else if ("mapped".equals(qName)) { - _dd.addDependencyConfiguration(_conf, _ivy.substitute(attributes - .getValue("name"))); - } else if ("manager".equals(qName) && _state == CONFLICT) { - String org = _ivy.substitute(attributes.getValue("org")); - org = org == null ? PatternMatcher.ANY_EXPRESSION : org; - String mod = _ivy.substitute(attributes.getValue("module")); - mod = mod == null ? PatternMatcher.ANY_EXPRESSION : mod; - ConflictManager cm; - String name = _ivy.substitute(attributes.getValue("name")); - String rev = _ivy.substitute(attributes.getValue("rev")); - if (rev != null) { - String[] revs = rev.split(","); - for (int i = 0; i < revs.length; i++) { - revs[i] = revs[i].trim(); - } - cm = new FixedConflictManager(revs); - } else if (name != null) { - cm = _ivy.getConflictManager(name); - if (cm == null) { - addError("unknown conflict manager: " + name); - return; - } - } else { - addError("bad conflict manager: no name nor rev"); - return; - } - String matcherName = _ivy.substitute(attributes.getValue("matcher")); - PatternMatcher matcher = matcherName == null ? _defaultMatcher : _ivy - .getMatcher(matcherName); - if (matcher == null) { - addError("unknown matcher: " + matcherName); - return; - } - _md.addConflictManager(new ModuleId(org, mod), matcher, cm); - } else if ("rule".equals(qName) && _state == EXCLUDE) { - parseRule(qName, attributes); - _md.addExcludeRule((ExcludeRule) _confAware); - } else if ("include".equals(qName) && _state == CONF) { - URL url; - String fileName = _ivy.substitute(attributes.getValue("file")); - if (fileName == null) { - String urlStr = _ivy.substitute(attributes.getValue("url")); - url = new URL(urlStr); - } else { - url = new File(fileName).toURL(); - } - - // create a new temporary parser to read the configurations from - // the specified file. - Parser parser = new Parser(getModuleDescriptorParser(), _ivy, false); - parser._md = new DefaultModuleDescriptor(getModuleDescriptorParser(), - new URLResource(url)); - XMLHelper.parse(url, null, parser); - - // add the configurations from this temporary parser to this module descriptor - Configuration[] configs = parser.getModuleDescriptor().getConfigurations(); - for (int i = 0; i < configs.length; i++) { - _md.addConfiguration(configs[i]); - } - if (parser.getDefaultConfMapping() != null) { - Message.debug("setting default conf from imported configurations file: " - + parser.getDefaultConfMapping()); - setDefaultConfMapping(parser.getDefaultConfMapping()); - } - if (parser._md.isMappingOverride()) { - Message - .debug("enabling mapping-override from imported configurations file"); - _md.setMappingOverride(true); - } - } else if (_validate && _state != INFO) { - addError("unknwon tag " + qName); - } - } catch (Exception ex) { - if (ex instanceof SAXException) { - throw (SAXException) ex; - } - throw new SAXException("problem occured while parsing ivy file. message: " - + ex.getMessage(), ex); - } - } - - private void addDependencyArtifacts(String tag, Attributes attributes) - throws MalformedURLException { - _state = DEP_ARTIFACT; - parseRule(tag, attributes); - } - - private void addIncludeRule(String tag, Attributes attributes) throws MalformedURLException { - _state = ARTIFACT_INCLUDE; - parseRule(tag, attributes); - } - - private void addExcludeRule(String tag, Attributes attributes) throws MalformedURLException { - _state = ARTIFACT_EXCLUDE; - parseRule(tag, attributes); - } - - private void parseRule(String tag, Attributes attributes) throws MalformedURLException { - String name = _ivy.substitute(attributes.getValue("name")); - if (name == null) { - name = _ivy.substitute(attributes.getValue("artifact")); - if (name == null) { - name = "artifact".equals(tag) ? _dd.getDependencyId().getName() - : PatternMatcher.ANY_EXPRESSION; - } - } - String type = _ivy.substitute(attributes.getValue("type")); - if (type == null) { - type = "artifact".equals(tag) ? "jar" : PatternMatcher.ANY_EXPRESSION; - } - String ext = _ivy.substitute(attributes.getValue("ext")); - ext = ext != null ? ext : type; - if (_state == DEP_ARTIFACT) { - String url = _ivy.substitute(attributes.getValue("url")); - Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] { - "name", "type", "ext", "url", "conf"}); - _confAware = new DefaultDependencyArtifactDescriptor(name, type, ext, - url == null ? null : new URL(url), extraAtt); - } else if (_state == ARTIFACT_INCLUDE) { - PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher")); - String org = _ivy.substitute(attributes.getValue("org")); - org = org == null ? PatternMatcher.ANY_EXPRESSION : org; - String module = _ivy.substitute(attributes.getValue("module")); - module = module == null ? PatternMatcher.ANY_EXPRESSION : module; - ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext); - Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] { - "org", "module", "name", "type", "ext", "matcher", "conf"}); - _confAware = new DefaultIncludeRule(aid, matcher, extraAtt); - } else { // _state == ARTIFACT_EXCLUDE - PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher")); - String org = _ivy.substitute(attributes.getValue("org")); - org = org == null ? PatternMatcher.ANY_EXPRESSION : org; - String module = _ivy.substitute(attributes.getValue("module")); - module = module == null ? PatternMatcher.ANY_EXPRESSION : module; - ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext); - Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] { - "org", "module", "name", "type", "ext", "matcher", "conf"}); - _confAware = new DefaultExcludeRule(aid, matcher, extraAtt); - } - String confs = _ivy.substitute(attributes.getValue("conf")); - // only add confs if they are specified. if they aren't, endElement will handle this - // only if there are no conf defined in sub elements - if (confs != null && confs.length() > 0) { - String[] conf; - if ("*".equals(confs)) { - conf = _md.getConfigurationsNames(); - } else { - conf = confs.split(","); - } - for (int i = 0; i < conf.length; i++) { - addConfiguration(conf[i].trim()); - } - } - } - - private void addConfiguration(String c) { - _confAware.addConfiguration(c); - if (_state == EXCLUDE) { - // we are adding a configuration to a module wide exclude rule - // we have nothing special to do here, the rule has already been added to the module - // descriptor - } else { - // we are currently adding a configuration to either an include, exclude or artifact - // element - // of a dependency. This means that we have to add this element to the corresponding - // conf - // of the current dependency descriptor - if (_confAware instanceof DependencyArtifactDescriptor) { - _dd.addDependencyArtifact(c, (DependencyArtifactDescriptor) _confAware); - } else if (_confAware instanceof IncludeRule) { - _dd.addIncludeRule(c, (IncludeRule) _confAware); - } else if (_confAware instanceof ExcludeRule) { - _dd.addExcludeRule(c, (ExcludeRule) _confAware); - } - } - } - - private PatternMatcher getPatternMatcher(String m) { - String matcherName = _ivy.substitute(m); - PatternMatcher matcher = matcherName == null ? _defaultMatcher : _ivy - .getMatcher(matcherName); - if (matcher == null) { - throw new IllegalArgumentException("unknown matcher " + matcherName); - } - return matcher; - } - - public void endElement(String uri, String localName, String qName) throws SAXException { - if (_state == PUB && "artifact".equals(qName) - && _artifact.getConfigurations().length == 0) { - String[] confs = _md.getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - _artifact.addConfiguration(confs[i]); - _md.addArtifact(confs[i], _artifact); - } - } else if ("configurations".equals(qName)) { - checkConfigurations(); - } else if ((_state == DEP_ARTIFACT && "artifact".equals(qName)) - || (_state == ARTIFACT_INCLUDE && "include".equals(qName)) - || (_state == ARTIFACT_EXCLUDE && "exclude".equals(qName))) { - _state = DEP; - if (_confAware.getConfigurations().length == 0) { - String[] confs = _md.getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - addConfiguration(confs[i]); - } - } - _confAware = null; - } else if (_state == EXCLUDE && "rule".equals(qName)) { - if (_confAware.getConfigurations().length == 0) { - String[] confs = _md.getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - addConfiguration(confs[i]); - } - } - _confAware = null; - } else if ("dependency".equals(qName) && _dd.getModuleConfigurations().length == 0) { - parseDepsConfs(getDefaultConf(), _dd); - } else if ("dependencies".equals(qName)) { - _state = NONE; - } - } - - private void checkConfigurations() { - if (_md.getConfigurations().length == 0) { - _md.addConfiguration(new Configuration("default")); - } - } - - private void replaceConfigurationWildcards() { - Configuration[] configs = _md.getConfigurations(); - for (int i = 0; i < configs.length; i++) { - configs[i].replaceWildcards(_md); - } - } - - } - - public String toString() { - return "ivy parser"; - } -} +/* + * 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.parser.xml; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.ParseException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.ConfigurationAware; +import org.apache.ivy.core.module.descriptor.DefaultDependencyArtifactDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultExcludeRule; +import org.apache.ivy.core.module.descriptor.DefaultIncludeRule; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; +import org.apache.ivy.core.module.descriptor.ExcludeRule; +import org.apache.ivy.core.module.descriptor.IncludeRule; +import org.apache.ivy.core.module.descriptor.License; +import org.apache.ivy.core.module.descriptor.MDArtifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.conflict.FixedConflictManager; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParser; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.url.URLResource; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.XMLHelper; +import org.apache.ivy.util.extendable.ExtendableItemHelper; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * Parses an xml ivy file and output a ModuleDescriptor. For dependency and performance reasons, it + * uses only the SAX API, which makes the parsing code harder to understand. + */ +public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { + static final String[] DEPENDENCY_REGULAR_ATTRIBUTES = new String[] {"org", "name", "branch", + "rev", "force", "transitive", "changing", "conf"}; + + private static XmlModuleDescriptorParser INSTANCE = new XmlModuleDescriptorParser(); + + public static XmlModuleDescriptorParser getInstance() { + return INSTANCE; + } + + private XmlModuleDescriptorParser() { + + } + + /** + * @param ivy + * @param xmlURL + * the url pointing to the file to parse + * @param res + * the real resource to parse, used for log only + * @param validate + * @return + * @throws ParseException + * @throws IOException + */ + public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL xmlURL, Resource res, + boolean validate) throws ParseException, IOException { + Parser parser = new Parser(this, ivySettings, validate); + parser.parse(xmlURL, res, validate); + return parser.getModuleDescriptor(); + } + + public ModuleDescriptor parseDescriptor(IvySettings ivySettings, InputStream descriptor, + Resource res, boolean validate) throws ParseException, IOException { + Parser parser = new Parser(this, ivySettings, validate); + parser.parse(descriptor, res, validate); + return parser.getModuleDescriptor(); + } + + public boolean accept(Resource res) { + return true; // this the default parser, it thus accepts all resources + } + + public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) + throws IOException, ParseException { + try { + Namespace ns = null; + if (md instanceof DefaultModuleDescriptor) { + DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md; + ns = dmd.getNamespace(); + } + XmlModuleDescriptorUpdater.update(null, is, destFile, Collections.EMPTY_MAP, md + .getStatus(), md.getResolvedModuleRevisionId().getRevision(), md + .getResolvedPublicationDate(), ns, false, null); + } catch (SAXException e) { + ParseException ex = new ParseException("exception occured while parsing " + res, 0); + ex.initCause(e); + throw ex; + } finally { + if (is != null) { + is.close(); + } + } + } + + private static class Parser extends AbstractParser { + + private static final List ALLOWED_VERSIONS = Arrays.asList(new String[] {"1.0", "1.1", + "1.2", "1.3", "1.4", "2.0"}); + + private DefaultDependencyDescriptor _dd; + + private ConfigurationAware _confAware; + + private MDArtifact _artifact; + + private String _conf; + + private boolean _validate = true; + + private IvySettings _ivy; + + private boolean _artifactsDeclared = false; + + private PatternMatcher _defaultMatcher; + + private static final int NONE = 0; + + private static final int INFO = 1; + + private static final int CONF = 2; + + private static final int PUB = 3; + + private static final int DEP = 4; + + private static final int DEP_ARTIFACT = 5; + + private static final int ARTIFACT_INCLUDE = 6; + + private static final int ARTIFACT_EXCLUDE = 7; + + private static final int CONFLICT = 8; + + private static final int EXCLUDE = 9; + + private int _state = NONE; + + public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate) { + super(parser); + _ivy = ivySettings; + _validate = validate; + } + + private void parse(URL xmlURL, Resource res, boolean validate) throws ParseException, + IOException { + try { + setResource(res); + URL schemaURL = validate ? getClass().getResource("ivy.xsd") : null; + XMLHelper.parse(xmlURL, schemaURL, this); + checkConfigurations(); + replaceConfigurationWildcards(); + if (!_artifactsDeclared) { + String[] confs = _md.getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + _md.addArtifact(confs[i], new MDArtifact(_md, _md.getModuleRevisionId() + .getName(), "jar", "jar")); + } + } + _md.check(); + } catch (ParserConfigurationException ex) { + IllegalStateException ise = new IllegalStateException(ex.getMessage() + " in " + + xmlURL); + ise.initCause(ex); + throw ise; + } catch (Exception ex) { + checkErrors(); + ParseException pe = new ParseException(ex.getMessage() + " in " + xmlURL, 0); + pe.initCause(ex); + throw pe; + } + } + + private void parse(InputStream descriptor, Resource res, boolean validate) + throws ParseException, IOException { + try { + setResource(res); + URL schemaURL = validate ? getClass().getResource("ivy.xsd") : null; + XMLHelper.parse(descriptor, schemaURL, this, null); + checkConfigurations(); + replaceConfigurationWildcards(); + if (!_artifactsDeclared) { + String[] confs = _md.getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + _md.addArtifact(confs[i], new MDArtifact(_md, _md.getModuleRevisionId() + .getName(), "jar", "jar")); + } + } + _md.check(); + } catch (ParserConfigurationException ex) { + IllegalStateException ise = new IllegalStateException(ex.getMessage()); + ise.initCause(ex); + throw ise; + } catch (Exception ex) { + checkErrors(); + ParseException pe = new ParseException(ex.getMessage(), 0); + pe.initCause(ex); + throw pe; + } + } + + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + try { + if ("ivy-module".equals(qName)) { + String version = attributes.getValue("version"); + int versionIndex = ALLOWED_VERSIONS.indexOf(version); + if (versionIndex == -1) { + addError("invalid version " + version); + throw new SAXException("invalid version " + version); + } + if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) { + Message.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT + + " as default matcher"); + _defaultMatcher = _ivy.getMatcher(PatternMatcher.EXACT); + } else { + Message.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP + + " as default matcher"); + _defaultMatcher = _ivy.getMatcher(PatternMatcher.EXACT_OR_REGEXP); + } + } else if ("info".equals(qName)) { + _state = INFO; + String org = _ivy.substitute(attributes.getValue("organisation")); + String module = _ivy.substitute(attributes.getValue("module")); + String revision = _ivy.substitute(attributes.getValue("revision")); + String branch = _ivy.substitute(attributes.getValue("branch")); + _md.setModuleRevisionId(ModuleRevisionId.newInstance(org, module, branch, + revision, ExtendableItemHelper.getExtraAttributes(attributes, new String[] { + "organisation", "module", "revision", "status", "publication", + "namespace", "default", "resolver"}))); + + String namespace = _ivy.substitute(attributes.getValue("namespace")); + if (namespace != null) { + Namespace ns = _ivy.getNamespace(namespace); + if (ns == null) { + Message.warn("namespace not found for " + _md.getModuleRevisionId() + + ": " + namespace); + } else { + _md.setNamespace(ns); + } + } + + String status = _ivy.substitute(attributes.getValue("status")); + _md.setStatus(status == null ? _ivy.getStatusManager().getDefaultStatus() + : status); + _md.setDefault(Boolean.valueOf(_ivy.substitute(attributes.getValue("default"))) + .booleanValue()); + String pubDate = _ivy.substitute(attributes.getValue("publication")); + if (pubDate != null && pubDate.length() > 0) { + try { + _md.setPublicationDate(Ivy.DATE_FORMAT.parse(pubDate)); + } catch (ParseException e) { + addError("invalid publication date format: " + pubDate); + _md.setPublicationDate(getDefaultPubDate()); + } + } else { + _md.setPublicationDate(getDefaultPubDate()); + } + + } else if ("license".equals(qName)) { + _md.addLicense(new License(_ivy.substitute(attributes.getValue("name")), _ivy + .substitute(attributes.getValue("url")))); + } else if ("description".equals(qName)) { + _md.setHomePage(_ivy.substitute(attributes.getValue("homepage"))); + } else if ("configurations".equals(qName)) { + _state = CONF; + setDefaultConfMapping(_ivy + .substitute(attributes.getValue("defaultconfmapping"))); + _md + .setMappingOverride(Boolean.valueOf( + _ivy.substitute(attributes.getValue("confmappingoverride"))) + .booleanValue()); + } else if ("publications".equals(qName)) { + _state = PUB; + _artifactsDeclared = true; + checkConfigurations(); + } else if ("dependencies".equals(qName)) { + _state = DEP; + String defaultConf = _ivy.substitute(attributes.getValue("defaultconf")); + if (defaultConf != null) { + setDefaultConf(defaultConf); + } + defaultConf = _ivy.substitute(attributes.getValue("defaultconfmapping")); + if (defaultConf != null) { + setDefaultConfMapping(defaultConf); + } + String confMappingOverride = _ivy.substitute(attributes + .getValue("confmappingoverride")); + if (confMappingOverride != null) { + _md.setMappingOverride(Boolean.valueOf(confMappingOverride).booleanValue()); + } + checkConfigurations(); + } else if ("conflicts".equals(qName)) { + _state = CONFLICT; + checkConfigurations(); + } else if ("exclude".equals(qName) && _state != DEP) { + _state = EXCLUDE; + checkConfigurations(); + } else if ("artifact".equals(qName)) { + if (_state == PUB) { + // this is a published artifact + String artName = _ivy.substitute(attributes.getValue("name")); + artName = artName == null ? _md.getModuleRevisionId().getName() : artName; + String type = _ivy.substitute(attributes.getValue("type")); + type = type == null ? "jar" : type; + String ext = _ivy.substitute(attributes.getValue("ext")); + ext = ext != null ? ext : type; + String url = _ivy.substitute(attributes.getValue("url")); + _artifact = new MDArtifact(_md, artName, type, ext, url == null ? null + : new URL(url), ExtendableItemHelper.getExtraAttributes(attributes, + new String[] {"ext", "type", "name", "conf"})); + String confs = _ivy.substitute(attributes.getValue("conf")); + // only add confs if they are specified. if they aren't, endElement will + // handle this + // only if there are no conf defined in sub elements + if (confs != null && confs.length() > 0) { + String[] conf; + if ("*".equals(confs)) { + conf = _md.getConfigurationsNames(); + } else { + conf = confs.split(","); + } + for (int i = 0; i < conf.length; i++) { + _artifact.addConfiguration(conf[i].trim()); + _md.addArtifact(conf[i].trim(), _artifact); + } + } + } else if (_state == DEP) { + // this is an artifact asked for a particular dependency + addDependencyArtifacts(qName, attributes); + } else if (_validate) { + addError("artifact tag found in invalid tag: " + _state); + } + } else if ("include".equals(qName) && _state == DEP) { + addIncludeRule(qName, attributes); + } else if ("exclude".equals(qName) && _state == DEP) { + addExcludeRule(qName, attributes); + } else if ("dependency".equals(qName)) { + String org = _ivy.substitute(attributes.getValue("org")); + if (org == null) { + org = _md.getModuleRevisionId().getOrganisation(); + } + boolean force = Boolean.valueOf(_ivy.substitute(attributes.getValue("force"))) + .booleanValue(); + boolean changing = Boolean.valueOf( + _ivy.substitute(attributes.getValue("changing"))).booleanValue(); + + String transitiveValue = _ivy.substitute(attributes.getValue("transitive")); + boolean transitive = (transitiveValue == null) ? true : Boolean.valueOf( + attributes.getValue("transitive")).booleanValue(); + + String name = _ivy.substitute(attributes.getValue("name")); + String branch = _ivy.substitute(attributes.getValue("branch")); + String rev = _ivy.substitute(attributes.getValue("rev")); + _dd = new DefaultDependencyDescriptor(_md, ModuleRevisionId.newInstance(org, + name, branch, rev, ExtendableItemHelper.getExtraAttributes(attributes, + DEPENDENCY_REGULAR_ATTRIBUTES)), force, changing, transitive); + _md.addDependency(_dd); + String confs = _ivy.substitute(attributes.getValue("conf")); + if (confs != null && confs.length() > 0) { + parseDepsConfs(confs, _dd); + } + } else if ("conf".equals(qName)) { + String conf = _ivy.substitute(attributes.getValue("name")); + switch (_state) { + case CONF: + String visibility = _ivy.substitute(attributes.getValue("visibility")); + String ext = _ivy.substitute(attributes.getValue("extends")); + String transitiveValue = attributes.getValue("transitive"); + boolean transitive = (transitiveValue == null) ? true : Boolean + .valueOf(attributes.getValue("transitive")).booleanValue(); + Configuration configuration = new Configuration(conf, + Configuration.Visibility + .getVisibility(visibility == null ? "public" + : visibility), _ivy.substitute(attributes + .getValue("description")), ext == null ? null : ext + .split(","), transitive); + ExtendableItemHelper.fillExtraAttributes(configuration, attributes, + new String[] {"name", "visibility", "extends", "transitive", + "description"}); + _md.addConfiguration(configuration); + break; + case PUB: + if ("*".equals(conf)) { + String[] confs = _md.getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + _artifact.addConfiguration(confs[i]); + _md.addArtifact(confs[i], _artifact); + } + } else { + _artifact.addConfiguration(conf); + _md.addArtifact(conf, _artifact); + } + break; + case DEP: + _conf = conf; + String mappeds = _ivy.substitute(attributes.getValue("mapped")); + if (mappeds != null) { + String[] mapped = mappeds.split(","); + for (int i = 0; i < mapped.length; i++) { + _dd.addDependencyConfiguration(_conf, mapped[i].trim()); + } + } + break; + case DEP_ARTIFACT: + case ARTIFACT_INCLUDE: + case ARTIFACT_EXCLUDE: + addConfiguration(conf); + break; + default: + if (_validate) { + addError("conf tag found in invalid tag: " + _state); + } + break; + } + } else if ("mapped".equals(qName)) { + _dd.addDependencyConfiguration(_conf, _ivy.substitute(attributes + .getValue("name"))); + } else if ("manager".equals(qName) && _state == CONFLICT) { + String org = _ivy.substitute(attributes.getValue("org")); + org = org == null ? PatternMatcher.ANY_EXPRESSION : org; + String mod = _ivy.substitute(attributes.getValue("module")); + mod = mod == null ? PatternMatcher.ANY_EXPRESSION : mod; + ConflictManager cm; + String name = _ivy.substitute(attributes.getValue("name")); + String rev = _ivy.substitute(attributes.getValue("rev")); + if (rev != null) { + String[] revs = rev.split(","); + for (int i = 0; i < revs.length; i++) { + revs[i] = revs[i].trim(); + } + cm = new FixedConflictManager(revs); + } else if (name != null) { + cm = _ivy.getConflictManager(name); + if (cm == null) { + addError("unknown conflict manager: " + name); + return; + } + } else { + addError("bad conflict manager: no name nor rev"); + return; + } + String matcherName = _ivy.substitute(attributes.getValue("matcher")); + PatternMatcher matcher = matcherName == null ? _defaultMatcher : _ivy + .getMatcher(matcherName); + if (matcher == null) { + addError("unknown matcher: " + matcherName); + return; + } + _md.addConflictManager(new ModuleId(org, mod), matcher, cm); + } else if ("rule".equals(qName) && _state == EXCLUDE) { + parseRule(qName, attributes); + _md.addExcludeRule((ExcludeRule) _confAware); + } else if ("include".equals(qName) && _state == CONF) { + URL url; + String fileName = _ivy.substitute(attributes.getValue("file")); + if (fileName == null) { + String urlStr = _ivy.substitute(attributes.getValue("url")); + url = new URL(urlStr); + } else { + url = new File(fileName).toURL(); + } + + // create a new temporary parser to read the configurations from + // the specified file. + Parser parser = new Parser(getModuleDescriptorParser(), _ivy, false); + parser._md = new DefaultModuleDescriptor(getModuleDescriptorParser(), + new URLResource(url)); + XMLHelper.parse(url, null, parser); + + // add the configurations from this temporary parser to this module descriptor + Configuration[] configs = parser.getModuleDescriptor().getConfigurations(); + for (int i = 0; i < configs.length; i++) { + _md.addConfiguration(configs[i]); + } + if (parser.getDefaultConfMapping() != null) { + Message.debug("setting default conf from imported configurations file: " + + parser.getDefaultConfMapping()); + setDefaultConfMapping(parser.getDefaultConfMapping()); + } + if (parser._md.isMappingOverride()) { + Message + .debug("enabling mapping-override from imported configurations file"); + _md.setMappingOverride(true); + } + } else if (_validate && _state != INFO) { + addError("unknwon tag " + qName); + } + } catch (Exception ex) { + if (ex instanceof SAXException) { + throw (SAXException) ex; + } + throw new SAXException("problem occured while parsing ivy file. message: " + + ex.getMessage(), ex); + } + } + + private void addDependencyArtifacts(String tag, Attributes attributes) + throws MalformedURLException { + _state = DEP_ARTIFACT; + parseRule(tag, attributes); + } + + private void addIncludeRule(String tag, Attributes attributes) throws MalformedURLException { + _state = ARTIFACT_INCLUDE; + parseRule(tag, attributes); + } + + private void addExcludeRule(String tag, Attributes attributes) throws MalformedURLException { + _state = ARTIFACT_EXCLUDE; + parseRule(tag, attributes); + } + + private void parseRule(String tag, Attributes attributes) throws MalformedURLException { + String name = _ivy.substitute(attributes.getValue("name")); + if (name == null) { + name = _ivy.substitute(attributes.getValue("artifact")); + if (name == null) { + name = "artifact".equals(tag) ? _dd.getDependencyId().getName() + : PatternMatcher.ANY_EXPRESSION; + } + } + String type = _ivy.substitute(attributes.getValue("type")); + if (type == null) { + type = "artifact".equals(tag) ? "jar" : PatternMatcher.ANY_EXPRESSION; + } + String ext = _ivy.substitute(attributes.getValue("ext")); + ext = ext != null ? ext : type; + if (_state == DEP_ARTIFACT) { + String url = _ivy.substitute(attributes.getValue("url")); + Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] { + "name", "type", "ext", "url", "conf"}); + _confAware = new DefaultDependencyArtifactDescriptor(name, type, ext, + url == null ? null : new URL(url), extraAtt); + } else if (_state == ARTIFACT_INCLUDE) { + PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher")); + String org = _ivy.substitute(attributes.getValue("org")); + org = org == null ? PatternMatcher.ANY_EXPRESSION : org; + String module = _ivy.substitute(attributes.getValue("module")); + module = module == null ? PatternMatcher.ANY_EXPRESSION : module; + ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext); + Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] { + "org", "module", "name", "type", "ext", "matcher", "conf"}); + _confAware = new DefaultIncludeRule(aid, matcher, extraAtt); + } else { // _state == ARTIFACT_EXCLUDE + PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher")); + String org = _ivy.substitute(attributes.getValue("org")); + org = org == null ? PatternMatcher.ANY_EXPRESSION : org; + String module = _ivy.substitute(attributes.getValue("module")); + module = module == null ? PatternMatcher.ANY_EXPRESSION : module; + ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext); + Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] { + "org", "module", "name", "type", "ext", "matcher", "conf"}); + _confAware = new DefaultExcludeRule(aid, matcher, extraAtt); + } + String confs = _ivy.substitute(attributes.getValue("conf")); + // only add confs if they are specified. if they aren't, endElement will handle this + // only if there are no conf defined in sub elements + if (confs != null && confs.length() > 0) { + String[] conf; + if ("*".equals(confs)) { + conf = _md.getConfigurationsNames(); + } else { + conf = confs.split(","); + } + for (int i = 0; i < conf.length; i++) { + addConfiguration(conf[i].trim()); + } + } + } + + private void addConfiguration(String c) { + _confAware.addConfiguration(c); + if (_state == EXCLUDE) { + // we are adding a configuration to a module wide exclude rule + // we have nothing special to do here, the rule has already been added to the module + // descriptor + } else { + // we are currently adding a configuration to either an include, exclude or artifact + // element + // of a dependency. This means that we have to add this element to the corresponding + // conf + // of the current dependency descriptor + if (_confAware instanceof DependencyArtifactDescriptor) { + _dd.addDependencyArtifact(c, (DependencyArtifactDescriptor) _confAware); + } else if (_confAware instanceof IncludeRule) { + _dd.addIncludeRule(c, (IncludeRule) _confAware); + } else if (_confAware instanceof ExcludeRule) { + _dd.addExcludeRule(c, (ExcludeRule) _confAware); + } + } + } + + private PatternMatcher getPatternMatcher(String m) { + String matcherName = _ivy.substitute(m); + PatternMatcher matcher = matcherName == null ? _defaultMatcher : _ivy + .getMatcher(matcherName); + if (matcher == null) { + throw new IllegalArgumentException("unknown matcher " + matcherName); + } + return matcher; + } + + public void endElement(String uri, String localName, String qName) throws SAXException { + if (_state == PUB && "artifact".equals(qName) + && _artifact.getConfigurations().length == 0) { + String[] confs = _md.getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + _artifact.addConfiguration(confs[i]); + _md.addArtifact(confs[i], _artifact); + } + } else if ("configurations".equals(qName)) { + checkConfigurations(); + } else if ((_state == DEP_ARTIFACT && "artifact".equals(qName)) + || (_state == ARTIFACT_INCLUDE && "include".equals(qName)) + || (_state == ARTIFACT_EXCLUDE && "exclude".equals(qName))) { + _state = DEP; + if (_confAware.getConfigurations().length == 0) { + String[] confs = _md.getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + addConfiguration(confs[i]); + } + } + _confAware = null; + } else if (_state == EXCLUDE && "rule".equals(qName)) { + if (_confAware.getConfigurations().length == 0) { + String[] confs = _md.getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + addConfiguration(confs[i]); + } + } + _confAware = null; + } else if ("dependency".equals(qName) && _dd.getModuleConfigurations().length == 0) { + parseDepsConfs(getDefaultConf(), _dd); + } else if ("dependencies".equals(qName)) { + _state = NONE; + } + } + + private void checkConfigurations() { + if (_md.getConfigurations().length == 0) { + _md.addConfiguration(new Configuration("default")); + } + } + + private void replaceConfigurationWildcards() { + Configuration[] configs = _md.getConfigurations(); + for (int i = 0; i < configs.length; i++) { + configs[i].replaceWildcards(_md); + } + } + + } + + public String toString() { + return "ivy parser"; + } +} diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java index d0dcd1d8..c0261071 100644 --- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java +++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java @@ -1,698 +1,698 @@ -/* - * 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.parser.xml; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Stack; -import java.util.StringTokenizer; - -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.XMLHelper; -import org.apache.ivy.util.extendable.ExtendableItemHelper; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.DefaultHandler; - -/** - * Used to update ivy files. Uses ivy file as source and not ModuleDescriptor to preserve as much as - * possible the original syntax - */ -public class XmlModuleDescriptorUpdater { - public static String LINE_SEPARATOR = System.getProperty("line.separator"); - - /** - * used to copy a module descriptor xml file (also known as ivy file) and update the revisions - * of its dependencies, its status and revision - * - * @param srcURL - * the url of the source module descriptor file - * @param destFile - * The file to which the updated module descriptor should be output - * @param resolvedRevisions - * Map from ModuleId of dependencies to new revision (as String) - * @param status - * the new status, null to keep the old one - * @param revision - * the new revision, null to keep the old one - */ - public static void update(URL srcURL, File destFile, final Map resolvedRevisions, - final String status, final String revision, final Date pubdate, String[] confsToExclude) - throws IOException, SAXException { - update(null, srcURL, destFile, resolvedRevisions, status, revision, pubdate, null, false, - confsToExclude); - } - - public static void update(final IvySettings settings, URL srcURL, File destFile, - final Map resolvedRevisions, final String status, final String revision, - final Date pubdate, final Namespace ns, final boolean replaceInclude, - String[] confsToExclude) throws IOException, SAXException { - update(settings, srcURL.openStream(), destFile, resolvedRevisions, status, revision, - pubdate, ns, replaceInclude, confsToExclude); - } - - public static void update(final IvySettings settings, InputStream in, File destFile, - final Map resolvedRevisions, final String status, final String revision, - final Date pubdate, final Namespace ns, final boolean replaceInclude, - String[] confsToExclude) throws IOException, SAXException { - if (destFile.getParentFile() != null) { - destFile.getParentFile().mkdirs(); - } - OutputStream fos = new FileOutputStream(destFile); - try { - update(settings, in, fos, resolvedRevisions, status, revision, pubdate, ns, - replaceInclude, confsToExclude); - } finally { - try { - in.close(); - } catch (IOException e) { - } - try { - fos.close(); - } catch (IOException e) { - } - } - } - - private static class UpdaterHandler extends DefaultHandler implements LexicalHandler { - - private final IvySettings settings; - - private final PrintWriter out; - - private final Map resolvedRevisions; - - private final String status; - - private final String revision; - - private final Date pubdate; - - private final Namespace ns; - - private final boolean replaceInclude; - - private boolean inHeader = true; - - private final List confs; - - public UpdaterHandler(final IvySettings settings, final PrintWriter out, - final Map resolvedRevisions, final String status, final String revision, - final Date pubdate, final Namespace ns, final boolean replaceInclude, - final String[] confs) { - this.settings = settings; - this.out = out; - this.resolvedRevisions = resolvedRevisions; - this.status = status; - this.revision = revision; - this.pubdate = pubdate; - this.ns = ns; - this.replaceInclude = replaceInclude; - if (confs != null) { - this.confs = Arrays.asList(confs); - } else { - this.confs = Collections.EMPTY_LIST; - } - } - - // never print *ln* cause \n is found in copied characters stream - // nor do we need do handle indentation, original one is maintained except for attributes - - private String _organisation = null; - - private String _defaultConfMapping = null; // defaultConfMapping of imported - - // configurations, if any - - private Boolean _confMappingOverride = null; // confMappingOverride of imported - - // configurations, if any - - private String _justOpen = null; // used to know if the last open tag was empty, to - - // adjust termination with /> instead of > - - private Stack _context = new Stack(); - - private Stack _buffers = new Stack(); - - private Stack _confAttributeBuffers = new Stack(); - - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - inHeader = false; - if (_justOpen != null) { - write(">"); - } - _context.push(qName); - if ("info".equals(qName)) { - _organisation = substitute(settings, attributes.getValue("organisation")); - write("\n\t\t"); - } - String extend = attributes.getValue("extends"); - if (extend != null) { - for (StringTokenizer tok = new StringTokenizer(extend, ", "); tok - .hasMoreTokens();) { - String current = tok.nextToken(); - if (confs.contains(current)) { - throw new IllegalArgumentException( - "Cannot exclude a configuration which is extended."); - } - } - - } - - write("<" + qName); - for (int i = 0; i < attributes.getLength(); i++) { - write(" " + attributes.getQName(i) + "=\"" - + substitute(settings, attributes.getValue(i)) - + "\""); - } - _doIndent = true; - } - } - } - - public void endElement(String uri, String localName, String name) - throws SAXException { - if ("configurations".equals(name)) { - _insideConfigurations = false; - } - } - }); - } catch (Exception e) { - Message.warn("exception occured while importing configurations: " - + e.getMessage()); - throw new SAXException(e); - } - } else if ("ivy-module/dependencies/dependency".equals(getContext())) { - ExtendedBuffer buffer = new ExtendedBuffer(getContext()); - _buffers.push(buffer); - _confAttributeBuffers.push(buffer); - buffer.setDefaultPrint(attributes.getValue("conf") == null); - write(" 0) { - String newMapping = removeConfigurationsFromMapping(oldMapping, confs); - if (newMapping.length() > 0) { - write(" conf=\"" + newMapping + "\""); - ((ExtendedBuffer) _buffers.peek()).setPrint(true); - } - } - } else { - write(" " + attName + "=\"" - + substitute(settings, attributes.getValue(attName)) + "\""); - } - } - } else if ("dependencies".equals(qName)) { - // copy - write("<" + qName); - for (int i = 0; i < attributes.getLength(); i++) { - String attName = attributes.getQName(i); - if ("defaultconfmapping".equals(attName)) { - String newMapping = removeConfigurationsFromMapping(attributes - .getValue("defaultconfmapping"), confs); - if (newMapping.length() > 0) { - write(" " + attributes.getQName(i) + "=\"" + newMapping + "\""); - } - } else { - write(" " + attributes.getQName(i) + "=\"" - + substitute(settings, attributes.getValue(i)) + "\""); - } - } - // add default conf mapping if needed - if (_defaultConfMapping != null - && attributes.getValue("defaultconfmapping") == null) { - String newMapping = removeConfigurationsFromMapping(_defaultConfMapping, confs); - if (newMapping.length() > 0) { - write(" defaultconfmapping=\"" + newMapping + "\""); - } - } - // add confmappingoverride if needed - if (_confMappingOverride != null - && attributes.getValue("confmappingoverride") == null) { - write(" confmappingoverride=\"" + _confMappingOverride.toString() + "\""); - } - } else if ("ivy-module/configurations/conf".equals(getContext())) { - _buffers.push(new ExtendedBuffer(getContext())); - String confName = attributes.getValue("name"); - if (!confs.contains(confName)) { - ((ExtendedBuffer) _buffers.peek()).setPrint(true); - String extend = attributes.getValue("extends"); - if (extend != null) { - for (StringTokenizer tok = new StringTokenizer(extend, ", "); tok - .hasMoreTokens();) { - String current = tok.nextToken(); - if (confs.contains(current)) { - throw new IllegalArgumentException( - "Cannot exclude a configuration which is extended."); - } - } - } - - write("<" + qName); - for (int i = 0; i < attributes.getLength(); i++) { - write(" " + attributes.getQName(i) + "=\"" - + substitute(settings, attributes.getValue(i)) + "\""); - } - } - } else if ("ivy-module/publications/artifact/conf".equals(getContext()) - || "ivy-module/dependencies/dependency/conf".equals(getContext()) - || "ivy-module/dependencies/dependency/artifact/conf".equals(getContext())) { - _buffers.push(new ExtendedBuffer(getContext())); - ((ExtendedBuffer) _confAttributeBuffers.peek()).setDefaultPrint(false); - String confName = attributes.getValue("name"); - if (!confs.contains(confName)) { - ((ExtendedBuffer) _confAttributeBuffers.peek()).setPrint(true); - ((ExtendedBuffer) _buffers.peek()).setPrint(true); - write("<" + qName); - for (int i = 0; i < attributes.getLength(); i++) { - write(" " + attributes.getQName(i) + "=\"" - + substitute(settings, attributes.getValue(i)) + "\""); - } - } - } else if ("ivy-module/publications/artifact".equals(getContext()) - || "ivy-module/dependencies/dependency/artifact".equals(getContext())) { - ExtendedBuffer buffer = new ExtendedBuffer(getContext()); - _buffers.push(buffer); - _confAttributeBuffers.push(buffer); - write("<" + qName); - buffer.setDefaultPrint(attributes.getValue("conf") == null); - for (int i = 0; i < attributes.getLength(); i++) { - String attName = attributes.getQName(i); - if ("conf".equals(attName)) { - String confName = attributes.getValue("conf"); - String newConf = removeConfigurationsFromList(confName, confs); - if (newConf.length() > 0) { - write(" " + attributes.getQName(i) + "=\"" + newConf + "\""); - ((ExtendedBuffer) _buffers.peek()).setPrint(true); - } - } else { - write(" " + attributes.getQName(i) + "=\"" - + substitute(settings, attributes.getValue(i)) + "\""); - } - } - } else { - // copy - write("<" + qName); - for (int i = 0; i < attributes.getLength(); i++) { - write(" " + attributes.getQName(i) + "=\"" - + substitute(settings, attributes.getValue(i)) + "\""); - } - } - _justOpen = qName; - // indent.append("\t"); - } - - private void write(String content) { - if (_buffers.isEmpty()) { - out.print(content); - } else { - ExtendedBuffer buffer = (ExtendedBuffer) _buffers.peek(); - buffer.getBuffer().append(content); - } - } - - private String getContext() { - StringBuffer buf = new StringBuffer(); - for (Iterator iter = _context.iterator(); iter.hasNext();) { - String ctx = (String) iter.next(); - buf.append(ctx).append("/"); - } - if (buf.length() > 0) { - buf.setLength(buf.length() - 1); - } - return buf.toString(); - } - - private String substitute(IvySettings ivy, String value) { - return ivy == null ? value : ivy.substitute(value); - } - - private String removeConfigurationsFromMapping(String mapping, List confsToRemove) { - StringBuffer newMapping = new StringBuffer(); - String mappingSep = ""; - for (StringTokenizer tokenizer = new StringTokenizer(mapping, ";"); tokenizer - .hasMoreTokens();) { - String current = tokenizer.nextToken(); - String[] ops = current.split("->"); - String[] lhs = ops[0].split(","); - List confsToWrite = new ArrayList(); - for (int j = 0; j < lhs.length; j++) { - if (!confs.contains(lhs[j].trim())) { - confsToWrite.add(lhs[j]); - } - } - if (!confsToWrite.isEmpty()) { - newMapping.append(mappingSep); - - String sep = ""; - for (Iterator it = confsToWrite.iterator(); it.hasNext();) { - newMapping.append(sep); - newMapping.append(it.next()); - sep = ","; - } - if (ops.length == 2) { - newMapping.append("->"); - newMapping.append(ops[1]); - } - mappingSep = ";"; - } - } - - return newMapping.toString(); - } - - private String removeConfigurationsFromList(String list, List confsToRemove) { - StringBuffer newList = new StringBuffer(); - String listSep = ""; - for (StringTokenizer tokenizer = new StringTokenizer(list, ","); tokenizer - .hasMoreTokens();) { - String current = tokenizer.nextToken(); - if (!confsToRemove.contains(current.trim())) { - newList.append(listSep); - newList.append(current); - listSep = ","; - } - } - - return newList.toString(); - } - - public void characters(char[] ch, int start, int length) throws SAXException { - if (_justOpen != null) { - write(">"); - _justOpen = null; - } - write(String.valueOf(ch, start, length)); - } - - public void endElement(String uri, String localName, String qName) throws SAXException { - if (qName.equals(_justOpen)) { - write("/>"); - } else { - write(""); - } - - if (!_buffers.isEmpty()) { - ExtendedBuffer buffer = (ExtendedBuffer) _buffers.peek(); - if (buffer.getContext().equals(getContext())) { - _buffers.pop(); - if (buffer.isPrint()) { - write(buffer.getBuffer().toString()); - } - } - } - - if (!_confAttributeBuffers.isEmpty()) { - ExtendedBuffer buffer = (ExtendedBuffer) _confAttributeBuffers.peek(); - if (buffer.getContext().equals(getContext())) { - _confAttributeBuffers.pop(); - } - } - - _justOpen = null; - _context.pop(); - } - - public void endDocument() throws SAXException { - out.print(LINE_SEPARATOR); - out.flush(); - out.close(); - } - - public void warning(SAXParseException e) throws SAXException { - throw e; - } - - public void error(SAXParseException e) throws SAXException { - throw e; - } - - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } - - public void endCDATA() throws SAXException { - } - - public void endDTD() throws SAXException { - } - - public void startCDATA() throws SAXException { - } - - public void comment(char[] ch, int start, int length) throws SAXException { - if (!inHeader) { - StringBuffer comment = new StringBuffer(); - comment.append(ch, start, length); - write(""); - } - } - - public void endEntity(String name) throws SAXException { - } - - public void startEntity(String name) throws SAXException { - } - - public void startDTD(String name, String publicId, String systemId) throws SAXException { - } - - } - - public static void update(final IvySettings settings, InputStream inStream, - OutputStream outStream, final Map resolvedRevisions, final String status, - final String revision, final Date pubdate, final Namespace ns, - final boolean replaceInclude) throws IOException, SAXException { - update(settings, inStream, outStream, resolvedRevisions, status, revision, pubdate, ns, - replaceInclude, null); - } - - public static void update(final IvySettings settings, InputStream inStream, - OutputStream outStream, final Map resolvedRevisions, final String status, - final String revision, final Date pubdate, final Namespace ns, - final boolean replaceInclude, String[] confsToExclude) throws IOException, SAXException { - final PrintWriter out = new PrintWriter(new OutputStreamWriter(outStream, "UTF-8")); - final BufferedInputStream in = new BufferedInputStream(inStream); - - in.mark(10000); // assume the header is never larger than 10000 bytes. - copyHeader(in, out); - in.reset(); // reposition the stream at the beginning - - try { - UpdaterHandler updaterHandler = new UpdaterHandler(settings, out, resolvedRevisions, - status, revision, pubdate, ns, replaceInclude, confsToExclude); - XMLHelper.parse(in, null, updaterHandler, updaterHandler); - } catch (ParserConfigurationException e) { - IllegalStateException ise = new IllegalStateException( - "impossible to update Ivy files: parser problem"); - ise.initCause(e); - throw ise; - } - } - - /** - * Copy xml header from src url ivy file to given printwriter In fact, copies everything before - * is also replaced by if it was present. - * - * @param in - * @param out - * @throws IOException - */ - private static void copyHeader(InputStream in, PrintWriter out) throws IOException { - BufferedReader r = new BufferedReader(new InputStreamReader(in)); - String line = r.readLine(); - if (line != null && line.startsWith(""); - line = line.substring(line.indexOf(">") + 1, line.length()); - } - for (; line != null; line = r.readLine()) { - int index = line.indexOf(" instead of > + + private Stack _context = new Stack(); + + private Stack _buffers = new Stack(); + + private Stack _confAttributeBuffers = new Stack(); + + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + inHeader = false; + if (_justOpen != null) { + write(">"); + } + _context.push(qName); + if ("info".equals(qName)) { + _organisation = substitute(settings, attributes.getValue("organisation")); + write("\n\t\t"); + } + String extend = attributes.getValue("extends"); + if (extend != null) { + for (StringTokenizer tok = new StringTokenizer(extend, ", "); tok + .hasMoreTokens();) { + String current = tok.nextToken(); + if (confs.contains(current)) { + throw new IllegalArgumentException( + "Cannot exclude a configuration which is extended."); + } + } + + } + + write("<" + qName); + for (int i = 0; i < attributes.getLength(); i++) { + write(" " + attributes.getQName(i) + "=\"" + + substitute(settings, attributes.getValue(i)) + + "\""); + } + _doIndent = true; + } + } + } + + public void endElement(String uri, String localName, String name) + throws SAXException { + if ("configurations".equals(name)) { + _insideConfigurations = false; + } + } + }); + } catch (Exception e) { + Message.warn("exception occured while importing configurations: " + + e.getMessage()); + throw new SAXException(e); + } + } else if ("ivy-module/dependencies/dependency".equals(getContext())) { + ExtendedBuffer buffer = new ExtendedBuffer(getContext()); + _buffers.push(buffer); + _confAttributeBuffers.push(buffer); + buffer.setDefaultPrint(attributes.getValue("conf") == null); + write(" 0) { + String newMapping = removeConfigurationsFromMapping(oldMapping, confs); + if (newMapping.length() > 0) { + write(" conf=\"" + newMapping + "\""); + ((ExtendedBuffer) _buffers.peek()).setPrint(true); + } + } + } else { + write(" " + attName + "=\"" + + substitute(settings, attributes.getValue(attName)) + "\""); + } + } + } else if ("dependencies".equals(qName)) { + // copy + write("<" + qName); + for (int i = 0; i < attributes.getLength(); i++) { + String attName = attributes.getQName(i); + if ("defaultconfmapping".equals(attName)) { + String newMapping = removeConfigurationsFromMapping(attributes + .getValue("defaultconfmapping"), confs); + if (newMapping.length() > 0) { + write(" " + attributes.getQName(i) + "=\"" + newMapping + "\""); + } + } else { + write(" " + attributes.getQName(i) + "=\"" + + substitute(settings, attributes.getValue(i)) + "\""); + } + } + // add default conf mapping if needed + if (_defaultConfMapping != null + && attributes.getValue("defaultconfmapping") == null) { + String newMapping = removeConfigurationsFromMapping(_defaultConfMapping, confs); + if (newMapping.length() > 0) { + write(" defaultconfmapping=\"" + newMapping + "\""); + } + } + // add confmappingoverride if needed + if (_confMappingOverride != null + && attributes.getValue("confmappingoverride") == null) { + write(" confmappingoverride=\"" + _confMappingOverride.toString() + "\""); + } + } else if ("ivy-module/configurations/conf".equals(getContext())) { + _buffers.push(new ExtendedBuffer(getContext())); + String confName = attributes.getValue("name"); + if (!confs.contains(confName)) { + ((ExtendedBuffer) _buffers.peek()).setPrint(true); + String extend = attributes.getValue("extends"); + if (extend != null) { + for (StringTokenizer tok = new StringTokenizer(extend, ", "); tok + .hasMoreTokens();) { + String current = tok.nextToken(); + if (confs.contains(current)) { + throw new IllegalArgumentException( + "Cannot exclude a configuration which is extended."); + } + } + } + + write("<" + qName); + for (int i = 0; i < attributes.getLength(); i++) { + write(" " + attributes.getQName(i) + "=\"" + + substitute(settings, attributes.getValue(i)) + "\""); + } + } + } else if ("ivy-module/publications/artifact/conf".equals(getContext()) + || "ivy-module/dependencies/dependency/conf".equals(getContext()) + || "ivy-module/dependencies/dependency/artifact/conf".equals(getContext())) { + _buffers.push(new ExtendedBuffer(getContext())); + ((ExtendedBuffer) _confAttributeBuffers.peek()).setDefaultPrint(false); + String confName = attributes.getValue("name"); + if (!confs.contains(confName)) { + ((ExtendedBuffer) _confAttributeBuffers.peek()).setPrint(true); + ((ExtendedBuffer) _buffers.peek()).setPrint(true); + write("<" + qName); + for (int i = 0; i < attributes.getLength(); i++) { + write(" " + attributes.getQName(i) + "=\"" + + substitute(settings, attributes.getValue(i)) + "\""); + } + } + } else if ("ivy-module/publications/artifact".equals(getContext()) + || "ivy-module/dependencies/dependency/artifact".equals(getContext())) { + ExtendedBuffer buffer = new ExtendedBuffer(getContext()); + _buffers.push(buffer); + _confAttributeBuffers.push(buffer); + write("<" + qName); + buffer.setDefaultPrint(attributes.getValue("conf") == null); + for (int i = 0; i < attributes.getLength(); i++) { + String attName = attributes.getQName(i); + if ("conf".equals(attName)) { + String confName = attributes.getValue("conf"); + String newConf = removeConfigurationsFromList(confName, confs); + if (newConf.length() > 0) { + write(" " + attributes.getQName(i) + "=\"" + newConf + "\""); + ((ExtendedBuffer) _buffers.peek()).setPrint(true); + } + } else { + write(" " + attributes.getQName(i) + "=\"" + + substitute(settings, attributes.getValue(i)) + "\""); + } + } + } else { + // copy + write("<" + qName); + for (int i = 0; i < attributes.getLength(); i++) { + write(" " + attributes.getQName(i) + "=\"" + + substitute(settings, attributes.getValue(i)) + "\""); + } + } + _justOpen = qName; + // indent.append("\t"); + } + + private void write(String content) { + if (_buffers.isEmpty()) { + out.print(content); + } else { + ExtendedBuffer buffer = (ExtendedBuffer) _buffers.peek(); + buffer.getBuffer().append(content); + } + } + + private String getContext() { + StringBuffer buf = new StringBuffer(); + for (Iterator iter = _context.iterator(); iter.hasNext();) { + String ctx = (String) iter.next(); + buf.append(ctx).append("/"); + } + if (buf.length() > 0) { + buf.setLength(buf.length() - 1); + } + return buf.toString(); + } + + private String substitute(IvySettings ivy, String value) { + return ivy == null ? value : ivy.substitute(value); + } + + private String removeConfigurationsFromMapping(String mapping, List confsToRemove) { + StringBuffer newMapping = new StringBuffer(); + String mappingSep = ""; + for (StringTokenizer tokenizer = new StringTokenizer(mapping, ";"); tokenizer + .hasMoreTokens();) { + String current = tokenizer.nextToken(); + String[] ops = current.split("->"); + String[] lhs = ops[0].split(","); + List confsToWrite = new ArrayList(); + for (int j = 0; j < lhs.length; j++) { + if (!confs.contains(lhs[j].trim())) { + confsToWrite.add(lhs[j]); + } + } + if (!confsToWrite.isEmpty()) { + newMapping.append(mappingSep); + + String sep = ""; + for (Iterator it = confsToWrite.iterator(); it.hasNext();) { + newMapping.append(sep); + newMapping.append(it.next()); + sep = ","; + } + if (ops.length == 2) { + newMapping.append("->"); + newMapping.append(ops[1]); + } + mappingSep = ";"; + } + } + + return newMapping.toString(); + } + + private String removeConfigurationsFromList(String list, List confsToRemove) { + StringBuffer newList = new StringBuffer(); + String listSep = ""; + for (StringTokenizer tokenizer = new StringTokenizer(list, ","); tokenizer + .hasMoreTokens();) { + String current = tokenizer.nextToken(); + if (!confsToRemove.contains(current.trim())) { + newList.append(listSep); + newList.append(current); + listSep = ","; + } + } + + return newList.toString(); + } + + public void characters(char[] ch, int start, int length) throws SAXException { + if (_justOpen != null) { + write(">"); + _justOpen = null; + } + write(String.valueOf(ch, start, length)); + } + + public void endElement(String uri, String localName, String qName) throws SAXException { + if (qName.equals(_justOpen)) { + write("/>"); + } else { + write(""); + } + + if (!_buffers.isEmpty()) { + ExtendedBuffer buffer = (ExtendedBuffer) _buffers.peek(); + if (buffer.getContext().equals(getContext())) { + _buffers.pop(); + if (buffer.isPrint()) { + write(buffer.getBuffer().toString()); + } + } + } + + if (!_confAttributeBuffers.isEmpty()) { + ExtendedBuffer buffer = (ExtendedBuffer) _confAttributeBuffers.peek(); + if (buffer.getContext().equals(getContext())) { + _confAttributeBuffers.pop(); + } + } + + _justOpen = null; + _context.pop(); + } + + public void endDocument() throws SAXException { + out.print(LINE_SEPARATOR); + out.flush(); + out.close(); + } + + public void warning(SAXParseException e) throws SAXException { + throw e; + } + + public void error(SAXParseException e) throws SAXException { + throw e; + } + + public void fatalError(SAXParseException e) throws SAXException { + throw e; + } + + public void endCDATA() throws SAXException { + } + + public void endDTD() throws SAXException { + } + + public void startCDATA() throws SAXException { + } + + public void comment(char[] ch, int start, int length) throws SAXException { + if (!inHeader) { + StringBuffer comment = new StringBuffer(); + comment.append(ch, start, length); + write(""); + } + } + + public void endEntity(String name) throws SAXException { + } + + public void startEntity(String name) throws SAXException { + } + + public void startDTD(String name, String publicId, String systemId) throws SAXException { + } + + } + + public static void update(final IvySettings settings, InputStream inStream, + OutputStream outStream, final Map resolvedRevisions, final String status, + final String revision, final Date pubdate, final Namespace ns, + final boolean replaceInclude) throws IOException, SAXException { + update(settings, inStream, outStream, resolvedRevisions, status, revision, pubdate, ns, + replaceInclude, null); + } + + public static void update(final IvySettings settings, InputStream inStream, + OutputStream outStream, final Map resolvedRevisions, final String status, + final String revision, final Date pubdate, final Namespace ns, + final boolean replaceInclude, String[] confsToExclude) throws IOException, SAXException { + final PrintWriter out = new PrintWriter(new OutputStreamWriter(outStream, "UTF-8")); + final BufferedInputStream in = new BufferedInputStream(inStream); + + in.mark(10000); // assume the header is never larger than 10000 bytes. + copyHeader(in, out); + in.reset(); // reposition the stream at the beginning + + try { + UpdaterHandler updaterHandler = new UpdaterHandler(settings, out, resolvedRevisions, + status, revision, pubdate, ns, replaceInclude, confsToExclude); + XMLHelper.parse(in, null, updaterHandler, updaterHandler); + } catch (ParserConfigurationException e) { + IllegalStateException ise = new IllegalStateException( + "impossible to update Ivy files: parser problem"); + ise.initCause(e); + throw ise; + } + } + + /** + * Copy xml header from src url ivy file to given printwriter In fact, copies everything before + * is also replaced by if it was present. + * + * @param in + * @param out + * @throws IOException + */ + private static void copyHeader(InputStream in, PrintWriter out) throws IOException { + BufferedReader r = new BufferedReader(new InputStreamReader(in)); + String line = r.readLine(); + if (line != null && line.startsWith(""); + line = line.substring(line.indexOf(">") + 1, line.length()); + } + for (; line != null; line = r.readLine()) { + int index = line.indexOf(""); - if (licenseHeader != null) { - out.print(licenseHeader); - } - out.println(""); - out.println("\t"); - Configuration[] confs = md.getConfigurations(); - if (confs.length > 0) { - out.println("\t"); - for (int i = 0; i < confs.length; i++) { - out.print("\t\t 0) { - out.print(" extends=\""); - for (int j = 0; j < exts.length; j++) { - out.print(exts[j]); - if (j + 1 < exts.length) { - out.print(","); - } - } - out.print("\""); - } - out.println("/>"); - } - out.println("\t"); - } - out.println("\t"); - Artifact[] artifacts = md.getAllArtifacts(); - for (int i = 0; i < artifacts.length; i++) { - out.print("\t\t"); - } - out.println("\t"); - - DependencyDescriptor[] dds = md.getDependencies(); - if (dds.length > 0) { - out.println("\t"); - for (int i = 0; i < dds.length; i++) { - out.print("\t\t"); - for (int k = 0; k < depConfs.length; k++) { - out.print(depConfs[k]); - if (k + 1 < depConfs.length) { - out.print(","); - } - } - if (j + 1 < modConfs.length) { - out.print(";"); - } - } - out.print("\""); - DependencyArtifactDescriptor[] depArtifacts = dds[i] - .getAllDependencyArtifacts(); - if (depArtifacts.length > 0) { - out.println(">"); - for (int j = 0; j < depArtifacts.length; j++) { - out.print("\t\t\t"); - } - } - IncludeRule[] includes = dds[i].getAllIncludeRules(); - if (includes.length > 0) { - if (depArtifacts.length == 0) { - out.println(">"); - } - for (int j = 0; j < includes.length; j++) { - out.print("\t\t\t"); - } - } - ExcludeRule[] excludes = dds[i].getAllExcludeRules(); - if (excludes.length > 0) { - if (includes.length == 0 && depArtifacts.length == 0) { - out.println(">"); - } - for (int j = 0; j < excludes.length; j++) { - out.print("\t\t\t"); - } - } - if (includes.length + excludes.length + depArtifacts.length == 0) { - out.println("/>"); - } else { - out.println("\t\t"); - } - } - out.println("\t"); - } - out.println(""); - } finally { - out.close(); - } - } - - private static String getConfs(ModuleDescriptor md, Artifact artifact) { - StringBuffer ret = new StringBuffer(); - - String[] confs = md.getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - if (Arrays.asList(md.getArtifacts(confs[i])).contains(artifact)) { - ret.append(confs[i]).append(","); - } - } - if (ret.length() > 0) { - ret.setLength(ret.length() - 1); - } - return ret.toString(); - } -} +/* + * 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.parser.xml; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ExcludeRule; +import org.apache.ivy.core.module.descriptor.IncludeRule; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; + +/** + * + */ +public class XmlModuleDescriptorWriter { + public static void write(ModuleDescriptor md, File output) throws IOException { + write(md, null, output); + } + + public static void write(ModuleDescriptor md, String licenseHeader, File output) + throws IOException { + if (output.getParentFile() != null) { + output.getParentFile().mkdirs(); + } + PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), + "UTF-8")); + try { + out.println(""); + if (licenseHeader != null) { + out.print(licenseHeader); + } + out.println(""); + out.println("\t"); + Configuration[] confs = md.getConfigurations(); + if (confs.length > 0) { + out.println("\t"); + for (int i = 0; i < confs.length; i++) { + out.print("\t\t 0) { + out.print(" extends=\""); + for (int j = 0; j < exts.length; j++) { + out.print(exts[j]); + if (j + 1 < exts.length) { + out.print(","); + } + } + out.print("\""); + } + out.println("/>"); + } + out.println("\t"); + } + out.println("\t"); + Artifact[] artifacts = md.getAllArtifacts(); + for (int i = 0; i < artifacts.length; i++) { + out.print("\t\t"); + } + out.println("\t"); + + DependencyDescriptor[] dds = md.getDependencies(); + if (dds.length > 0) { + out.println("\t"); + for (int i = 0; i < dds.length; i++) { + out.print("\t\t"); + for (int k = 0; k < depConfs.length; k++) { + out.print(depConfs[k]); + if (k + 1 < depConfs.length) { + out.print(","); + } + } + if (j + 1 < modConfs.length) { + out.print(";"); + } + } + out.print("\""); + DependencyArtifactDescriptor[] depArtifacts = dds[i] + .getAllDependencyArtifacts(); + if (depArtifacts.length > 0) { + out.println(">"); + for (int j = 0; j < depArtifacts.length; j++) { + out.print("\t\t\t"); + } + } + IncludeRule[] includes = dds[i].getAllIncludeRules(); + if (includes.length > 0) { + if (depArtifacts.length == 0) { + out.println(">"); + } + for (int j = 0; j < includes.length; j++) { + out.print("\t\t\t"); + } + } + ExcludeRule[] excludes = dds[i].getAllExcludeRules(); + if (excludes.length > 0) { + if (includes.length == 0 && depArtifacts.length == 0) { + out.println(">"); + } + for (int j = 0; j < excludes.length; j++) { + out.print("\t\t\t"); + } + } + if (includes.length + excludes.length + depArtifacts.length == 0) { + out.println("/>"); + } else { + out.println("\t\t"); + } + } + out.println("\t"); + } + out.println(""); + } finally { + out.close(); + } + } + + private static String getConfs(ModuleDescriptor md, Artifact artifact) { + StringBuffer ret = new StringBuffer(); + + String[] confs = md.getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + if (Arrays.asList(md.getArtifacts(confs[i])).contains(artifact)) { + ret.append(confs[i]).append(","); + } + } + if (ret.length() > 0) { + ret.setLength(ret.length() - 1); + } + return ret.toString(); + } +} diff --git a/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java b/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java index b77830d2..a59191b8 100644 --- a/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java +++ b/src/java/org/apache/ivy/plugins/report/LogReportOutputter.java @@ -1,189 +1,189 @@ -/* - * 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.report; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.ConfigurationResolveReport; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.util.Message; - -/** - * - */ -public class LogReportOutputter implements ReportOutputter { - - public String getName() { - return CONSOLE; - } - - public void output(ResolveReport report, File destDir) { - IvySettings settings = IvyContext.getContext().getSettings(); - if (settings.logModulesInUse()) { - Message.info("\t:: modules in use:"); - List dependencies = new ArrayList(report.getDependencies()); - Collections.sort(dependencies); - if (dependencies.size() > 0) { - String[] confs = report.getConfigurations(); - for (int i = 0; i < dependencies.size(); i++) { - IvyNode node = (IvyNode) dependencies.get(i); - if (node.isCompletelyEvicted()) { - continue; - } - List nodeConfs = new ArrayList(confs.length); - for (int j = 0; j < confs.length; j++) { - String conf = confs[j]; - if (report.getConfigurationReport(conf).getModuleRevisionIds().contains( - node.getResolvedId())) { - nodeConfs.add(conf); - } - } - Message - .info("\t" + node + " from " - + node.getModuleRevision().getResolver().getName() + " in " - + nodeConfs); - } - } - } - - IvyNode[] evicted = report.getEvictedNodes(); - - if (evicted.length > 0) { - Message.info("\t:: evicted modules:"); - for (int i = 0; i < evicted.length; i++) { - Collection allEvictingNodes = evicted[i].getAllEvictingNodes(); - if (allEvictingNodes == null) { - Message.info("\t" + evicted[i] + " transitively in " - + Arrays.asList(evicted[i].getEvictedConfs())); - } else if (allEvictingNodes.isEmpty()) { - Message.info("\t" + evicted[i] + " by [] (" - + evicted[i].getAllEvictingConflictManagers() + ") in " - + Arrays.asList(evicted[i].getEvictedConfs())); - } else { - Message.info("\t" + evicted[i] + " by " + allEvictingNodes + " in " - + Arrays.asList(evicted[i].getEvictedConfs())); - } - String[] confs = evicted[i].getEvictedConfs(); - for (int j = 0; j < confs.length; j++) { - EvictionData evictedData = evicted[i].getEvictedData(confs[j]); - Message.verbose("\t in " + evictedData.getParent() + " with " - + evictedData.getConflictManager()); - } - } - } - - char[] sep = new char[69]; - Arrays.fill(sep, '-'); - Message.rawinfo("\t" + new String(sep)); - StringBuffer line = new StringBuffer("\t"); - append(line, "", 18); - append(line, "modules", 31); - line.append("|"); - append(line, "artifacts", 15); - line.append("|"); - Message.rawinfo(line.toString()); - - line = new StringBuffer("\t"); - append(line, "conf", 18); - append(line, "number", 7); - append(line, "search", 7); - append(line, "dwnlded", 7); - append(line, "evicted", 7); - line.append("|"); - append(line, "number", 7); - append(line, "dwnlded", 7); - line.append("|"); - Message.rawinfo(line.toString()); - Message.rawinfo("\t" + new String(sep)); - - String[] confs = report.getConfigurations(); - for (int i = 0; i < confs.length; i++) { - output(report.getConfigurationReport(confs[i])); - } - Message.rawinfo("\t" + new String(sep)); - - IvyNode[] unresolved = report.getUnresolvedDependencies(); - if (unresolved.length > 0) { - Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); - Message.warn("\t:: UNRESOLVED DEPENDENCIES ::"); - Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); - } - for (int i = 0; i < unresolved.length; i++) { - Message.warn("\t:: " + unresolved[i] + ": " + unresolved[i].getProblemMessage()); - } - if (unresolved.length > 0) { - Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::\n"); - } - - ArtifactDownloadReport[] errors = report.getFailedArtifactsReports(); - if (errors.length > 0) { - Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); - Message.warn("\t:: FAILED DOWNLOADS ::"); - Message.warn("\t:: ^ see resolution messages for details ^ ::"); - Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); - } - for (int i = 0; i < errors.length; i++) { - Message.warn("\t:: " + errors[i].getArtifact()); - } - if (errors.length > 0) { - Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::\n"); - } - } - - public void output(ConfigurationResolveReport report) { - StringBuffer line = new StringBuffer("\t"); - append(line, report.getConfiguration(), 18); - append(line, String.valueOf(report.getNodesNumber()), 7); - append(line, String.valueOf(report.getSearchedNodes().length), 7); - append(line, String.valueOf(report.getDownloadedNodes().length), 7); - append(line, String.valueOf(report.getEvictedNodes().length), 7); - line.append("|"); - append(line, String.valueOf(report.getArtifactsNumber()), 7); - append(line, String.valueOf(report.getDownloadedArtifactsReports().length), 7); - line.append("|"); - - Message.rawinfo(line.toString()); - } - - private void append(StringBuffer line, Object o, int limit) { - String v = String.valueOf(o); - if (v.length() >= limit) { - v = v.substring(0, limit); - } else { - int missing = limit - v.length(); - int half = missing / 2; - char[] c = new char[limit]; - Arrays.fill(c, ' '); - System.arraycopy(v.toCharArray(), 0, c, missing - half, v.length()); - v = new String(c); - } - line.append("|"); - line.append(v); - } - -} +/* + * 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.report; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.ConfigurationResolveReport; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.util.Message; + +/** + * + */ +public class LogReportOutputter implements ReportOutputter { + + public String getName() { + return CONSOLE; + } + + public void output(ResolveReport report, File destDir) { + IvySettings settings = IvyContext.getContext().getSettings(); + if (settings.logModulesInUse()) { + Message.info("\t:: modules in use:"); + List dependencies = new ArrayList(report.getDependencies()); + Collections.sort(dependencies); + if (dependencies.size() > 0) { + String[] confs = report.getConfigurations(); + for (int i = 0; i < dependencies.size(); i++) { + IvyNode node = (IvyNode) dependencies.get(i); + if (node.isCompletelyEvicted()) { + continue; + } + List nodeConfs = new ArrayList(confs.length); + for (int j = 0; j < confs.length; j++) { + String conf = confs[j]; + if (report.getConfigurationReport(conf).getModuleRevisionIds().contains( + node.getResolvedId())) { + nodeConfs.add(conf); + } + } + Message + .info("\t" + node + " from " + + node.getModuleRevision().getResolver().getName() + " in " + + nodeConfs); + } + } + } + + IvyNode[] evicted = report.getEvictedNodes(); + + if (evicted.length > 0) { + Message.info("\t:: evicted modules:"); + for (int i = 0; i < evicted.length; i++) { + Collection allEvictingNodes = evicted[i].getAllEvictingNodes(); + if (allEvictingNodes == null) { + Message.info("\t" + evicted[i] + " transitively in " + + Arrays.asList(evicted[i].getEvictedConfs())); + } else if (allEvictingNodes.isEmpty()) { + Message.info("\t" + evicted[i] + " by [] (" + + evicted[i].getAllEvictingConflictManagers() + ") in " + + Arrays.asList(evicted[i].getEvictedConfs())); + } else { + Message.info("\t" + evicted[i] + " by " + allEvictingNodes + " in " + + Arrays.asList(evicted[i].getEvictedConfs())); + } + String[] confs = evicted[i].getEvictedConfs(); + for (int j = 0; j < confs.length; j++) { + EvictionData evictedData = evicted[i].getEvictedData(confs[j]); + Message.verbose("\t in " + evictedData.getParent() + " with " + + evictedData.getConflictManager()); + } + } + } + + char[] sep = new char[69]; + Arrays.fill(sep, '-'); + Message.rawinfo("\t" + new String(sep)); + StringBuffer line = new StringBuffer("\t"); + append(line, "", 18); + append(line, "modules", 31); + line.append("|"); + append(line, "artifacts", 15); + line.append("|"); + Message.rawinfo(line.toString()); + + line = new StringBuffer("\t"); + append(line, "conf", 18); + append(line, "number", 7); + append(line, "search", 7); + append(line, "dwnlded", 7); + append(line, "evicted", 7); + line.append("|"); + append(line, "number", 7); + append(line, "dwnlded", 7); + line.append("|"); + Message.rawinfo(line.toString()); + Message.rawinfo("\t" + new String(sep)); + + String[] confs = report.getConfigurations(); + for (int i = 0; i < confs.length; i++) { + output(report.getConfigurationReport(confs[i])); + } + Message.rawinfo("\t" + new String(sep)); + + IvyNode[] unresolved = report.getUnresolvedDependencies(); + if (unresolved.length > 0) { + Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); + Message.warn("\t:: UNRESOLVED DEPENDENCIES ::"); + Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); + } + for (int i = 0; i < unresolved.length; i++) { + Message.warn("\t:: " + unresolved[i] + ": " + unresolved[i].getProblemMessage()); + } + if (unresolved.length > 0) { + Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::\n"); + } + + ArtifactDownloadReport[] errors = report.getFailedArtifactsReports(); + if (errors.length > 0) { + Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); + Message.warn("\t:: FAILED DOWNLOADS ::"); + Message.warn("\t:: ^ see resolution messages for details ^ ::"); + Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::"); + } + for (int i = 0; i < errors.length; i++) { + Message.warn("\t:: " + errors[i].getArtifact()); + } + if (errors.length > 0) { + Message.warn("\t::::::::::::::::::::::::::::::::::::::::::::::\n"); + } + } + + public void output(ConfigurationResolveReport report) { + StringBuffer line = new StringBuffer("\t"); + append(line, report.getConfiguration(), 18); + append(line, String.valueOf(report.getNodesNumber()), 7); + append(line, String.valueOf(report.getSearchedNodes().length), 7); + append(line, String.valueOf(report.getDownloadedNodes().length), 7); + append(line, String.valueOf(report.getEvictedNodes().length), 7); + line.append("|"); + append(line, String.valueOf(report.getArtifactsNumber()), 7); + append(line, String.valueOf(report.getDownloadedArtifactsReports().length), 7); + line.append("|"); + + Message.rawinfo(line.toString()); + } + + private void append(StringBuffer line, Object o, int limit) { + String v = String.valueOf(o); + if (v.length() >= limit) { + v = v.substring(0, limit); + } else { + int missing = limit - v.length(); + int half = missing / 2; + char[] c = new char[limit]; + Arrays.fill(c, ' '); + System.arraycopy(v.toCharArray(), 0, c, missing - half, v.length()); + v = new String(c); + } + line.append("|"); + line.append(v); + } + +} diff --git a/src/java/org/apache/ivy/plugins/report/ReportOutputter.java b/src/java/org/apache/ivy/plugins/report/ReportOutputter.java index 3f5ea21d..15b117da 100644 --- a/src/java/org/apache/ivy/plugins/report/ReportOutputter.java +++ b/src/java/org/apache/ivy/plugins/report/ReportOutputter.java @@ -1,35 +1,35 @@ -/* - * 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.report; - -import java.io.File; - -import org.apache.ivy.core.report.ResolveReport; - -/** - * - */ -public interface ReportOutputter { - public static final String CONSOLE = "console"; - - public static final String XML = "xml"; - - public abstract void output(ResolveReport report, File destDir); - - public abstract String getName(); -} +/* + * 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.report; + +import java.io.File; + +import org.apache.ivy.core.report.ResolveReport; + +/** + * + */ +public interface ReportOutputter { + public static final String CONSOLE = "console"; + + public static final String XML = "xml"; + + public abstract void output(ResolveReport report, File destDir); + + public abstract String getName(); +} diff --git a/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java b/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java index 8f07e28d..c04d6d74 100644 --- a/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java +++ b/src/java/org/apache/ivy/plugins/report/XmlReportOutputter.java @@ -1,272 +1,272 @@ -/* - * 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.report; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.ArtifactOrigin; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.License; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.ConfigurationResolveReport; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.IvyNodeCallers.Caller; -import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.StringUtils; - -/** - * - */ -public class XmlReportOutputter implements ReportOutputter { - - public String getName() { - return XML; - } - - public void output(ResolveReport report, File destDir) { - String[] confs = report.getConfigurations(); - for (int i = 0; i < confs.length; i++) { - output(report.getConfigurationReport(confs[i]), report.getResolveId(), confs, destDir); - } - } - - public void output(ConfigurationResolveReport report, String resolveId, String[] confs, - File destDir) { - try { - destDir.mkdirs(); - CacheManager cacheMgr = new CacheManager(null, destDir); - File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, report - .getConfiguration()); - OutputStream stream = new FileOutputStream(reportFile); - output(report, confs, stream); - stream.close(); - - Message.verbose("\treport for " + report.getModuleDescriptor().getModuleRevisionId() - + " " + report.getConfiguration() + " produced in " + reportFile); - - File reportXsl = new File(destDir, "ivy-report.xsl"); - File reportCss = new File(destDir, "ivy-report.css"); - if (!reportXsl.exists()) { - FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.xsl"), reportXsl, - null); - } - if (!reportCss.exists()) { - FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.css"), reportCss, - null); - } - } catch (IOException ex) { - Message.error("impossible to produce report for " + report.getModuleDescriptor() + ": " - + ex.getMessage()); - } - } - - public void output(ConfigurationResolveReport report, OutputStream stream) { - output(report, new String[] {report.getConfiguration()}, stream); - } - - public void output(ConfigurationResolveReport report, String[] confs, OutputStream stream) { - PrintWriter out = new PrintWriter(stream); - ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId(); - out.println(""); - out.println(""); - out.println(""); - out.println("\t"); - - out.println("\t"); - - // create a list of ModuleRevisionIds indicating the position for each dependency - List dependencies = new ArrayList(report.getModuleRevisionIds()); - - for (Iterator iter = report.getModuleIds().iterator(); iter.hasNext();) { - ModuleId mid = (ModuleId) iter.next(); - out.println("\t\t"); - for (Iterator it2 = report.getNodes(mid).iterator(); it2.hasNext();) { - IvyNode dep = (IvyNode) it2.next(); - ModuleDescriptor md = null; - if (dep.getModuleRevision() != null) { - md = dep.getModuleRevision().getDescriptor(); - } - StringBuffer details = new StringBuffer(); - if (dep.isLoaded()) { - details.append(" status=\"").append(dep.getDescriptor().getStatus()).append( - "\"").append(" pubdate=\"").append( - Ivy.DATE_FORMAT.format(new Date(dep.getPublication()))).append("\"") - .append(" resolver=\"").append( - dep.getModuleRevision().getResolver().getName()).append("\"") - .append(" artresolver=\"").append( - dep.getModuleRevision().getArtifactResolver().getName()).append( - "\""); - } - if (dep.isEvicted(report.getConfiguration())) { - EvictionData ed = dep.getEvictedData(report.getConfiguration()); - if (ed.getConflictManager() != null) { - details.append(" evicted=\"").append(ed.getConflictManager()).append("\""); - } else { - details.append(" evicted=\"transitive\""); - } - } - if (dep.hasProblem()) { - details.append(" error=\"").append(dep.getProblem().getMessage()).append("\""); - } - if (md != null && md.getHomePage() != null) { - details.append(" homepage=\"").append(md.getHomePage()).append("\""); - } - extraAttributes = md != null ? md.getExtraAttributes() : dep.getResolvedId() - .getExtraAttributes(); - for (Iterator iterator = extraAttributes.keySet().iterator(); iterator.hasNext();) { - String attName = (String) iterator.next(); - details.append(" extra-").append(attName).append("=\"").append( - extraAttributes.get(attName)).append("\""); - } - String defaultValue = dep.getDescriptor() != null ? " default=\"" - + dep.getDescriptor().isDefault() + "\"" : ""; - int position = dependencies.indexOf(dep.getResolvedId()); - out.println("\t\t\t"); - if (md != null) { - License[] licenses = md.getLicenses(); - for (int i = 0; i < licenses.length; i++) { - String lurl; - if (licenses[i].getUrl() != null) { - lurl = " url=\"" + licenses[i].getUrl() + "\""; - } else { - lurl = ""; - } - out.println("\t\t\t\t"); - } - } - if (dep.isEvicted(report.getConfiguration())) { - EvictionData ed = dep.getEvictedData(report.getConfiguration()); - Collection selected = ed.getSelected(); - if (selected != null) { - for (Iterator it3 = selected.iterator(); it3.hasNext();) { - IvyNode sel = (IvyNode) it3.next(); - out.println("\t\t\t\t"); - } - } - } - Caller[] callers = dep.getCallers(report.getConfiguration()); - for (int i = 0; i < callers.length; i++) { - StringBuffer callerDetails = new StringBuffer(); - Map callerExtraAttributes = callers[i].getDependencyDescriptor() - .getExtraAttributes(); - for (Iterator iterator = callerExtraAttributes.keySet().iterator(); iterator - .hasNext();) { - String attName = (String) iterator.next(); - callerDetails.append(" extra-").append(attName).append("=\"").append( - callerExtraAttributes.get(attName)).append("\""); - } - - out.println("\t\t\t\t"); - } - ArtifactDownloadReport[] adr = report.getDownloadReports(dep.getResolvedId()); - out.println("\t\t\t\t"); - for (int i = 0; i < adr.length; i++) { - out.print("\t\t\t\t\t"); - out.println("\t\t\t\t\t\t"); - out.println("\t\t\t\t\t"); - } else { - out.println("/>"); - } - } - out.println("\t\t\t\t"); - out.println("\t\t\t"); - } - out.println("\t\t"); - } - out.println("\t"); - out.println(""); - out.flush(); - } - - private String toString(String[] strs) { - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < strs.length; i++) { - buf.append(strs[i]); - if (i + 1 < strs.length) { - buf.append(", "); - } - } - return buf.toString(); - } -} +/* + * 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.report; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.License; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.ConfigurationResolveReport; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.IvyNodeCallers.Caller; +import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.StringUtils; + +/** + * + */ +public class XmlReportOutputter implements ReportOutputter { + + public String getName() { + return XML; + } + + public void output(ResolveReport report, File destDir) { + String[] confs = report.getConfigurations(); + for (int i = 0; i < confs.length; i++) { + output(report.getConfigurationReport(confs[i]), report.getResolveId(), confs, destDir); + } + } + + public void output(ConfigurationResolveReport report, String resolveId, String[] confs, + File destDir) { + try { + destDir.mkdirs(); + CacheManager cacheMgr = new CacheManager(null, destDir); + File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, report + .getConfiguration()); + OutputStream stream = new FileOutputStream(reportFile); + output(report, confs, stream); + stream.close(); + + Message.verbose("\treport for " + report.getModuleDescriptor().getModuleRevisionId() + + " " + report.getConfiguration() + " produced in " + reportFile); + + File reportXsl = new File(destDir, "ivy-report.xsl"); + File reportCss = new File(destDir, "ivy-report.css"); + if (!reportXsl.exists()) { + FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.xsl"), reportXsl, + null); + } + if (!reportCss.exists()) { + FileUtil.copy(XmlReportOutputter.class.getResource("ivy-report.css"), reportCss, + null); + } + } catch (IOException ex) { + Message.error("impossible to produce report for " + report.getModuleDescriptor() + ": " + + ex.getMessage()); + } + } + + public void output(ConfigurationResolveReport report, OutputStream stream) { + output(report, new String[] {report.getConfiguration()}, stream); + } + + public void output(ConfigurationResolveReport report, String[] confs, OutputStream stream) { + PrintWriter out = new PrintWriter(stream); + ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId(); + out.println(""); + out.println(""); + out.println(""); + out.println("\t"); + + out.println("\t"); + + // create a list of ModuleRevisionIds indicating the position for each dependency + List dependencies = new ArrayList(report.getModuleRevisionIds()); + + for (Iterator iter = report.getModuleIds().iterator(); iter.hasNext();) { + ModuleId mid = (ModuleId) iter.next(); + out.println("\t\t"); + for (Iterator it2 = report.getNodes(mid).iterator(); it2.hasNext();) { + IvyNode dep = (IvyNode) it2.next(); + ModuleDescriptor md = null; + if (dep.getModuleRevision() != null) { + md = dep.getModuleRevision().getDescriptor(); + } + StringBuffer details = new StringBuffer(); + if (dep.isLoaded()) { + details.append(" status=\"").append(dep.getDescriptor().getStatus()).append( + "\"").append(" pubdate=\"").append( + Ivy.DATE_FORMAT.format(new Date(dep.getPublication()))).append("\"") + .append(" resolver=\"").append( + dep.getModuleRevision().getResolver().getName()).append("\"") + .append(" artresolver=\"").append( + dep.getModuleRevision().getArtifactResolver().getName()).append( + "\""); + } + if (dep.isEvicted(report.getConfiguration())) { + EvictionData ed = dep.getEvictedData(report.getConfiguration()); + if (ed.getConflictManager() != null) { + details.append(" evicted=\"").append(ed.getConflictManager()).append("\""); + } else { + details.append(" evicted=\"transitive\""); + } + } + if (dep.hasProblem()) { + details.append(" error=\"").append(dep.getProblem().getMessage()).append("\""); + } + if (md != null && md.getHomePage() != null) { + details.append(" homepage=\"").append(md.getHomePage()).append("\""); + } + extraAttributes = md != null ? md.getExtraAttributes() : dep.getResolvedId() + .getExtraAttributes(); + for (Iterator iterator = extraAttributes.keySet().iterator(); iterator.hasNext();) { + String attName = (String) iterator.next(); + details.append(" extra-").append(attName).append("=\"").append( + extraAttributes.get(attName)).append("\""); + } + String defaultValue = dep.getDescriptor() != null ? " default=\"" + + dep.getDescriptor().isDefault() + "\"" : ""; + int position = dependencies.indexOf(dep.getResolvedId()); + out.println("\t\t\t"); + if (md != null) { + License[] licenses = md.getLicenses(); + for (int i = 0; i < licenses.length; i++) { + String lurl; + if (licenses[i].getUrl() != null) { + lurl = " url=\"" + licenses[i].getUrl() + "\""; + } else { + lurl = ""; + } + out.println("\t\t\t\t"); + } + } + if (dep.isEvicted(report.getConfiguration())) { + EvictionData ed = dep.getEvictedData(report.getConfiguration()); + Collection selected = ed.getSelected(); + if (selected != null) { + for (Iterator it3 = selected.iterator(); it3.hasNext();) { + IvyNode sel = (IvyNode) it3.next(); + out.println("\t\t\t\t"); + } + } + } + Caller[] callers = dep.getCallers(report.getConfiguration()); + for (int i = 0; i < callers.length; i++) { + StringBuffer callerDetails = new StringBuffer(); + Map callerExtraAttributes = callers[i].getDependencyDescriptor() + .getExtraAttributes(); + for (Iterator iterator = callerExtraAttributes.keySet().iterator(); iterator + .hasNext();) { + String attName = (String) iterator.next(); + callerDetails.append(" extra-").append(attName).append("=\"").append( + callerExtraAttributes.get(attName)).append("\""); + } + + out.println("\t\t\t\t"); + } + ArtifactDownloadReport[] adr = report.getDownloadReports(dep.getResolvedId()); + out.println("\t\t\t\t"); + for (int i = 0; i < adr.length; i++) { + out.print("\t\t\t\t\t"); + out.println("\t\t\t\t\t\t"); + out.println("\t\t\t\t\t"); + } else { + out.println("/>"); + } + } + out.println("\t\t\t\t"); + out.println("\t\t\t"); + } + out.println("\t\t"); + } + out.println("\t"); + out.println(""); + out.flush(); + } + + private String toString(String[] strs) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < strs.length; i++) { + buf.append(strs[i]); + if (i + 1 < strs.length) { + buf.append(", "); + } + } + return buf.toString(); + } +} diff --git a/src/java/org/apache/ivy/plugins/report/XmlReportParser.java b/src/java/org/apache/ivy/plugins/report/XmlReportParser.java index 36d590e2..6c9ada59 100644 --- a/src/java/org/apache/ivy/plugins/report/XmlReportParser.java +++ b/src/java/org/apache/ivy/plugins/report/XmlReportParser.java @@ -1,239 +1,239 @@ -/* - * 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.report; - -import java.io.File; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.util.extendable.ExtendableItemHelper; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -public class XmlReportParser { - private static class SaxXmlReportParser { - private List _mrids; - - private List _defaultMrids; - - private List _realMrids; - - private List _artifacts; - - private ModuleRevisionId _mRevisionId; - - private File _report; - - SaxXmlReportParser(File report) { - _artifacts = new ArrayList(); - _mrids = new ArrayList(); - _defaultMrids = new ArrayList(); - _realMrids = new ArrayList(); - _report = report; - } - - public void parse() throws Exception { - SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.parse(_report, new DefaultHandler() { - private String _organisation; - - private String _module; - - private String _branch; - - private String _revision; - - private int _position; - - private Date _pubdate; - - private boolean _skip; - - private ModuleRevisionId _mrid; - - private boolean _default; - - private SortedMap _revisionsMap = new TreeMap(); // Use a TreeMap to order by - - // position (position = key) - - private List _revisionArtifacts = null; - - public void startElement(String uri, String localName, String qName, - Attributes attributes) throws SAXException { - if ("module".equals(qName)) { - _organisation = attributes.getValue("organisation"); - _module = attributes.getValue("name"); - } else if ("revision".equals(qName)) { - _revisionArtifacts = new ArrayList(); - _branch = attributes.getValue("branch"); - _revision = attributes.getValue("name"); - _default = Boolean.valueOf(attributes.getValue("default")).booleanValue(); - // retrieve position from file. If no position is found, it may be an old - // report generated with a previous version, - // in which case, we put it at the last position - String pos = attributes.getValue("position"); - _position = pos == null ? getMaxPos() + 1 : Integer.valueOf(pos).intValue(); - if (attributes.getValue("error") != null - || attributes.getValue("evicted") != null) { - _skip = true; - } else { - _revisionsMap.put(new Integer(_position), _revisionArtifacts); - _mrid = ModuleRevisionId.newInstance(_organisation, _module, _branch, - _revision, ExtendableItemHelper.getExtraAttributes(attributes, - "extra-")); - _mrids.add(_mrid); - if (_default) { - _defaultMrids.add(_mrid); - } else { - _realMrids.add(_mrid); - } - try { - _pubdate = Ivy.DATE_FORMAT.parse(attributes.getValue("pubdate")); - _skip = false; - } catch (ParseException e) { - throw new IllegalArgumentException("invalid publication date for " - + _organisation + " " + _module + " " + _revision + ": " - + attributes.getValue("pubdate")); - } - } - } else if ("artifact".equals(qName)) { - if (_skip) { - return; - } - String status = attributes.getValue("status"); - if (status != null && "failed".equals(status)) { - return; - } - String artifactName = attributes.getValue("name"); - String type = attributes.getValue("type"); - String ext = attributes.getValue("ext"); - Artifact artifact = new DefaultArtifact(_mrid, _pubdate, artifactName, - type, ext, ExtendableItemHelper.getExtraAttributes(attributes, - "extra-")); - _revisionArtifacts.add(artifact); - } else if ("info".equals(qName)) { - String organisation = attributes.getValue("organisation"); - String name = attributes.getValue("module"); - String branch = attributes.getValue("branch"); - String revision = attributes.getValue("revision"); - Map extraAttributes = new HashMap(); - for (int i = 0; i < attributes.getLength(); i++) { - String attName = attributes.getQName(i); - if (attName.startsWith("extra-")) { - String extraAttrName = attName.substring(6); - String extraAttrValue = attributes.getValue(i); - extraAttributes.put(extraAttrName, extraAttrValue); - } - } - _mRevisionId = ModuleRevisionId.newInstance(organisation, name, branch, - revision, extraAttributes); - } - } - - public void endElement(String uri, String localName, String qname) - throws SAXException { - if ("dependencies".equals(qname)) { - // add the artifacts in the correct order - for (Iterator it = _revisionsMap.values().iterator(); it.hasNext();) { - List artifacts = (List) it.next(); - _artifacts.addAll(artifacts); - } - } - } - - private int getMaxPos() { - return _revisionsMap.isEmpty() ? -1 : ((Integer) _revisionsMap.keySet() - .toArray()[_revisionsMap.size() - 1]).intValue(); - } - }); - } - - public List getArtifacts() { - return _artifacts; - } - - public List getModuleRevisionIds() { - return _mrids; - } - - public List getRealModuleRevisionIds() { - return _realMrids; - } - - public ModuleRevisionId getResolvedModule() { - return _mRevisionId; - } - } - - private SaxXmlReportParser parser = null; - - public void parse(File report) throws ParseException { - if (!report.exists()) { - throw new IllegalStateException("Report file '" + report.getAbsolutePath() - + "' does not exist."); - } - - parser = new SaxXmlReportParser(report); - try { - parser.parse(); - } catch (Exception e) { - ParseException pe = new ParseException("failed to parse report: " + report + ": " - + e.getMessage(), 0); - pe.initCause(e); - throw pe; - } - } - - public Artifact[] getArtifacts() { - return (Artifact[]) parser.getArtifacts().toArray( - new Artifact[parser.getArtifacts().size()]); - } - - public ModuleRevisionId[] getDependencyRevisionIds() { - return (ModuleRevisionId[]) parser.getModuleRevisionIds().toArray( - new ModuleRevisionId[parser.getModuleRevisionIds().size()]); - } - - public ModuleRevisionId[] getRealDependencyRevisionIds() { - return (ModuleRevisionId[]) parser.getRealModuleRevisionIds().toArray( - new ModuleRevisionId[parser.getRealModuleRevisionIds().size()]); - } - - /** - * Returns the ModuleRevisionId of the resolved module. - */ - public ModuleRevisionId getResolvedModule() { - return parser.getResolvedModule(); - } -} +/* + * 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.report; + +import java.io.File; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.util.extendable.ExtendableItemHelper; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public class XmlReportParser { + private static class SaxXmlReportParser { + private List _mrids; + + private List _defaultMrids; + + private List _realMrids; + + private List _artifacts; + + private ModuleRevisionId _mRevisionId; + + private File _report; + + SaxXmlReportParser(File report) { + _artifacts = new ArrayList(); + _mrids = new ArrayList(); + _defaultMrids = new ArrayList(); + _realMrids = new ArrayList(); + _report = report; + } + + public void parse() throws Exception { + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + saxParser.parse(_report, new DefaultHandler() { + private String _organisation; + + private String _module; + + private String _branch; + + private String _revision; + + private int _position; + + private Date _pubdate; + + private boolean _skip; + + private ModuleRevisionId _mrid; + + private boolean _default; + + private SortedMap _revisionsMap = new TreeMap(); // Use a TreeMap to order by + + // position (position = key) + + private List _revisionArtifacts = null; + + public void startElement(String uri, String localName, String qName, + Attributes attributes) throws SAXException { + if ("module".equals(qName)) { + _organisation = attributes.getValue("organisation"); + _module = attributes.getValue("name"); + } else if ("revision".equals(qName)) { + _revisionArtifacts = new ArrayList(); + _branch = attributes.getValue("branch"); + _revision = attributes.getValue("name"); + _default = Boolean.valueOf(attributes.getValue("default")).booleanValue(); + // retrieve position from file. If no position is found, it may be an old + // report generated with a previous version, + // in which case, we put it at the last position + String pos = attributes.getValue("position"); + _position = pos == null ? getMaxPos() + 1 : Integer.valueOf(pos).intValue(); + if (attributes.getValue("error") != null + || attributes.getValue("evicted") != null) { + _skip = true; + } else { + _revisionsMap.put(new Integer(_position), _revisionArtifacts); + _mrid = ModuleRevisionId.newInstance(_organisation, _module, _branch, + _revision, ExtendableItemHelper.getExtraAttributes(attributes, + "extra-")); + _mrids.add(_mrid); + if (_default) { + _defaultMrids.add(_mrid); + } else { + _realMrids.add(_mrid); + } + try { + _pubdate = Ivy.DATE_FORMAT.parse(attributes.getValue("pubdate")); + _skip = false; + } catch (ParseException e) { + throw new IllegalArgumentException("invalid publication date for " + + _organisation + " " + _module + " " + _revision + ": " + + attributes.getValue("pubdate")); + } + } + } else if ("artifact".equals(qName)) { + if (_skip) { + return; + } + String status = attributes.getValue("status"); + if (status != null && "failed".equals(status)) { + return; + } + String artifactName = attributes.getValue("name"); + String type = attributes.getValue("type"); + String ext = attributes.getValue("ext"); + Artifact artifact = new DefaultArtifact(_mrid, _pubdate, artifactName, + type, ext, ExtendableItemHelper.getExtraAttributes(attributes, + "extra-")); + _revisionArtifacts.add(artifact); + } else if ("info".equals(qName)) { + String organisation = attributes.getValue("organisation"); + String name = attributes.getValue("module"); + String branch = attributes.getValue("branch"); + String revision = attributes.getValue("revision"); + Map extraAttributes = new HashMap(); + for (int i = 0; i < attributes.getLength(); i++) { + String attName = attributes.getQName(i); + if (attName.startsWith("extra-")) { + String extraAttrName = attName.substring(6); + String extraAttrValue = attributes.getValue(i); + extraAttributes.put(extraAttrName, extraAttrValue); + } + } + _mRevisionId = ModuleRevisionId.newInstance(organisation, name, branch, + revision, extraAttributes); + } + } + + public void endElement(String uri, String localName, String qname) + throws SAXException { + if ("dependencies".equals(qname)) { + // add the artifacts in the correct order + for (Iterator it = _revisionsMap.values().iterator(); it.hasNext();) { + List artifacts = (List) it.next(); + _artifacts.addAll(artifacts); + } + } + } + + private int getMaxPos() { + return _revisionsMap.isEmpty() ? -1 : ((Integer) _revisionsMap.keySet() + .toArray()[_revisionsMap.size() - 1]).intValue(); + } + }); + } + + public List getArtifacts() { + return _artifacts; + } + + public List getModuleRevisionIds() { + return _mrids; + } + + public List getRealModuleRevisionIds() { + return _realMrids; + } + + public ModuleRevisionId getResolvedModule() { + return _mRevisionId; + } + } + + private SaxXmlReportParser parser = null; + + public void parse(File report) throws ParseException { + if (!report.exists()) { + throw new IllegalStateException("Report file '" + report.getAbsolutePath() + + "' does not exist."); + } + + parser = new SaxXmlReportParser(report); + try { + parser.parse(); + } catch (Exception e) { + ParseException pe = new ParseException("failed to parse report: " + report + ": " + + e.getMessage(), 0); + pe.initCause(e); + throw pe; + } + } + + public Artifact[] getArtifacts() { + return (Artifact[]) parser.getArtifacts().toArray( + new Artifact[parser.getArtifacts().size()]); + } + + public ModuleRevisionId[] getDependencyRevisionIds() { + return (ModuleRevisionId[]) parser.getModuleRevisionIds().toArray( + new ModuleRevisionId[parser.getModuleRevisionIds().size()]); + } + + public ModuleRevisionId[] getRealDependencyRevisionIds() { + return (ModuleRevisionId[]) parser.getRealModuleRevisionIds().toArray( + new ModuleRevisionId[parser.getRealModuleRevisionIds().size()]); + } + + /** + * Returns the ModuleRevisionId of the resolved module. + */ + public ModuleRevisionId getResolvedModule() { + return parser.getResolvedModule(); + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/AbstractRepository.java b/src/java/org/apache/ivy/plugins/repository/AbstractRepository.java index 2e2789eb..d473d98e 100644 --- a/src/java/org/apache/ivy/plugins/repository/AbstractRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/AbstractRepository.java @@ -1,136 +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.plugins.repository; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - -import javax.swing.event.EventListenerList; - -import org.apache.ivy.core.module.descriptor.Artifact; - -public abstract class AbstractRepository implements Repository { - private EventListenerList _listeners = new EventListenerList(); - - private String _name; - - private TransferEvent _evt; - - public void addTransferListener(TransferListener listener) { - _listeners.add(TransferListener.class, listener); - } - - public void removeTransferListener(TransferListener listener) { - _listeners.remove(TransferListener.class, listener); - } - - public boolean hasTransferListener(TransferListener listener) { - return Arrays.asList(_listeners.getListeners(TransferListener.class)).contains(listener); - } - - protected void fireTransferInitiated(Resource res, int requestType) { - _evt = new TransferEvent(this, res, TransferEvent.TRANSFER_INITIATED, requestType); - fireTransferEvent(_evt); - } - - protected void fireTransferStarted() { - _evt.setEventType(TransferEvent.TRANSFER_STARTED); - fireTransferEvent(_evt); - } - - protected void fireTransferStarted(long totalLength) { - _evt.setEventType(TransferEvent.TRANSFER_STARTED); - _evt.setTotalLength(totalLength); - _evt.setTotalLengthSet(true); - fireTransferEvent(_evt); - } - - protected void fireTransferProgress(long length) { - _evt.setEventType(TransferEvent.TRANSFER_PROGRESS); - _evt.setLength(length); - if (!_evt.isTotalLengthSet()) { - _evt.setTotalLength(_evt.getTotalLength() + length); - } - fireTransferEvent(_evt); - } - - protected void fireTransferCompleted() { - _evt.setEventType(TransferEvent.TRANSFER_COMPLETED); - if (_evt.getTotalLength() > 0 && !_evt.isTotalLengthSet()) { - _evt.setTotalLengthSet(true); - } - fireTransferEvent(_evt); - } - - protected void fireTransferCompleted(long totalLength) { - _evt.setEventType(TransferEvent.TRANSFER_COMPLETED); - _evt.setTotalLength(totalLength); - _evt.setTotalLengthSet(true); - fireTransferEvent(_evt); - } - - protected void fireTransferError() { - _evt.setEventType(TransferEvent.TRANSFER_ERROR); - fireTransferEvent(_evt); - } - - protected void fireTransferError(Exception ex) { - _evt.setEventType(TransferEvent.TRANSFER_ERROR); - _evt.setException(ex); - fireTransferEvent(_evt); - } - - protected void fireTransferEvent(TransferEvent evt) { - Object[] listeners = _listeners.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == TransferListener.class) { - ((TransferListener) listeners[i + 1]).transferProgress(evt); - } - } - } - - public String getFileSeparator() { - return "/"; - } - - public String standardize(String source) { - return source.replace('\\', '/'); - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public String toString() { - return getName(); - } - - public void put(Artifact artifact, File source, String destination, boolean overwrite) - throws IOException { - put(source, destination, overwrite); - } - - protected void put(File source, String destination, boolean overwrite) throws IOException { - throw new UnsupportedOperationException("put in not supported by " + getName()); - } -} +/* + * 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; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +import javax.swing.event.EventListenerList; + +import org.apache.ivy.core.module.descriptor.Artifact; + +public abstract class AbstractRepository implements Repository { + private EventListenerList _listeners = new EventListenerList(); + + private String _name; + + private TransferEvent _evt; + + public void addTransferListener(TransferListener listener) { + _listeners.add(TransferListener.class, listener); + } + + public void removeTransferListener(TransferListener listener) { + _listeners.remove(TransferListener.class, listener); + } + + public boolean hasTransferListener(TransferListener listener) { + return Arrays.asList(_listeners.getListeners(TransferListener.class)).contains(listener); + } + + protected void fireTransferInitiated(Resource res, int requestType) { + _evt = new TransferEvent(this, res, TransferEvent.TRANSFER_INITIATED, requestType); + fireTransferEvent(_evt); + } + + protected void fireTransferStarted() { + _evt.setEventType(TransferEvent.TRANSFER_STARTED); + fireTransferEvent(_evt); + } + + protected void fireTransferStarted(long totalLength) { + _evt.setEventType(TransferEvent.TRANSFER_STARTED); + _evt.setTotalLength(totalLength); + _evt.setTotalLengthSet(true); + fireTransferEvent(_evt); + } + + protected void fireTransferProgress(long length) { + _evt.setEventType(TransferEvent.TRANSFER_PROGRESS); + _evt.setLength(length); + if (!_evt.isTotalLengthSet()) { + _evt.setTotalLength(_evt.getTotalLength() + length); + } + fireTransferEvent(_evt); + } + + protected void fireTransferCompleted() { + _evt.setEventType(TransferEvent.TRANSFER_COMPLETED); + if (_evt.getTotalLength() > 0 && !_evt.isTotalLengthSet()) { + _evt.setTotalLengthSet(true); + } + fireTransferEvent(_evt); + } + + protected void fireTransferCompleted(long totalLength) { + _evt.setEventType(TransferEvent.TRANSFER_COMPLETED); + _evt.setTotalLength(totalLength); + _evt.setTotalLengthSet(true); + fireTransferEvent(_evt); + } + + protected void fireTransferError() { + _evt.setEventType(TransferEvent.TRANSFER_ERROR); + fireTransferEvent(_evt); + } + + protected void fireTransferError(Exception ex) { + _evt.setEventType(TransferEvent.TRANSFER_ERROR); + _evt.setException(ex); + fireTransferEvent(_evt); + } + + protected void fireTransferEvent(TransferEvent evt) { + Object[] listeners = _listeners.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == TransferListener.class) { + ((TransferListener) listeners[i + 1]).transferProgress(evt); + } + } + } + + public String getFileSeparator() { + return "/"; + } + + public String standardize(String source) { + return source.replace('\\', '/'); + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public String toString() { + return getName(); + } + + public void put(Artifact artifact, File source, String destination, boolean overwrite) + throws IOException { + put(source, destination, overwrite); + } + + protected void put(File source, String destination, boolean overwrite) throws IOException { + throw new UnsupportedOperationException("put in not supported by " + getName()); + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/BasicResource.java b/src/java/org/apache/ivy/plugins/repository/BasicResource.java index 102eac8f..738f6c81 100644 --- a/src/java/org/apache/ivy/plugins/repository/BasicResource.java +++ b/src/java/org/apache/ivy/plugins/repository/BasicResource.java @@ -1,76 +1,76 @@ -/* - * 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; - -import java.io.IOException; -import java.io.InputStream; - -public class BasicResource implements Resource { - private boolean _local; - - private String _name; - - private long _lastModified; - - private long _contentLength; - - private boolean _exists; - - public BasicResource(String name, boolean exists, long contentLength, long lastModified, - boolean local) { - _name = name; - _exists = exists; - _contentLength = contentLength; - _lastModified = lastModified; - _local = local; - } - - public Resource clone(String cloneName) { - throw new UnsupportedOperationException("basic resource do not support the clone method"); - } - - public boolean exists() { - return _exists; - } - - public long getContentLength() { - return _contentLength; - } - - public long getLastModified() { - return _lastModified; - } - - public String getName() { - return _name; - } - - public boolean isLocal() { - return _local; - } - - public InputStream openStream() throws IOException { - throw new UnsupportedOperationException( - "basic resource do not support the openStream method"); - } - - public String toString() { - return getName(); - } - -} +/* + * 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; + +import java.io.IOException; +import java.io.InputStream; + +public class BasicResource implements Resource { + private boolean _local; + + private String _name; + + private long _lastModified; + + private long _contentLength; + + private boolean _exists; + + public BasicResource(String name, boolean exists, long contentLength, long lastModified, + boolean local) { + _name = name; + _exists = exists; + _contentLength = contentLength; + _lastModified = lastModified; + _local = local; + } + + public Resource clone(String cloneName) { + throw new UnsupportedOperationException("basic resource do not support the clone method"); + } + + public boolean exists() { + return _exists; + } + + public long getContentLength() { + return _contentLength; + } + + public long getLastModified() { + return _lastModified; + } + + public String getName() { + return _name; + } + + public boolean isLocal() { + return _local; + } + + public InputStream openStream() throws IOException { + throw new UnsupportedOperationException( + "basic resource do not support the openStream method"); + } + + public String toString() { + return getName(); + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/LazyResource.java b/src/java/org/apache/ivy/plugins/repository/LazyResource.java index 781a82f5..d8ed38ef 100644 --- a/src/java/org/apache/ivy/plugins/repository/LazyResource.java +++ b/src/java/org/apache/ivy/plugins/repository/LazyResource.java @@ -1,97 +1,97 @@ -/* - * 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; - -public abstract class LazyResource implements Resource { - private boolean _init = false; - - private boolean _local; - - private String _name; - - private long _lastModified; - - private long _contentLength; - - private boolean _exists; - - public LazyResource(String name) { - _name = name; - } - - protected abstract void init(); - - private void checkInit() { - if (!_init) { - init(); - _init = true; - } - } - - public boolean exists() { - checkInit(); - return _exists; - } - - public long getContentLength() { - checkInit(); - return _contentLength; - } - - public long getLastModified() { - checkInit(); - return _lastModified; - } - - public String getName() { - return _name; - } - - public boolean isLocal() { - checkInit(); - return _local; - } - - public String toString() { - return getName(); - } - - protected void setContentLength(long contentLength) { - _contentLength = contentLength; - } - - protected void setExists(boolean exists) { - _exists = exists; - } - - protected void setLastModified(long lastModified) { - _lastModified = lastModified; - } - - protected void setLocal(boolean local) { - _local = local; - } - - protected void init(Resource r) { - setContentLength(r.getContentLength()); - setLocal(r.isLocal()); - setLastModified(r.getLastModified()); - setExists(r.exists()); - } - -} +/* + * 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; + +public abstract class LazyResource implements Resource { + private boolean _init = false; + + private boolean _local; + + private String _name; + + private long _lastModified; + + private long _contentLength; + + private boolean _exists; + + public LazyResource(String name) { + _name = name; + } + + protected abstract void init(); + + private void checkInit() { + if (!_init) { + init(); + _init = true; + } + } + + public boolean exists() { + checkInit(); + return _exists; + } + + public long getContentLength() { + checkInit(); + return _contentLength; + } + + public long getLastModified() { + checkInit(); + return _lastModified; + } + + public String getName() { + return _name; + } + + public boolean isLocal() { + checkInit(); + return _local; + } + + public String toString() { + return getName(); + } + + protected void setContentLength(long contentLength) { + _contentLength = contentLength; + } + + protected void setExists(boolean exists) { + _exists = exists; + } + + protected void setLastModified(long lastModified) { + _lastModified = lastModified; + } + + protected void setLocal(boolean local) { + _local = local; + } + + protected void init(Resource r) { + setContentLength(r.getContentLength()); + setLocal(r.isLocal()); + setLastModified(r.getLastModified()); + setExists(r.exists()); + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/Repository.java b/src/java/org/apache/ivy/plugins/repository/Repository.java index 2145b563..238d9d1d 100644 --- a/src/java/org/apache/ivy/plugins/repository/Repository.java +++ b/src/java/org/apache/ivy/plugins/repository/Repository.java @@ -1,159 +1,159 @@ -/* - * 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; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.Artifact; - -/** - * Represents a collection of resources available to Ivy. Ivy uses one or more repositories as both - * a source of resources for Ivy enabled build systems and as a distribution center for resources - * generated by Ivy enabled build systems. - *

      - *

      - * A repository supports the following fundamental operations - *

        - *
      • retrieving a resource from the repository.
      • - *
      • transfering a resource to the repository.
      • - *
      • retrieving a listing of resources.
      • - *
      - *

      - *

      Resource Retrieval

      - *

      - *

      - * {@link #get} retrieves a resource specified by a provided identifier creating a new file . - *

      - *

      - *

      resource Publication

      - *

      - *

      - * {@link #put} transfers a file to the repository. - *

      - *

      - *

      resource Listing

      - *

      - *

      - * {@link #list} returns a listing of file like objects belonging to a specified parent directory. - *

      - *

      - */ -public interface Repository { - - /** - * Return the resource associated with a specified identifier. If the resource does not exist, - * it should return a Resource with exists() returning false. An IOException should only be - * thrown when a real IO problem occurs, like the impossibility to connect to a server. - * - * @param source - * A string identifying the resource. - * @return The resource associated with the resource identifier. - * @throws IOException - * On error whle trying to get resource. - */ - Resource getResource(String source) throws IOException; - - /** - * Fetch a resource from the repository. - * - * @param source - * A string identifying the resource to be fetched. - * @param destination - * Where to place the fetched resource. - * @throws IOException - * On retrieval failure. - */ - void get(String source, File destination) throws IOException; - - /** - * Transfer a resource to the repository - * - * @param artifact - * The artifact to be transferred. - * @param source - * The local file to be transferred. - * @param destination - * Where to transfer the resource. - * @param overwrite - * Whether the transfer should overwrite an existing resource. - * @throws IOException - * On publication failure. - */ - void put(Artifact artifact, File source, String destination, boolean overwrite) - throws IOException; - - /** - * Return a listing of resources names - * - * @param parent - * The parent directory from which to generate the listing. - * @return A listing of the parent directory's file content, as a List of String. - * @throws IOException - * On listing failure. - */ - List list(String parent) throws IOException; - - /** - * Add a listener to the repository. - * - * @param listener - * The listener to attach to the repository. - */ - void addTransferListener(TransferListener listener); - - /** - * Remove a listener on the repository - * - * @param listener - * The listener to remove - */ - void removeTransferListener(TransferListener listener); - - /** - * Determine if a given listener is attached to the repository. - * - * @param listener - * The listener being quireied - * @return true if the provided listener is attached to the repository, - * false if not. - */ - boolean hasTransferListener(TransferListener listener); - - /** - * Get the repository's file separator string. - * - * @return The repository's file separator delimiter - */ - String getFileSeparator(); - - /** - * Normalize a string. - * - * @param source - * The string to normalize. - * @return The normalized string. - */ - String standardize(String source); - - /** - * Return the name of the repository - */ - String getName(); -} +/* + * 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; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.Artifact; + +/** + * Represents a collection of resources available to Ivy. Ivy uses one or more repositories as both + * a source of resources for Ivy enabled build systems and as a distribution center for resources + * generated by Ivy enabled build systems. + *

      + *

      + * A repository supports the following fundamental operations + *

        + *
      • retrieving a resource from the repository.
      • + *
      • transfering a resource to the repository.
      • + *
      • retrieving a listing of resources.
      • + *
      + *

      + *

      Resource Retrieval

      + *

      + *

      + * {@link #get} retrieves a resource specified by a provided identifier creating a new file . + *

      + *

      + *

      resource Publication

      + *

      + *

      + * {@link #put} transfers a file to the repository. + *

      + *

      + *

      resource Listing

      + *

      + *

      + * {@link #list} returns a listing of file like objects belonging to a specified parent directory. + *

      + *

      + */ +public interface Repository { + + /** + * Return the resource associated with a specified identifier. If the resource does not exist, + * it should return a Resource with exists() returning false. An IOException should only be + * thrown when a real IO problem occurs, like the impossibility to connect to a server. + * + * @param source + * A string identifying the resource. + * @return The resource associated with the resource identifier. + * @throws IOException + * On error whle trying to get resource. + */ + Resource getResource(String source) throws IOException; + + /** + * Fetch a resource from the repository. + * + * @param source + * A string identifying the resource to be fetched. + * @param destination + * Where to place the fetched resource. + * @throws IOException + * On retrieval failure. + */ + void get(String source, File destination) throws IOException; + + /** + * Transfer a resource to the repository + * + * @param artifact + * The artifact to be transferred. + * @param source + * The local file to be transferred. + * @param destination + * Where to transfer the resource. + * @param overwrite + * Whether the transfer should overwrite an existing resource. + * @throws IOException + * On publication failure. + */ + void put(Artifact artifact, File source, String destination, boolean overwrite) + throws IOException; + + /** + * Return a listing of resources names + * + * @param parent + * The parent directory from which to generate the listing. + * @return A listing of the parent directory's file content, as a List of String. + * @throws IOException + * On listing failure. + */ + List list(String parent) throws IOException; + + /** + * Add a listener to the repository. + * + * @param listener + * The listener to attach to the repository. + */ + void addTransferListener(TransferListener listener); + + /** + * Remove a listener on the repository + * + * @param listener + * The listener to remove + */ + void removeTransferListener(TransferListener listener); + + /** + * Determine if a given listener is attached to the repository. + * + * @param listener + * The listener being quireied + * @return true if the provided listener is attached to the repository, + * false if not. + */ + boolean hasTransferListener(TransferListener listener); + + /** + * Get the repository's file separator string. + * + * @return The repository's file separator delimiter + */ + String getFileSeparator(); + + /** + * Normalize a string. + * + * @param source + * The string to normalize. + * @return The normalized string. + */ + String standardize(String source); + + /** + * Return the name of the repository + */ + String getName(); +} diff --git a/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java b/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java index 601b69f4..cca6b10a 100644 --- a/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java +++ b/src/java/org/apache/ivy/plugins/repository/RepositoryCopyProgressListener.java @@ -1,56 +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. - * - */ -package org.apache.ivy.plugins.repository; - -import org.apache.ivy.util.CopyProgressEvent; -import org.apache.ivy.util.CopyProgressListener; - -public class RepositoryCopyProgressListener implements CopyProgressListener { - private final AbstractRepository _repository; - - public RepositoryCopyProgressListener(AbstractRepository repository) { - _repository = repository; - } - - private Long _totalLength = null; - - public void start(CopyProgressEvent evt) { - if (_totalLength != null) { - _repository.fireTransferStarted(_totalLength.longValue()); - } else { - _repository.fireTransferStarted(); - } - } - - public void progress(CopyProgressEvent evt) { - _repository.fireTransferProgress(evt.getReadBytes()); - } - - public void end(CopyProgressEvent evt) { - _repository.fireTransferProgress(evt.getReadBytes()); - _repository.fireTransferCompleted(); - } - - public Long getTotalLength() { - return _totalLength; - } - - public void setTotalLength(Long totalLength) { - _totalLength = totalLength; - } -} \ No newline at end of file +/* + * 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; + +import org.apache.ivy.util.CopyProgressEvent; +import org.apache.ivy.util.CopyProgressListener; + +public class RepositoryCopyProgressListener implements CopyProgressListener { + private final AbstractRepository _repository; + + public RepositoryCopyProgressListener(AbstractRepository repository) { + _repository = repository; + } + + private Long _totalLength = null; + + public void start(CopyProgressEvent evt) { + if (_totalLength != null) { + _repository.fireTransferStarted(_totalLength.longValue()); + } else { + _repository.fireTransferStarted(); + } + } + + public void progress(CopyProgressEvent evt) { + _repository.fireTransferProgress(evt.getReadBytes()); + } + + public void end(CopyProgressEvent evt) { + _repository.fireTransferProgress(evt.getReadBytes()); + _repository.fireTransferCompleted(); + } + + public Long getTotalLength() { + return _totalLength; + } + + public void setTotalLength(Long totalLength) { + _totalLength = totalLength; + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/Resource.java b/src/java/org/apache/ivy/plugins/repository/Resource.java index d5b16d4c..89deb2be 100644 --- a/src/java/org/apache/ivy/plugins/repository/Resource.java +++ b/src/java/org/apache/ivy/plugins/repository/Resource.java @@ -1,102 +1,102 @@ -/* - * 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; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Represents a resource in an Ivy {@link Repository}. The resource interface allows one to obtain - * the following information about a resource: - *
        - *
      • resource name/identifier in repository syntax
      • - *
      • date the resource was last modified.
      • - *
      • size of the resource in bytes.
      • - *
      • if the resource is available.
      • - *
      - *

      - *

      Implementation Notes

      - * In implementing the interface you need to ensure the following behaviors: - *
        - *
      • All of the methods specified in the interface fail by returning an empty value (false, - * 0, ""). In other words, the specified interface methods should - * not throw RuntimeExceptions.
      • - *
      • Failure conditions should be logged using the {@link org.apache.ivy.util.Message#verbose} - * method.
      • - *
      • Failure of one of the interface's specified methods results in all other interface specified - * methods returning an empty value (false, 0, "").
      • - *
      - *

      - */ - -public interface Resource { - /** - * Get the name of the resource. - * - * @return the repositorie's assigned resource name/identifier. - */ - public String getName(); - - /** - * Get the date the resource was last modified - * - * @return A long value representing the time the file was last modified, - * measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or - * 0L if the file does not exist or if an I/O error occurs. - */ - public long getLastModified(); - - /** - * Get the resource size - * - * @return a long value representing the size of the resource in bytes. - */ - public long getContentLength(); - - /** - * Determine if the resource is available. - *

      - * Note that this method only checks for availability, not for actual existence. - * - * @return boolean value indicating if the resource is available. - */ - public boolean exists(); - - /** - * Is this resource local to this host, i.e. is it on the file system? - * - * @return boolean value indicating if the resource is local. - */ - public boolean isLocal(); - - /** - * Clones this resource with a new resource with a different name - * - * @param cloneName - * the name of the clone - * @return the cloned resource - */ - public Resource clone(String cloneName); - - /** - * Opens a stream on this resource - * - * @return the opened input stream - */ - public InputStream openStream() throws IOException; -} +/* + * 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; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Represents a resource in an Ivy {@link Repository}. The resource interface allows one to obtain + * the following information about a resource: + *
        + *
      • resource name/identifier in repository syntax
      • + *
      • date the resource was last modified.
      • + *
      • size of the resource in bytes.
      • + *
      • if the resource is available.
      • + *
      + *

      + *

      Implementation Notes

      + * In implementing the interface you need to ensure the following behaviors: + *
        + *
      • All of the methods specified in the interface fail by returning an empty value (false, + * 0, ""). In other words, the specified interface methods should + * not throw RuntimeExceptions.
      • + *
      • Failure conditions should be logged using the {@link org.apache.ivy.util.Message#verbose} + * method.
      • + *
      • Failure of one of the interface's specified methods results in all other interface specified + * methods returning an empty value (false, 0, "").
      • + *
      + *

      + */ + +public interface Resource { + /** + * Get the name of the resource. + * + * @return the repositorie's assigned resource name/identifier. + */ + public String getName(); + + /** + * Get the date the resource was last modified + * + * @return A long value representing the time the file was last modified, + * measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or + * 0L if the file does not exist or if an I/O error occurs. + */ + public long getLastModified(); + + /** + * Get the resource size + * + * @return a long value representing the size of the resource in bytes. + */ + public long getContentLength(); + + /** + * Determine if the resource is available. + *

      + * Note that this method only checks for availability, not for actual existence. + * + * @return boolean value indicating if the resource is available. + */ + public boolean exists(); + + /** + * Is this resource local to this host, i.e. is it on the file system? + * + * @return boolean value indicating if the resource is local. + */ + public boolean isLocal(); + + /** + * Clones this resource with a new resource with a different name + * + * @param cloneName + * the name of the clone + * @return the cloned resource + */ + public Resource clone(String cloneName); + + /** + * Opens a stream on this resource + * + * @return the opened input stream + */ + public InputStream openStream() throws IOException; +} diff --git a/src/java/org/apache/ivy/plugins/repository/ResourceHelper.java b/src/java/org/apache/ivy/plugins/repository/ResourceHelper.java index e3c6119b..0f2a7cb0 100644 --- a/src/java/org/apache/ivy/plugins/repository/ResourceHelper.java +++ b/src/java/org/apache/ivy/plugins/repository/ResourceHelper.java @@ -1,45 +1,45 @@ -/* - * 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; - -import java.io.File; -import java.net.MalformedURLException; - -import org.apache.ivy.plugins.repository.file.FileResource; -import org.apache.ivy.plugins.repository.url.URLResource; - -public class ResourceHelper { - public static boolean equals(Resource res, File f) { - if (res == null && f == null) { - return true; - } - if (res == null || f == null) { - return false; - } - if (res instanceof FileResource) { - return new File(res.getName()).equals(f); - } else if (res instanceof URLResource) { - try { - return f.toURL().toExternalForm().equals(res.getName()); - } catch (MalformedURLException e) { - return false; - } - } - return false; - } -} +/* + * 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; + +import java.io.File; +import java.net.MalformedURLException; + +import org.apache.ivy.plugins.repository.file.FileResource; +import org.apache.ivy.plugins.repository.url.URLResource; + +public class ResourceHelper { + public static boolean equals(Resource res, File f) { + if (res == null && f == null) { + return true; + } + if (res == null || f == null) { + return false; + } + if (res instanceof FileResource) { + return new File(res.getName()).equals(f); + } else if (res instanceof URLResource) { + try { + return f.toURL().toExternalForm().equals(res.getName()); + } catch (MalformedURLException e) { + return false; + } + } + return false; + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/TransferEvent.java b/src/java/org/apache/ivy/plugins/repository/TransferEvent.java index 99bb83d0..6d9cda88 100644 --- a/src/java/org/apache/ivy/plugins/repository/TransferEvent.java +++ b/src/java/org/apache/ivy/plugins/repository/TransferEvent.java @@ -1,288 +1,288 @@ -/* - * 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; - -import java.io.File; - -import org.apache.ivy.core.event.IvyEvent; - -/** - * TransferEvent is used to notify TransferListeners about progress in transfer of resources form/to - * the respository This class is LARGELY inspired by org.apache.maven.wagon.events.TransferEvent - * released under the following copyright license: - * - *
      - * 
      - *  Copyright 2001-2005 The Apache Software Foundation.
      - * 
      - *  Licensed 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.
      - *  
      - * 
      - * - * Orginal class written by Michal Maczka. - */ -public class TransferEvent extends IvyEvent { - /** - * A transfer was attempted, but has not yet commenced. - */ - public static final int TRANSFER_INITIATED = 0; - - /** - * A transfer was started. - */ - public final static int TRANSFER_STARTED = 1; - - /** - * A transfer is completed. - */ - public final static int TRANSFER_COMPLETED = 2; - - /** - * A transfer is in progress. - */ - public final static int TRANSFER_PROGRESS = 3; - - /** - * An error occured during transfer - */ - public final static int TRANSFER_ERROR = 4; - - /** - * Indicates GET transfer (from the repository) - */ - public final static int REQUEST_GET = 5; - - /** - * Indicates PUT transfer (to the repository) - */ - public final static int REQUEST_PUT = 6; - - public static final String TRANSFER_INITIATED_NAME = "transfer-initiated"; - - public static final String TRANSFER_STARTED_NAME = "transfer-started"; - - public static final String TRANSFER_PROGRESS_NAME = "transfer-progress"; - - public static final String TRANSFER_COMPLETED_NAME = "transfer-completed"; - - public static final String TRANSFER_ERROR_NAME = "transfer-error"; - - private Resource _resource; - - private int _eventType; - - private int _requestType; - - private Exception _exception; - - private File _localFile; - - private Repository _repository; - - private long _length; - - private long _totalLength; - - private boolean _isTotalLengthSet = false; - - public TransferEvent(final Repository repository, final Resource resource, final int eventType, - final int requestType) { - super(getName(eventType)); - - _repository = repository; - addAttribute("repository", _repository.getName()); - _resource = resource; - addAttribute("resource", _resource.getName()); - - setEventType(eventType); - - setRequestType(requestType); - addAttribute("request-type", requestType == REQUEST_GET ? "get" : "put"); - } - - public TransferEvent(final Repository repository, final Resource resource, - final Exception exception, final int requestType) { - this(repository, resource, TRANSFER_ERROR, requestType); - - _exception = exception; - } - - public TransferEvent(final Repository repository, final Resource resource, long length, - final int requestType) { - this(repository, resource, TRANSFER_PROGRESS, requestType); - - _length = length; - _totalLength = length; - } - - private static String getName(int eventType) { - switch (eventType) { - case TRANSFER_INITIATED: - return TRANSFER_INITIATED_NAME; - case TRANSFER_STARTED: - return TRANSFER_STARTED_NAME; - case TRANSFER_PROGRESS: - return TRANSFER_PROGRESS_NAME; - case TRANSFER_COMPLETED: - return TRANSFER_COMPLETED_NAME; - case TRANSFER_ERROR: - return TRANSFER_ERROR_NAME; - } - return null; - } - - /** - * @return Returns the resource. - */ - public Resource getResource() { - return _resource; - } - - /** - * @return Returns the exception. - */ - public Exception getException() { - return _exception; - } - - /** - * Returns the request type. - * - * @return Returns the request type. The Request type is one of - * TransferEvent.REQUEST_GET or TransferEvent.REQUEST_PUT - */ - public int getRequestType() { - return _requestType; - } - - /** - * Sets the request type - * - * @param requestType - * The requestType to set. The Request type value should be either - * TransferEvent.REQUEST_GET or TransferEvent.REQUEST_PUT. - * @throws IllegalArgumentException when - */ - protected void setRequestType(final int requestType) { - switch (requestType) { - - case REQUEST_PUT: - break; - case REQUEST_GET: - break; - - default: - throw new IllegalArgumentException("Illegal request type: " + requestType); - } - - _requestType = requestType; - } - - /** - * @return Returns the eventType. - */ - public int getEventType() { - return _eventType; - } - - /** - * @param eventType - * The eventType to set. - */ - protected void setEventType(final int eventType) { - switch (eventType) { - - case TRANSFER_INITIATED: - break; - case TRANSFER_STARTED: - break; - case TRANSFER_COMPLETED: - break; - case TRANSFER_PROGRESS: - break; - case TRANSFER_ERROR: - break; - default: - throw new IllegalArgumentException("Illegal event type: " + eventType); - } - - this._eventType = eventType; - } - - /** - * @param _resource - * The resource to set. - */ - protected void setResource(final Resource resource) { - _resource = resource; - } - - /** - * @return Returns the local file. - */ - public File getLocalFile() { - return _localFile; - } - - /** - * @param localFile - * The local file to set. - */ - protected void setLocalFile(File localFile) { - _localFile = localFile; - } - - public long getLength() { - return _length; - } - - protected void setLength(long length) { - _length = length; - } - - public long getTotalLength() { - return _totalLength; - } - - protected void setTotalLength(long totalLength) { - _totalLength = totalLength; - } - - public void setException(Exception exception) { - _exception = exception; - } - - public boolean isTotalLengthSet() { - return _isTotalLengthSet; - } - - public void setTotalLengthSet(boolean isTotalLengthSet) { - _isTotalLengthSet = isTotalLengthSet; - } - -} +/* + * 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; + +import java.io.File; + +import org.apache.ivy.core.event.IvyEvent; + +/** + * TransferEvent is used to notify TransferListeners about progress in transfer of resources form/to + * the respository This class is LARGELY inspired by org.apache.maven.wagon.events.TransferEvent + * released under the following copyright license: + * + *
      + * 
      + *  Copyright 2001-2005 The Apache Software Foundation.
      + * 
      + *  Licensed 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.
      + *  
      + * 
      + * + * Orginal class written by Michal Maczka. + */ +public class TransferEvent extends IvyEvent { + /** + * A transfer was attempted, but has not yet commenced. + */ + public static final int TRANSFER_INITIATED = 0; + + /** + * A transfer was started. + */ + public final static int TRANSFER_STARTED = 1; + + /** + * A transfer is completed. + */ + public final static int TRANSFER_COMPLETED = 2; + + /** + * A transfer is in progress. + */ + public final static int TRANSFER_PROGRESS = 3; + + /** + * An error occured during transfer + */ + public final static int TRANSFER_ERROR = 4; + + /** + * Indicates GET transfer (from the repository) + */ + public final static int REQUEST_GET = 5; + + /** + * Indicates PUT transfer (to the repository) + */ + public final static int REQUEST_PUT = 6; + + public static final String TRANSFER_INITIATED_NAME = "transfer-initiated"; + + public static final String TRANSFER_STARTED_NAME = "transfer-started"; + + public static final String TRANSFER_PROGRESS_NAME = "transfer-progress"; + + public static final String TRANSFER_COMPLETED_NAME = "transfer-completed"; + + public static final String TRANSFER_ERROR_NAME = "transfer-error"; + + private Resource _resource; + + private int _eventType; + + private int _requestType; + + private Exception _exception; + + private File _localFile; + + private Repository _repository; + + private long _length; + + private long _totalLength; + + private boolean _isTotalLengthSet = false; + + public TransferEvent(final Repository repository, final Resource resource, final int eventType, + final int requestType) { + super(getName(eventType)); + + _repository = repository; + addAttribute("repository", _repository.getName()); + _resource = resource; + addAttribute("resource", _resource.getName()); + + setEventType(eventType); + + setRequestType(requestType); + addAttribute("request-type", requestType == REQUEST_GET ? "get" : "put"); + } + + public TransferEvent(final Repository repository, final Resource resource, + final Exception exception, final int requestType) { + this(repository, resource, TRANSFER_ERROR, requestType); + + _exception = exception; + } + + public TransferEvent(final Repository repository, final Resource resource, long length, + final int requestType) { + this(repository, resource, TRANSFER_PROGRESS, requestType); + + _length = length; + _totalLength = length; + } + + private static String getName(int eventType) { + switch (eventType) { + case TRANSFER_INITIATED: + return TRANSFER_INITIATED_NAME; + case TRANSFER_STARTED: + return TRANSFER_STARTED_NAME; + case TRANSFER_PROGRESS: + return TRANSFER_PROGRESS_NAME; + case TRANSFER_COMPLETED: + return TRANSFER_COMPLETED_NAME; + case TRANSFER_ERROR: + return TRANSFER_ERROR_NAME; + } + return null; + } + + /** + * @return Returns the resource. + */ + public Resource getResource() { + return _resource; + } + + /** + * @return Returns the exception. + */ + public Exception getException() { + return _exception; + } + + /** + * Returns the request type. + * + * @return Returns the request type. The Request type is one of + * TransferEvent.REQUEST_GET or TransferEvent.REQUEST_PUT + */ + public int getRequestType() { + return _requestType; + } + + /** + * Sets the request type + * + * @param requestType + * The requestType to set. The Request type value should be either + * TransferEvent.REQUEST_GET or TransferEvent.REQUEST_PUT. + * @throws IllegalArgumentException when + */ + protected void setRequestType(final int requestType) { + switch (requestType) { + + case REQUEST_PUT: + break; + case REQUEST_GET: + break; + + default: + throw new IllegalArgumentException("Illegal request type: " + requestType); + } + + _requestType = requestType; + } + + /** + * @return Returns the eventType. + */ + public int getEventType() { + return _eventType; + } + + /** + * @param eventType + * The eventType to set. + */ + protected void setEventType(final int eventType) { + switch (eventType) { + + case TRANSFER_INITIATED: + break; + case TRANSFER_STARTED: + break; + case TRANSFER_COMPLETED: + break; + case TRANSFER_PROGRESS: + break; + case TRANSFER_ERROR: + break; + default: + throw new IllegalArgumentException("Illegal event type: " + eventType); + } + + this._eventType = eventType; + } + + /** + * @param _resource + * The resource to set. + */ + protected void setResource(final Resource resource) { + _resource = resource; + } + + /** + * @return Returns the local file. + */ + public File getLocalFile() { + return _localFile; + } + + /** + * @param localFile + * The local file to set. + */ + protected void setLocalFile(File localFile) { + _localFile = localFile; + } + + public long getLength() { + return _length; + } + + protected void setLength(long length) { + _length = length; + } + + public long getTotalLength() { + return _totalLength; + } + + protected void setTotalLength(long totalLength) { + _totalLength = totalLength; + } + + public void setException(Exception exception) { + _exception = exception; + } + + public boolean isTotalLengthSet() { + return _isTotalLengthSet; + } + + public void setTotalLengthSet(boolean isTotalLengthSet) { + _isTotalLengthSet = isTotalLengthSet; + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/TransferListener.java b/src/java/org/apache/ivy/plugins/repository/TransferListener.java index 4076b841..b3ccb9e2 100644 --- a/src/java/org/apache/ivy/plugins/repository/TransferListener.java +++ b/src/java/org/apache/ivy/plugins/repository/TransferListener.java @@ -1,27 +1,27 @@ -/* - * 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; - -import java.util.EventListener; - -/** - * Listen to repository transfer - */ -public interface TransferListener extends EventListener { - void transferProgress(TransferEvent evt); -} +/* + * 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; + +import java.util.EventListener; + +/** + * Listen to repository transfer + */ +public interface TransferListener extends EventListener { + void transferProgress(TransferEvent evt); +} diff --git a/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java b/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java index ea6db521..2f0f4f97 100644 --- a/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/file/FileRepository.java @@ -1,113 +1,113 @@ -/* - * 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.file; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -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 FileRepository extends AbstractRepository { - private RepositoryCopyProgressListener _progress = new RepositoryCopyProgressListener(this); - - private File _baseDir; - - private boolean _local = true; - - public FileRepository() { - _baseDir = null; - } - - public FileRepository(File basedir) { - _baseDir = basedir; - } - - public Resource getResource(String source) throws IOException { - return new FileResource(this, getFile(source)); - } - - public void get(String source, File destination) throws IOException { - fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); - copy(getFile(source), destination, true); - } - - public void put(File source, String destination, boolean overwrite) throws IOException { - fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT); - copy(source, getFile(destination), overwrite); - } - - private void copy(File src, File destination, boolean overwrite) throws IOException { - try { - _progress.setTotalLength(new Long(src.length())); - if (!FileUtil.copy(src, destination, _progress, overwrite)) { - if (!overwrite) { - throw new IOException("file copy not done from " + src + " to " + destination - + ": destination probably already exists and overwrite is false"); - } else { - throw new IOException("file copy not done from " + src + " to " + destination); - } - } - } catch (IOException ex) { - fireTransferError(ex); - throw ex; - } catch (RuntimeException ex) { - fireTransferError(ex); - throw ex; - } finally { - _progress.setTotalLength(null); - } - } - - public List list(String parent) throws IOException { - File dir = getFile(parent); - if (dir.exists() && dir.isDirectory()) { - String[] names = dir.list(); - if (names != null) { - List ret = new ArrayList(names.length); - for (int i = 0; i < names.length; i++) { - ret.add(parent + getFileSeparator() + names[i]); - } - return ret; - } - } - return null; - } - - private File getFile(String source) { - if (_baseDir != null) { - return new File(_baseDir, source); - } else { - return new File(source); - } - } - - public boolean isLocal() { - return _local; - } - - public void setLocal(boolean local) { - _local = local; - } - -} +/* + * 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.file; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +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 FileRepository extends AbstractRepository { + private RepositoryCopyProgressListener _progress = new RepositoryCopyProgressListener(this); + + private File _baseDir; + + private boolean _local = true; + + public FileRepository() { + _baseDir = null; + } + + public FileRepository(File basedir) { + _baseDir = basedir; + } + + public Resource getResource(String source) throws IOException { + return new FileResource(this, getFile(source)); + } + + public void get(String source, File destination) throws IOException { + fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); + copy(getFile(source), destination, true); + } + + public void put(File source, String destination, boolean overwrite) throws IOException { + fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT); + copy(source, getFile(destination), overwrite); + } + + private void copy(File src, File destination, boolean overwrite) throws IOException { + try { + _progress.setTotalLength(new Long(src.length())); + if (!FileUtil.copy(src, destination, _progress, overwrite)) { + if (!overwrite) { + throw new IOException("file copy not done from " + src + " to " + destination + + ": destination probably already exists and overwrite is false"); + } else { + throw new IOException("file copy not done from " + src + " to " + destination); + } + } + } catch (IOException ex) { + fireTransferError(ex); + throw ex; + } catch (RuntimeException ex) { + fireTransferError(ex); + throw ex; + } finally { + _progress.setTotalLength(null); + } + } + + public List list(String parent) throws IOException { + File dir = getFile(parent); + if (dir.exists() && dir.isDirectory()) { + String[] names = dir.list(); + if (names != null) { + List ret = new ArrayList(names.length); + for (int i = 0; i < names.length; i++) { + ret.add(parent + getFileSeparator() + names[i]); + } + return ret; + } + } + return null; + } + + private File getFile(String source) { + if (_baseDir != null) { + return new File(_baseDir, source); + } else { + return new File(source); + } + } + + public boolean isLocal() { + return _local; + } + + public void setLocal(boolean local) { + _local = local; + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/file/FileResource.java b/src/java/org/apache/ivy/plugins/repository/file/FileResource.java index fd44e3de..20977e4a 100644 --- a/src/java/org/apache/ivy/plugins/repository/file/FileResource.java +++ b/src/java/org/apache/ivy/plugins/repository/file/FileResource.java @@ -1,76 +1,76 @@ -/* - * 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.file; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.apache.ivy.plugins.repository.Resource; - -public class FileResource implements Resource { - private File _file; - - private FileRepository _repository; - - public FileResource(FileRepository repository, File f) { - _repository = repository; - _file = f; - } - - public String getName() { - return _file.getPath(); - } - - public Resource clone(String cloneName) { - return new FileResource(_repository, new File(cloneName)); - } - - public long getLastModified() { - return _file.lastModified(); - } - - public long getContentLength() { - return _file.length(); - } - - public boolean exists() { - return _file.exists(); - } - - public String toString() { - return getName(); - } - - public File getFile() { - return _file; - } - - public FileRepository getRepository() { - return _repository; - } - - public boolean isLocal() { - return _repository.isLocal(); - } - - public InputStream openStream() throws IOException { - return new FileInputStream(_file); - } -} +/* + * 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.file; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.ivy.plugins.repository.Resource; + +public class FileResource implements Resource { + private File _file; + + private FileRepository _repository; + + public FileResource(FileRepository repository, File f) { + _repository = repository; + _file = f; + } + + public String getName() { + return _file.getPath(); + } + + public Resource clone(String cloneName) { + return new FileResource(_repository, new File(cloneName)); + } + + public long getLastModified() { + return _file.lastModified(); + } + + public long getContentLength() { + return _file.length(); + } + + public boolean exists() { + return _file.exists(); + } + + public String toString() { + return getName(); + } + + public File getFile() { + return _file; + } + + public FileRepository getRepository() { + return _repository; + } + + public boolean isLocal() { + return _repository.isLocal(); + } + + public InputStream openStream() throws IOException { + return new FileInputStream(_file); + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java b/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java index c00f3c77..2b034d71 100644 --- a/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java @@ -1,245 +1,245 @@ -/* - * 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.sftp; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.apache.ivy.plugins.repository.BasicResource; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.repository.TransferEvent; -import org.apache.ivy.plugins.repository.ssh.AbstractSshBasedRepository; -import org.apache.ivy.plugins.repository.ssh.SshCache; -import org.apache.ivy.util.Message; - -import com.jcraft.jsch.ChannelSftp; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import com.jcraft.jsch.SftpATTRS; -import com.jcraft.jsch.SftpException; -import com.jcraft.jsch.SftpProgressMonitor; -import com.jcraft.jsch.ChannelSftp.LsEntry; - -/** - * SFTP Repository, allow to use a repository accessed by sftp protocol. It supports all operations: - * get, put and list. It relies on jsch for sftp handling, and thus is compatible with sftp version - * 0, 1, 2 and 3 - */ -public class SFTPRepository extends AbstractSshBasedRepository { - private final class MyProgressMonitor implements SftpProgressMonitor { - private long _totalLength; - - public void init(int op, String src, String dest, long max) { - _totalLength = max; - fireTransferStarted(max); - } - - public void end() { - fireTransferCompleted(_totalLength); - } - - public boolean count(long count) { - fireTransferProgress(count); - return true; - } - } - - public SFTPRepository() { - } - - public Resource getResource(String source) { - return new SFTPResource(this, source); - } - - /** - * This method is similar to getResource, except that the returned resource is fully initialised - * (resolved in the sftp repository), and that the given string is a full remote path - * - * @param path - * the full remote path in the repository of the resource - * @return a fully initialised resource, able to answer to all its methods without needing any - * further connection - */ - public Resource resolveResource(String path) { - try { - ChannelSftp c = getSftpChannel(path); - Collection r = c.ls(path); - if (r != null) { - for (Iterator iter = r.iterator(); iter.hasNext();) { - Object obj = iter.next(); - if (obj instanceof LsEntry) { - LsEntry entry = (LsEntry) obj; - SftpATTRS attrs = entry.getAttrs(); - return new BasicResource(path, true, attrs.getSize(), - attrs.getMTime() * 1000, false); - } - } - } - } catch (Exception e) { - Message.debug("reolving resource error: " + e.getMessage()); - // silent fail, return unexisting resource - } - return new BasicResource(path, false, 0, 0, false); - } - - public InputStream openStream(SFTPResource resource) throws IOException { - ChannelSftp c = getSftpChannel(resource.getName()); - try { - return c.get(resource.getName()); - } catch (SftpException e) { - e.printStackTrace(); - IOException ex = new IOException("impossible to open stream for " + resource + " on " - + getHost() + (e.getMessage() != null ? ": " + e.getMessage() : "")); - ex.initCause(e); - throw ex; - } - } - - public void get(String source, File destination) throws IOException { - fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); - ChannelSftp c = getSftpChannel(source); - try { - c.get(source, destination.getAbsolutePath(), new MyProgressMonitor()); - } catch (SftpException e) { - e.printStackTrace(); - IOException ex = new IOException("impossible to get " + source + " on " + getHost() - + (e.getMessage() != null ? ": " + e.getMessage() : "")); - ex.initCause(e); - throw ex; - } - } - - public void put(File source, String destination, boolean overwrite) throws IOException { - fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT); - ChannelSftp c = getSftpChannel(destination); - try { - if (!overwrite && checkExistence(destination, c)) - throw new IOException("destination file exists and overwrite == true"); - if (destination.indexOf('/') != -1) { - mkdirs(destination.substring(0, destination.lastIndexOf('/')), c); - } - c.put(source.getAbsolutePath(), destination, new MyProgressMonitor()); - } catch (SftpException e) { - IOException ex = new IOException(e.getMessage()); - ex.initCause(e); - throw ex; - } - } - - private void mkdirs(String directory, ChannelSftp c) throws IOException, SftpException { - try { - SftpATTRS att = c.stat(directory); - if (att != null) { - if (att.isDir()) { - return; - } - } - } catch (SftpException ex) { - if (directory.indexOf('/') != -1) { - mkdirs(directory.substring(0, directory.lastIndexOf('/')), c); - } - c.mkdir(directory); - } - } - - public List list(String parent) throws IOException { - try { - ChannelSftp c = getSftpChannel(parent); - Collection r = c.ls(parent); - if (r != null) { - if (!parent.endsWith("/")) { - parent = parent + "/"; - } - List result = new ArrayList(); - for (Iterator iter = r.iterator(); iter.hasNext();) { - Object obj = iter.next(); - if (obj instanceof LsEntry) { - LsEntry entry = (LsEntry) obj; - if (".".equals(entry.getFilename()) || "..".equals(entry.getFilename())) { - continue; - } - result.add(parent + entry.getFilename()); - } - } - return result; - } - } catch (Exception e) { - // silent fail, return null listing - } - return null; - } - - /** - * Checks the existence for a remote file - * - * @param file - * to check - * @param channel - * to use - * @returns true if file exists, false otherwise - * @throws IOException - * @throws SftpException - */ - private boolean checkExistence(String file, ChannelSftp channel) throws IOException, - SftpException { - try { - return channel.stat(file) != null; - } catch (SftpException ex) { - return false; - } - } - - /** - * Establish the connection to the server if not yet connected, and listen to ivy events for - * closing connection when resolve is finished. Not meant to be used in multi threaded - * environment. - * - * @return the ChannelSftp with which a connection is established - * @throws IOException - * if any connection problem occurs - */ - private ChannelSftp getSftpChannel(String pathOrUri) throws IOException { - Session session = getSession(pathOrUri); - String host = session.getHost(); - ChannelSftp channel = SshCache.getInstance().getChannelSftp(session); - if (channel == null) { - try { - channel = (ChannelSftp) session.openChannel("sftp"); - channel.connect(); - Message.verbose(":: SFTP :: connected to " + host + "!"); - SshCache.getInstance().attachChannelSftp(session, channel); - } catch (JSchException e) { - IOException ex = new IOException(e.getMessage()); - ex.initCause(e); - throw ex; - } - } - return channel; - } - - protected String getRepositoryScheme() { - // use the Resolver type name here? - // would be nice if it would be static, so we could use SFTPResolver.getTypeName() - return "sftp"; - } -} +/* + * 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.sftp; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.ivy.plugins.repository.BasicResource; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.TransferEvent; +import org.apache.ivy.plugins.repository.ssh.AbstractSshBasedRepository; +import org.apache.ivy.plugins.repository.ssh.SshCache; +import org.apache.ivy.util.Message; + +import com.jcraft.jsch.ChannelSftp; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; +import com.jcraft.jsch.SftpATTRS; +import com.jcraft.jsch.SftpException; +import com.jcraft.jsch.SftpProgressMonitor; +import com.jcraft.jsch.ChannelSftp.LsEntry; + +/** + * SFTP Repository, allow to use a repository accessed by sftp protocol. It supports all operations: + * get, put and list. It relies on jsch for sftp handling, and thus is compatible with sftp version + * 0, 1, 2 and 3 + */ +public class SFTPRepository extends AbstractSshBasedRepository { + private final class MyProgressMonitor implements SftpProgressMonitor { + private long _totalLength; + + public void init(int op, String src, String dest, long max) { + _totalLength = max; + fireTransferStarted(max); + } + + public void end() { + fireTransferCompleted(_totalLength); + } + + public boolean count(long count) { + fireTransferProgress(count); + return true; + } + } + + public SFTPRepository() { + } + + public Resource getResource(String source) { + return new SFTPResource(this, source); + } + + /** + * This method is similar to getResource, except that the returned resource is fully initialised + * (resolved in the sftp repository), and that the given string is a full remote path + * + * @param path + * the full remote path in the repository of the resource + * @return a fully initialised resource, able to answer to all its methods without needing any + * further connection + */ + public Resource resolveResource(String path) { + try { + ChannelSftp c = getSftpChannel(path); + Collection r = c.ls(path); + if (r != null) { + for (Iterator iter = r.iterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof LsEntry) { + LsEntry entry = (LsEntry) obj; + SftpATTRS attrs = entry.getAttrs(); + return new BasicResource(path, true, attrs.getSize(), + attrs.getMTime() * 1000, false); + } + } + } + } catch (Exception e) { + Message.debug("reolving resource error: " + e.getMessage()); + // silent fail, return unexisting resource + } + return new BasicResource(path, false, 0, 0, false); + } + + public InputStream openStream(SFTPResource resource) throws IOException { + ChannelSftp c = getSftpChannel(resource.getName()); + try { + return c.get(resource.getName()); + } catch (SftpException e) { + e.printStackTrace(); + IOException ex = new IOException("impossible to open stream for " + resource + " on " + + getHost() + (e.getMessage() != null ? ": " + e.getMessage() : "")); + ex.initCause(e); + throw ex; + } + } + + public void get(String source, File destination) throws IOException { + fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); + ChannelSftp c = getSftpChannel(source); + try { + c.get(source, destination.getAbsolutePath(), new MyProgressMonitor()); + } catch (SftpException e) { + e.printStackTrace(); + IOException ex = new IOException("impossible to get " + source + " on " + getHost() + + (e.getMessage() != null ? ": " + e.getMessage() : "")); + ex.initCause(e); + throw ex; + } + } + + public void put(File source, String destination, boolean overwrite) throws IOException { + fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT); + ChannelSftp c = getSftpChannel(destination); + try { + if (!overwrite && checkExistence(destination, c)) + throw new IOException("destination file exists and overwrite == true"); + if (destination.indexOf('/') != -1) { + mkdirs(destination.substring(0, destination.lastIndexOf('/')), c); + } + c.put(source.getAbsolutePath(), destination, new MyProgressMonitor()); + } catch (SftpException e) { + IOException ex = new IOException(e.getMessage()); + ex.initCause(e); + throw ex; + } + } + + private void mkdirs(String directory, ChannelSftp c) throws IOException, SftpException { + try { + SftpATTRS att = c.stat(directory); + if (att != null) { + if (att.isDir()) { + return; + } + } + } catch (SftpException ex) { + if (directory.indexOf('/') != -1) { + mkdirs(directory.substring(0, directory.lastIndexOf('/')), c); + } + c.mkdir(directory); + } + } + + public List list(String parent) throws IOException { + try { + ChannelSftp c = getSftpChannel(parent); + Collection r = c.ls(parent); + if (r != null) { + if (!parent.endsWith("/")) { + parent = parent + "/"; + } + List result = new ArrayList(); + for (Iterator iter = r.iterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof LsEntry) { + LsEntry entry = (LsEntry) obj; + if (".".equals(entry.getFilename()) || "..".equals(entry.getFilename())) { + continue; + } + result.add(parent + entry.getFilename()); + } + } + return result; + } + } catch (Exception e) { + // silent fail, return null listing + } + return null; + } + + /** + * Checks the existence for a remote file + * + * @param file + * to check + * @param channel + * to use + * @returns true if file exists, false otherwise + * @throws IOException + * @throws SftpException + */ + private boolean checkExistence(String file, ChannelSftp channel) throws IOException, + SftpException { + try { + return channel.stat(file) != null; + } catch (SftpException ex) { + return false; + } + } + + /** + * Establish the connection to the server if not yet connected, and listen to ivy events for + * closing connection when resolve is finished. Not meant to be used in multi threaded + * environment. + * + * @return the ChannelSftp with which a connection is established + * @throws IOException + * if any connection problem occurs + */ + private ChannelSftp getSftpChannel(String pathOrUri) throws IOException { + Session session = getSession(pathOrUri); + String host = session.getHost(); + ChannelSftp channel = SshCache.getInstance().getChannelSftp(session); + if (channel == null) { + try { + channel = (ChannelSftp) session.openChannel("sftp"); + channel.connect(); + Message.verbose(":: SFTP :: connected to " + host + "!"); + SshCache.getInstance().attachChannelSftp(session, channel); + } catch (JSchException e) { + IOException ex = new IOException(e.getMessage()); + ex.initCause(e); + throw ex; + } + } + return channel; + } + + protected String getRepositoryScheme() { + // use the Resolver type name here? + // would be nice if it would be static, so we could use SFTPResolver.getTypeName() + return "sftp"; + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java b/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java index 182ae1c5..9ec149f6 100644 --- a/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java +++ b/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java @@ -1,87 +1,87 @@ -/* - * 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.sftp; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.ivy.plugins.repository.Resource; - -public class SFTPResource implements Resource { - private SFTPRepository _repository; - - private String _path; - - private transient boolean _init = false; - - private transient boolean _exists; - - private transient long _lastModified; - - private transient long _contentLength; - - public SFTPResource(SFTPRepository repository, String path) { - _repository = repository; - _path = path; - } - - public String getName() { - return _path; - } - - public Resource clone(String cloneName) { - return new SFTPResource(_repository, cloneName); - } - - public long getLastModified() { - init(); - return _lastModified; - } - - public long getContentLength() { - init(); - return _contentLength; - } - - public boolean exists() { - init(); - return _exists; - } - - private void init() { - if (!_init) { - Resource r = _repository.resolveResource(_path); - _contentLength = r.getContentLength(); - _lastModified = r.getLastModified(); - _exists = r.exists(); - _init = true; - } - } - - public String toString() { - return getName(); - } - - public boolean isLocal() { - return false; - } - - public InputStream openStream() throws IOException { - return _repository.openStream(this); - } -} +/* + * 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.sftp; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.ivy.plugins.repository.Resource; + +public class SFTPResource implements Resource { + private SFTPRepository _repository; + + private String _path; + + private transient boolean _init = false; + + private transient boolean _exists; + + private transient long _lastModified; + + private transient long _contentLength; + + public SFTPResource(SFTPRepository repository, String path) { + _repository = repository; + _path = path; + } + + public String getName() { + return _path; + } + + public Resource clone(String cloneName) { + return new SFTPResource(_repository, cloneName); + } + + public long getLastModified() { + init(); + return _lastModified; + } + + public long getContentLength() { + init(); + return _contentLength; + } + + public boolean exists() { + init(); + return _exists; + } + + private void init() { + if (!_init) { + Resource r = _repository.resolveResource(_path); + _contentLength = r.getContentLength(); + _lastModified = r.getLastModified(); + _exists = r.exists(); + _init = true; + } + } + + public String toString() { + return getName(); + } + + public boolean isLocal() { + return false; + } + + public InputStream openStream() throws IOException { + return _repository.openStream(this); + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java b/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java index 544e7393..da0e0012 100644 --- a/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java @@ -242,4 +242,4 @@ public abstract class AbstractSshBasedRepository extends AbstractRepository { protected abstract String getRepositoryScheme(); -} \ No newline at end of file +} diff --git a/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java b/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java index 42d217c7..ae910518 100644 --- a/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java +++ b/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java @@ -1,664 +1,664 @@ -/* - * 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.ssh; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.jcraft.jsch.Channel; -import com.jcraft.jsch.ChannelExec; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; - -/** - * This class is using the scp client to transfer data and information for the repository. It is - * based on the SCPClient from the ganymed ssh library from Christian Plattner. To minimize the - * dependency to the ssh library and because I needed some additional functionality, I decided to - * copy'n'paste the single class rather than to inherit or delegate it somehow. Nevertheless credit - * should go to the original author. - */ - -public class Scp { - Session session; - - public class FileInfo { - private String filename; - - private long length; - - private long lastModified; - - /** - * @param filename - * The filename to set. - */ - public void setFilename(String filename) { - this.filename = filename; - } - - /** - * @return Returns the filename. - */ - public String getFilename() { - return filename; - } - - /** - * @param length - * The length to set. - */ - public void setLength(long length) { - this.length = length; - } - - /** - * @return Returns the length. - */ - public long getLength() { - return length; - } - - /** - * @param lastModified - * The lastModified to set. - */ - public void setLastModified(long lastModified) { - this.lastModified = lastModified; - } - - /** - * @return Returns the lastModified. - */ - public long getLastModified() { - return lastModified; - } - } - - public Scp(Session session) { - if (session == null) - throw new IllegalArgumentException("Cannot accept null argument!"); - this.session = session; - } - - private void readResponse(InputStream is) throws IOException, RemoteScpException { - int c = is.read(); - - if (c == 0) - return; - - if (c == -1) - throw new RemoteScpException("Remote scp terminated unexpectedly."); - - if ((c != 1) && (c != 2)) - throw new RemoteScpException("Remote scp sent illegal error code."); - - if (c == 2) - throw new RemoteScpException("Remote scp terminated with error."); - - String err = receiveLine(is); - throw new RemoteScpException("Remote scp terminated with error (" + err + ")."); - } - - private String receiveLine(InputStream is) throws IOException, RemoteScpException { - StringBuffer sb = new StringBuffer(30); - - while (true) { - /* - * This is a random limit - if your path names are longer, then adjust it - */ - - if (sb.length() > 8192) - throw new RemoteScpException("Remote scp sent a too long line"); - - int c = is.read(); - - if (c < 0) - throw new RemoteScpException("Remote scp terminated unexpectedly."); - - if (c == '\n') - break; - - sb.append((char) c); - - } - return sb.toString(); - } - - private void parseCLine(String line, FileInfo fileInfo) throws RemoteScpException { - /* Minimum line: "xxxx y z" ---> 8 chars */ - - long len; - - if (line.length() < 8) - throw new RemoteScpException( - "Malformed C line sent by remote SCP binary, line too short."); - - if ((line.charAt(4) != ' ') || (line.charAt(5) == ' ')) - throw new RemoteScpException("Malformed C line sent by remote SCP binary."); - - int length_name_sep = line.indexOf(' ', 5); - - if (length_name_sep == -1) - throw new RemoteScpException("Malformed C line sent by remote SCP binary."); - - String length_substring = line.substring(5, length_name_sep); - String name_substring = line.substring(length_name_sep + 1); - - if ((length_substring.length() <= 0) || (name_substring.length() <= 0)) - throw new RemoteScpException("Malformed C line sent by remote SCP binary."); - - if ((6 + length_substring.length() + name_substring.length()) != line.length()) - throw new RemoteScpException("Malformed C line sent by remote SCP binary."); - - try { - len = Long.parseLong(length_substring); - } catch (NumberFormatException e) { - throw new RemoteScpException( - "Malformed C line sent by remote SCP binary, cannot parse file length."); - } - - if (len < 0) - throw new RemoteScpException( - "Malformed C line sent by remote SCP binary, illegal file length."); - - fileInfo.setLength(len); - fileInfo.setFilename(name_substring); - } - - private void parseTLine(String line, FileInfo fileInfo) throws RemoteScpException { - /* Minimum line: "0 0 0 0" ---> 8 chars */ - - long modtime; - long first_msec; - long atime; - long second_msec; - - if (line.length() < 8) - throw new RemoteScpException( - "Malformed T line sent by remote SCP binary, line too short."); - - int first_msec_begin = line.indexOf(" ") + 1; - if (first_msec_begin == 0 || first_msec_begin >= line.length()) - throw new RemoteScpException( - "Malformed T line sent by remote SCP binary, line not enough data."); - - int atime_begin = line.indexOf(" ", first_msec_begin + 1) + 1; - if (atime_begin == 0 || atime_begin >= line.length()) - throw new RemoteScpException( - "Malformed T line sent by remote SCP binary, line not enough data."); - - int second_msec_begin = line.indexOf(" ", atime_begin + 1) + 1; - if (second_msec_begin == 0 || second_msec_begin >= line.length()) - throw new RemoteScpException( - "Malformed T line sent by remote SCP binary, line not enough data."); - - try { - modtime = Long.parseLong(line.substring(0, first_msec_begin - 1)); - first_msec = Long.parseLong(line.substring(first_msec_begin, atime_begin - 1)); - atime = Long.parseLong(line.substring(atime_begin, second_msec_begin - 1)); - second_msec = Long.parseLong(line.substring(second_msec_begin)); - } catch (NumberFormatException e) { - throw new RemoteScpException( - "Malformed C line sent by remote SCP binary, cannot parse file length."); - } - - if (modtime < 0 || first_msec < 0 || atime < 0 || second_msec < 0) - throw new RemoteScpException( - "Malformed C line sent by remote SCP binary, illegal file length."); - - fileInfo.setLastModified(modtime); - } - - private void sendBytes(Channel channel, byte[] data, String fileName, String mode) - throws IOException, RemoteScpException { - OutputStream os = channel.getOutputStream(); - InputStream is = new BufferedInputStream(channel.getInputStream(), 512); - - try { - if (channel.isConnected()) - channel.start(); - else - channel.connect(); - } catch (JSchException e1) { - throw (IOException) new IOException("Channel connection problems").initCause(e1); - } - - readResponse(is); - - String cline = "C" + mode + " " + data.length + " " + fileName + "\n"; - - os.write(cline.getBytes()); - os.flush(); - - readResponse(is); - - os.write(data, 0, data.length); - os.write(0); - os.flush(); - - readResponse(is); - - os.write("E\n".getBytes()); - os.flush(); - } - - private void sendFile(Channel channel, String localFile, String remoteName, String mode) - throws IOException, RemoteScpException { - byte[] buffer = new byte[8192]; - - OutputStream os = new BufferedOutputStream(channel.getOutputStream(), 40000); - InputStream is = new BufferedInputStream(channel.getInputStream(), 512); - - try { - if (channel.isConnected()) - channel.start(); - else - channel.connect(); - } catch (JSchException e1) { - throw (IOException) new IOException("Channel connection problems").initCause(e1); - } - - readResponse(is); - - File f = new File(localFile); - long remain = f.length(); - - String cline = "C" + mode + " " + remain + " " + remoteName + "\n"; - - os.write(cline.getBytes()); - os.flush(); - - readResponse(is); - - FileInputStream fis = null; - - try { - fis = new FileInputStream(f); - - while (remain > 0) { - int trans; - if (remain > buffer.length) - trans = buffer.length; - else - trans = (int) remain; - - if (fis.read(buffer, 0, trans) != trans) - throw new IOException("Cannot read enough from local file " + localFile); - - os.write(buffer, 0, trans); - - remain -= trans; - } - - fis.close(); - } catch (IOException e) { - if (fis != null) { - fis.close(); - } - throw (e); - } - - os.write(0); - os.flush(); - - readResponse(is); - - os.write("E\n".getBytes()); - os.flush(); - } - - /** - * Receive a file via scp and store it in a stream - * - * @param channel - * ssh channel to use - * @param file - * to receive from remote - * @param target - * to store file into (if null, get only file info) - * @return file information of the file we received - * @throws IOException - * in case of network or protocol trouble - * @throws RemoteScpException - * in case of problems on the target system (connection is fine) - */ - private FileInfo receiveStream(Channel channel, String file, OutputStream targetStream) - throws IOException, RemoteScpException { - byte[] buffer = new byte[8192]; - - OutputStream os = channel.getOutputStream(); - InputStream is = channel.getInputStream(); - try { - if (channel.isConnected()) - channel.start(); - else - channel.connect(); - } catch (JSchException e1) { - throw (IOException) new IOException("Channel connection problems").initCause(e1); - } - os.write(0x0); - os.flush(); - - FileInfo fileInfo = new FileInfo(); - - while (true) { - int c = is.read(); - if (c < 0) - throw new RemoteScpException("Remote scp terminated unexpectedly."); - - String line = receiveLine(is); - - if (c == 'T') { - parseTLine(line, fileInfo); - os.write(0x0); - os.flush(); - continue; - } - if ((c == 1) || (c == 2)) - throw new RemoteScpException("Remote SCP error: " + line); - - if (c == 'C') { - parseCLine(line, fileInfo); - break; - } - throw new RemoteScpException("Remote SCP error: " + ((char) c) + line); - } - if (targetStream != null) { - - os.write(0x0); - os.flush(); - - try { - long remain = fileInfo.getLength(); - - while (remain > 0) { - int trans; - if (remain > buffer.length) - trans = buffer.length; - else - trans = (int) remain; - - int this_time_received = is.read(buffer, 0, trans); - - if (this_time_received < 0) { - throw new IOException("Remote scp terminated connection unexpectedly"); - } - - targetStream.write(buffer, 0, this_time_received); - - remain -= this_time_received; - } - - targetStream.close(); - } catch (IOException e) { - if (targetStream != null) - targetStream.close(); - - throw (e); - } - - readResponse(is); - - os.write(0x0); - os.flush(); - } - return fileInfo; - } - - /** - * Copy a local file to a remote directory, uses mode 0600 when creating the file on the remote - * side. - * - * @param localFile - * Path and name of local file. - * @param remoteTargetDirectory - * Remote target directory where the file has to end up (optional) - * @param remoteName - * target filename to use - * @throws IOException - * in case of network problems - * @throws RemoteScpException - * in case of problems on the target system (connection ok) - */ - public void put(String localFile, String remoteTargetDirectory, String remoteName) - throws IOException, RemoteScpException { - put(localFile, remoteTargetDirectory, remoteName, "0600"); - } - - /** - * Create a remote file and copy the contents of the passed byte array into it. Uses mode 0600 - * for creating the remote file. - * - * @param data - * the data to be copied into the remote file. - * @param remoteFileName - * The name of the file which will be created in the remote target directory. - * @param remoteTargetDirectory - * Remote target directory where the file has to end up (optional) - * @throws IOException - * in case of network problems - * @throws RemoteScpException - * in case of problems on the target system (connection ok) - */ - - public void put(byte[] data, String remoteFileName, String remoteTargetDirectory) - throws IOException, RemoteScpException { - put(data, remoteFileName, remoteTargetDirectory, "0600"); - } - - /** - * Create a remote file and copy the contents of the passed byte array into it. The method use - * the specified mode when creating the file on the remote side. - * - * @param data - * the data to be copied into the remote file. - * @param remoteFileName - * The name of the file which will be created in the remote target directory. - * @param remoteTargetDirectory - * Remote target directory where the file has to end up (optional) - * @param mode - * a four digit string (e.g., 0644, see "man chmod", "man open") - * @throws IOException - * in case of network problems - * @throws RemoteScpException - * in case of problems on the target system (connection ok) - */ - public void put(byte[] data, String remoteFileName, String remoteTargetDirectory, String mode) - throws IOException, RemoteScpException { - ChannelExec channel = null; - - if ((remoteFileName == null) || (mode == null)) - throw new IllegalArgumentException("Null argument."); - - if (mode.length() != 4) - throw new IllegalArgumentException("Invalid mode."); - - for (int i = 0; i < mode.length(); i++) - if (Character.isDigit(mode.charAt(i)) == false) - throw new IllegalArgumentException("Invalid mode."); - - String cmd = "scp -t "; - if (remoteTargetDirectory != null && remoteTargetDirectory.length() > 0) { - cmd = cmd + "-d " + remoteTargetDirectory; - } - - try { - channel = getExecChannel(); - channel.setCommand(cmd); - sendBytes(channel, data, remoteFileName, mode); - // channel.disconnect(); - } catch (JSchException e) { - if (channel != null) - channel.disconnect(); - throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) - .initCause(e); - } - } - - /** - * @return - * @throws JSchException - */ - private ChannelExec getExecChannel() throws JSchException { - ChannelExec channel; - channel = (ChannelExec) session.openChannel("exec"); - return channel; - } - - /** - * Copy a local file to a remote site, uses the specified mode when creating the file on the - * remote side. - * - * @param localFile - * Path and name of local file. - * @param remoteTargetDir - * Remote target directory where the file has to end up (optional) - * @param remoteTargetName - * file name to use on the target system - * @param mode - * a four digit string (e.g., 0644, see "man chmod", "man open") - * @throws IOException - * in case of network problems - * @throws RemoteScpException - * in case of problems on the target system (connection ok) - */ - public void put(String localFile, String remoteTargetDir, String remoteTargetName, String mode) - throws IOException, RemoteScpException { - ChannelExec channel = null; - - if ((localFile == null) || (remoteTargetName == null) || (mode == null)) - throw new IllegalArgumentException("Null argument."); - - if (mode.length() != 4) - throw new IllegalArgumentException("Invalid mode."); - - for (int i = 0; i < mode.length(); i++) - if (Character.isDigit(mode.charAt(i)) == false) - throw new IllegalArgumentException("Invalid mode."); - - String cmd = "scp -t "; - if (remoteTargetDir != null && remoteTargetDir.length() > 0) { - cmd = cmd + "-d " + remoteTargetDir; - } - - try { - channel = getExecChannel(); - channel.setCommand(cmd); - sendFile(channel, localFile, remoteTargetName, mode); - channel.disconnect(); - } catch (JSchException e) { - if (channel != null) - channel.disconnect(); - throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) - .initCause(e); - } - } - - /** - * Download a file from the remote server to a local file. - * - * @param remoteFile - * Path and name of the remote file. - * @param localTarget - * Local file where to store the data. - * @throws IOException - * in case of network problems - * @throws RemoteScpException - * in case of problems on the target system (connection ok) - */ - public void get(String remoteFile, String localTarget) throws IOException, RemoteScpException { - File f = new File(localTarget); - FileOutputStream fop = new FileOutputStream(f); - get(remoteFile, fop); - } - - /** - * Download a file from the remote server into an OutputStream - * - * @param remoteFile - * Path and name of the remote file. - * @param localTarget - * OutputStream to store the data. - * @throws IOException - * in case of network problems - * @throws RemoteScpException - * in case of problems on the target system (connection ok) - */ - public void get(String remoteFile, OutputStream localTarget) throws IOException, - RemoteScpException { - ChannelExec channel = null; - - if ((remoteFile == null) || (localTarget == null)) - throw new IllegalArgumentException("Null argument."); - - String cmd = "scp -p -f " + remoteFile; - - try { - channel = getExecChannel(); - channel.setCommand(cmd); - receiveStream(channel, remoteFile, localTarget); - channel.disconnect(); - } catch (JSchException e) { - if (channel != null) - channel.disconnect(); - throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) - .initCause(e); - } - } - - /** - * Initiates an SCP sequence but stops after getting fileinformation header - * - * @param remoteFile - * to get information for - * @return the file information got - * @throws IOException - * in case of network problems - * @throws RemoteScpException - * in case of problems on the target system (connection ok) - */ - public FileInfo getFileinfo(String remoteFile) throws IOException, RemoteScpException { - ChannelExec channel = null; - FileInfo fileInfo = null; - - if (remoteFile == null) - throw new IllegalArgumentException("Null argument."); - - String cmd = "scp -p -f \"" + remoteFile + "\""; - - try { - channel = getExecChannel(); - channel.setCommand(cmd); - fileInfo = receiveStream(channel, remoteFile, null); - channel.disconnect(); - } catch (JSchException e) { - throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) - .initCause(e); - } finally { - if (channel != null) - channel.disconnect(); - } - return fileInfo; - } -} +/* + * 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.ssh; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import com.jcraft.jsch.Channel; +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; + +/** + * This class is using the scp client to transfer data and information for the repository. It is + * based on the SCPClient from the ganymed ssh library from Christian Plattner. To minimize the + * dependency to the ssh library and because I needed some additional functionality, I decided to + * copy'n'paste the single class rather than to inherit or delegate it somehow. Nevertheless credit + * should go to the original author. + */ + +public class Scp { + Session session; + + public class FileInfo { + private String filename; + + private long length; + + private long lastModified; + + /** + * @param filename + * The filename to set. + */ + public void setFilename(String filename) { + this.filename = filename; + } + + /** + * @return Returns the filename. + */ + public String getFilename() { + return filename; + } + + /** + * @param length + * The length to set. + */ + public void setLength(long length) { + this.length = length; + } + + /** + * @return Returns the length. + */ + public long getLength() { + return length; + } + + /** + * @param lastModified + * The lastModified to set. + */ + public void setLastModified(long lastModified) { + this.lastModified = lastModified; + } + + /** + * @return Returns the lastModified. + */ + public long getLastModified() { + return lastModified; + } + } + + public Scp(Session session) { + if (session == null) + throw new IllegalArgumentException("Cannot accept null argument!"); + this.session = session; + } + + private void readResponse(InputStream is) throws IOException, RemoteScpException { + int c = is.read(); + + if (c == 0) + return; + + if (c == -1) + throw new RemoteScpException("Remote scp terminated unexpectedly."); + + if ((c != 1) && (c != 2)) + throw new RemoteScpException("Remote scp sent illegal error code."); + + if (c == 2) + throw new RemoteScpException("Remote scp terminated with error."); + + String err = receiveLine(is); + throw new RemoteScpException("Remote scp terminated with error (" + err + ")."); + } + + private String receiveLine(InputStream is) throws IOException, RemoteScpException { + StringBuffer sb = new StringBuffer(30); + + while (true) { + /* + * This is a random limit - if your path names are longer, then adjust it + */ + + if (sb.length() > 8192) + throw new RemoteScpException("Remote scp sent a too long line"); + + int c = is.read(); + + if (c < 0) + throw new RemoteScpException("Remote scp terminated unexpectedly."); + + if (c == '\n') + break; + + sb.append((char) c); + + } + return sb.toString(); + } + + private void parseCLine(String line, FileInfo fileInfo) throws RemoteScpException { + /* Minimum line: "xxxx y z" ---> 8 chars */ + + long len; + + if (line.length() < 8) + throw new RemoteScpException( + "Malformed C line sent by remote SCP binary, line too short."); + + if ((line.charAt(4) != ' ') || (line.charAt(5) == ' ')) + throw new RemoteScpException("Malformed C line sent by remote SCP binary."); + + int length_name_sep = line.indexOf(' ', 5); + + if (length_name_sep == -1) + throw new RemoteScpException("Malformed C line sent by remote SCP binary."); + + String length_substring = line.substring(5, length_name_sep); + String name_substring = line.substring(length_name_sep + 1); + + if ((length_substring.length() <= 0) || (name_substring.length() <= 0)) + throw new RemoteScpException("Malformed C line sent by remote SCP binary."); + + if ((6 + length_substring.length() + name_substring.length()) != line.length()) + throw new RemoteScpException("Malformed C line sent by remote SCP binary."); + + try { + len = Long.parseLong(length_substring); + } catch (NumberFormatException e) { + throw new RemoteScpException( + "Malformed C line sent by remote SCP binary, cannot parse file length."); + } + + if (len < 0) + throw new RemoteScpException( + "Malformed C line sent by remote SCP binary, illegal file length."); + + fileInfo.setLength(len); + fileInfo.setFilename(name_substring); + } + + private void parseTLine(String line, FileInfo fileInfo) throws RemoteScpException { + /* Minimum line: "0 0 0 0" ---> 8 chars */ + + long modtime; + long first_msec; + long atime; + long second_msec; + + if (line.length() < 8) + throw new RemoteScpException( + "Malformed T line sent by remote SCP binary, line too short."); + + int first_msec_begin = line.indexOf(" ") + 1; + if (first_msec_begin == 0 || first_msec_begin >= line.length()) + throw new RemoteScpException( + "Malformed T line sent by remote SCP binary, line not enough data."); + + int atime_begin = line.indexOf(" ", first_msec_begin + 1) + 1; + if (atime_begin == 0 || atime_begin >= line.length()) + throw new RemoteScpException( + "Malformed T line sent by remote SCP binary, line not enough data."); + + int second_msec_begin = line.indexOf(" ", atime_begin + 1) + 1; + if (second_msec_begin == 0 || second_msec_begin >= line.length()) + throw new RemoteScpException( + "Malformed T line sent by remote SCP binary, line not enough data."); + + try { + modtime = Long.parseLong(line.substring(0, first_msec_begin - 1)); + first_msec = Long.parseLong(line.substring(first_msec_begin, atime_begin - 1)); + atime = Long.parseLong(line.substring(atime_begin, second_msec_begin - 1)); + second_msec = Long.parseLong(line.substring(second_msec_begin)); + } catch (NumberFormatException e) { + throw new RemoteScpException( + "Malformed C line sent by remote SCP binary, cannot parse file length."); + } + + if (modtime < 0 || first_msec < 0 || atime < 0 || second_msec < 0) + throw new RemoteScpException( + "Malformed C line sent by remote SCP binary, illegal file length."); + + fileInfo.setLastModified(modtime); + } + + private void sendBytes(Channel channel, byte[] data, String fileName, String mode) + throws IOException, RemoteScpException { + OutputStream os = channel.getOutputStream(); + InputStream is = new BufferedInputStream(channel.getInputStream(), 512); + + try { + if (channel.isConnected()) + channel.start(); + else + channel.connect(); + } catch (JSchException e1) { + throw (IOException) new IOException("Channel connection problems").initCause(e1); + } + + readResponse(is); + + String cline = "C" + mode + " " + data.length + " " + fileName + "\n"; + + os.write(cline.getBytes()); + os.flush(); + + readResponse(is); + + os.write(data, 0, data.length); + os.write(0); + os.flush(); + + readResponse(is); + + os.write("E\n".getBytes()); + os.flush(); + } + + private void sendFile(Channel channel, String localFile, String remoteName, String mode) + throws IOException, RemoteScpException { + byte[] buffer = new byte[8192]; + + OutputStream os = new BufferedOutputStream(channel.getOutputStream(), 40000); + InputStream is = new BufferedInputStream(channel.getInputStream(), 512); + + try { + if (channel.isConnected()) + channel.start(); + else + channel.connect(); + } catch (JSchException e1) { + throw (IOException) new IOException("Channel connection problems").initCause(e1); + } + + readResponse(is); + + File f = new File(localFile); + long remain = f.length(); + + String cline = "C" + mode + " " + remain + " " + remoteName + "\n"; + + os.write(cline.getBytes()); + os.flush(); + + readResponse(is); + + FileInputStream fis = null; + + try { + fis = new FileInputStream(f); + + while (remain > 0) { + int trans; + if (remain > buffer.length) + trans = buffer.length; + else + trans = (int) remain; + + if (fis.read(buffer, 0, trans) != trans) + throw new IOException("Cannot read enough from local file " + localFile); + + os.write(buffer, 0, trans); + + remain -= trans; + } + + fis.close(); + } catch (IOException e) { + if (fis != null) { + fis.close(); + } + throw (e); + } + + os.write(0); + os.flush(); + + readResponse(is); + + os.write("E\n".getBytes()); + os.flush(); + } + + /** + * Receive a file via scp and store it in a stream + * + * @param channel + * ssh channel to use + * @param file + * to receive from remote + * @param target + * to store file into (if null, get only file info) + * @return file information of the file we received + * @throws IOException + * in case of network or protocol trouble + * @throws RemoteScpException + * in case of problems on the target system (connection is fine) + */ + private FileInfo receiveStream(Channel channel, String file, OutputStream targetStream) + throws IOException, RemoteScpException { + byte[] buffer = new byte[8192]; + + OutputStream os = channel.getOutputStream(); + InputStream is = channel.getInputStream(); + try { + if (channel.isConnected()) + channel.start(); + else + channel.connect(); + } catch (JSchException e1) { + throw (IOException) new IOException("Channel connection problems").initCause(e1); + } + os.write(0x0); + os.flush(); + + FileInfo fileInfo = new FileInfo(); + + while (true) { + int c = is.read(); + if (c < 0) + throw new RemoteScpException("Remote scp terminated unexpectedly."); + + String line = receiveLine(is); + + if (c == 'T') { + parseTLine(line, fileInfo); + os.write(0x0); + os.flush(); + continue; + } + if ((c == 1) || (c == 2)) + throw new RemoteScpException("Remote SCP error: " + line); + + if (c == 'C') { + parseCLine(line, fileInfo); + break; + } + throw new RemoteScpException("Remote SCP error: " + ((char) c) + line); + } + if (targetStream != null) { + + os.write(0x0); + os.flush(); + + try { + long remain = fileInfo.getLength(); + + while (remain > 0) { + int trans; + if (remain > buffer.length) + trans = buffer.length; + else + trans = (int) remain; + + int this_time_received = is.read(buffer, 0, trans); + + if (this_time_received < 0) { + throw new IOException("Remote scp terminated connection unexpectedly"); + } + + targetStream.write(buffer, 0, this_time_received); + + remain -= this_time_received; + } + + targetStream.close(); + } catch (IOException e) { + if (targetStream != null) + targetStream.close(); + + throw (e); + } + + readResponse(is); + + os.write(0x0); + os.flush(); + } + return fileInfo; + } + + /** + * Copy a local file to a remote directory, uses mode 0600 when creating the file on the remote + * side. + * + * @param localFile + * Path and name of local file. + * @param remoteTargetDirectory + * Remote target directory where the file has to end up (optional) + * @param remoteName + * target filename to use + * @throws IOException + * in case of network problems + * @throws RemoteScpException + * in case of problems on the target system (connection ok) + */ + public void put(String localFile, String remoteTargetDirectory, String remoteName) + throws IOException, RemoteScpException { + put(localFile, remoteTargetDirectory, remoteName, "0600"); + } + + /** + * Create a remote file and copy the contents of the passed byte array into it. Uses mode 0600 + * for creating the remote file. + * + * @param data + * the data to be copied into the remote file. + * @param remoteFileName + * The name of the file which will be created in the remote target directory. + * @param remoteTargetDirectory + * Remote target directory where the file has to end up (optional) + * @throws IOException + * in case of network problems + * @throws RemoteScpException + * in case of problems on the target system (connection ok) + */ + + public void put(byte[] data, String remoteFileName, String remoteTargetDirectory) + throws IOException, RemoteScpException { + put(data, remoteFileName, remoteTargetDirectory, "0600"); + } + + /** + * Create a remote file and copy the contents of the passed byte array into it. The method use + * the specified mode when creating the file on the remote side. + * + * @param data + * the data to be copied into the remote file. + * @param remoteFileName + * The name of the file which will be created in the remote target directory. + * @param remoteTargetDirectory + * Remote target directory where the file has to end up (optional) + * @param mode + * a four digit string (e.g., 0644, see "man chmod", "man open") + * @throws IOException + * in case of network problems + * @throws RemoteScpException + * in case of problems on the target system (connection ok) + */ + public void put(byte[] data, String remoteFileName, String remoteTargetDirectory, String mode) + throws IOException, RemoteScpException { + ChannelExec channel = null; + + if ((remoteFileName == null) || (mode == null)) + throw new IllegalArgumentException("Null argument."); + + if (mode.length() != 4) + throw new IllegalArgumentException("Invalid mode."); + + for (int i = 0; i < mode.length(); i++) + if (Character.isDigit(mode.charAt(i)) == false) + throw new IllegalArgumentException("Invalid mode."); + + String cmd = "scp -t "; + if (remoteTargetDirectory != null && remoteTargetDirectory.length() > 0) { + cmd = cmd + "-d " + remoteTargetDirectory; + } + + try { + channel = getExecChannel(); + channel.setCommand(cmd); + sendBytes(channel, data, remoteFileName, mode); + // channel.disconnect(); + } catch (JSchException e) { + if (channel != null) + channel.disconnect(); + throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) + .initCause(e); + } + } + + /** + * @return + * @throws JSchException + */ + private ChannelExec getExecChannel() throws JSchException { + ChannelExec channel; + channel = (ChannelExec) session.openChannel("exec"); + return channel; + } + + /** + * Copy a local file to a remote site, uses the specified mode when creating the file on the + * remote side. + * + * @param localFile + * Path and name of local file. + * @param remoteTargetDir + * Remote target directory where the file has to end up (optional) + * @param remoteTargetName + * file name to use on the target system + * @param mode + * a four digit string (e.g., 0644, see "man chmod", "man open") + * @throws IOException + * in case of network problems + * @throws RemoteScpException + * in case of problems on the target system (connection ok) + */ + public void put(String localFile, String remoteTargetDir, String remoteTargetName, String mode) + throws IOException, RemoteScpException { + ChannelExec channel = null; + + if ((localFile == null) || (remoteTargetName == null) || (mode == null)) + throw new IllegalArgumentException("Null argument."); + + if (mode.length() != 4) + throw new IllegalArgumentException("Invalid mode."); + + for (int i = 0; i < mode.length(); i++) + if (Character.isDigit(mode.charAt(i)) == false) + throw new IllegalArgumentException("Invalid mode."); + + String cmd = "scp -t "; + if (remoteTargetDir != null && remoteTargetDir.length() > 0) { + cmd = cmd + "-d " + remoteTargetDir; + } + + try { + channel = getExecChannel(); + channel.setCommand(cmd); + sendFile(channel, localFile, remoteTargetName, mode); + channel.disconnect(); + } catch (JSchException e) { + if (channel != null) + channel.disconnect(); + throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) + .initCause(e); + } + } + + /** + * Download a file from the remote server to a local file. + * + * @param remoteFile + * Path and name of the remote file. + * @param localTarget + * Local file where to store the data. + * @throws IOException + * in case of network problems + * @throws RemoteScpException + * in case of problems on the target system (connection ok) + */ + public void get(String remoteFile, String localTarget) throws IOException, RemoteScpException { + File f = new File(localTarget); + FileOutputStream fop = new FileOutputStream(f); + get(remoteFile, fop); + } + + /** + * Download a file from the remote server into an OutputStream + * + * @param remoteFile + * Path and name of the remote file. + * @param localTarget + * OutputStream to store the data. + * @throws IOException + * in case of network problems + * @throws RemoteScpException + * in case of problems on the target system (connection ok) + */ + public void get(String remoteFile, OutputStream localTarget) throws IOException, + RemoteScpException { + ChannelExec channel = null; + + if ((remoteFile == null) || (localTarget == null)) + throw new IllegalArgumentException("Null argument."); + + String cmd = "scp -p -f " + remoteFile; + + try { + channel = getExecChannel(); + channel.setCommand(cmd); + receiveStream(channel, remoteFile, localTarget); + channel.disconnect(); + } catch (JSchException e) { + if (channel != null) + channel.disconnect(); + throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) + .initCause(e); + } + } + + /** + * Initiates an SCP sequence but stops after getting fileinformation header + * + * @param remoteFile + * to get information for + * @return the file information got + * @throws IOException + * in case of network problems + * @throws RemoteScpException + * in case of problems on the target system (connection ok) + */ + public FileInfo getFileinfo(String remoteFile) throws IOException, RemoteScpException { + ChannelExec channel = null; + FileInfo fileInfo = null; + + if (remoteFile == null) + throw new IllegalArgumentException("Null argument."); + + String cmd = "scp -p -f \"" + remoteFile + "\""; + + try { + channel = getExecChannel(); + channel.setCommand(cmd); + fileInfo = receiveStream(channel, remoteFile, null); + channel.disconnect(); + } catch (JSchException e) { + throw (IOException) new IOException("Error during SCP transfer." + e.getMessage()) + .initCause(e); + } finally { + if (channel != null) + channel.disconnect(); + } + return fileInfo; + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java b/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java index 650befcd..9ec89a7a 100644 --- a/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java @@ -1,108 +1,108 @@ -/* - * 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.url; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; - -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; -import org.apache.ivy.util.url.ApacheURLLister; - -public class URLRepository extends AbstractRepository { - private RepositoryCopyProgressListener _progress = new RepositoryCopyProgressListener(this); - - private Map _resourcesCache = new HashMap(); - - public Resource getResource(String source) throws IOException { - Resource res = (Resource) _resourcesCache.get(source); - if (res == null) { - res = new URLResource(new URL(source)); - _resourcesCache.put(source, res); - } - return res; - } - - public void get(String source, File destination) throws IOException { - fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); - try { - Resource res = getResource(source); - long totalLength = res.getContentLength(); - if (totalLength > 0) { - _progress.setTotalLength(new Long(totalLength)); - } - FileUtil.copy(new URL(source), destination, _progress); - } catch (IOException ex) { - fireTransferError(ex); - throw ex; - } catch (RuntimeException ex) { - fireTransferError(ex); - throw ex; - } finally { - _progress.setTotalLength(null); - } - } - - public void put(File source, String destination, boolean overwrite) throws IOException { - throw new UnsupportedOperationException( - "URL repository is not able to put files for the moment"); - } - - private ApacheURLLister _lister = new ApacheURLLister(); - - public List list(String parent) throws IOException { - if (parent.startsWith("http")) { - List urls = _lister.listAll(new URL(parent)); - if (urls != null) { - List ret = new ArrayList(urls.size()); - for (ListIterator iter = urls.listIterator(); iter.hasNext();) { - URL url = (URL) iter.next(); - ret.add(url.toExternalForm()); - } - return ret; - } - } else if (parent.startsWith("file")) { - String path = new URL(parent).getPath(); - File file = new File(path); - if (file.exists() && file.isDirectory()) { - String[] files = file.list(); - List ret = new ArrayList(files.length); - URL context = path.endsWith("/") ? new URL(parent) : new URL(parent + "/"); - for (int i = 0; i < files.length; i++) { - ret.add(new URL(context, files[i]).toExternalForm()); - } - return ret; - } else { - return Collections.EMPTY_LIST; - } - - } - return null; - } - -} +/* + * 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.url; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; + +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; +import org.apache.ivy.util.url.ApacheURLLister; + +public class URLRepository extends AbstractRepository { + private RepositoryCopyProgressListener _progress = new RepositoryCopyProgressListener(this); + + private Map _resourcesCache = new HashMap(); + + public Resource getResource(String source) throws IOException { + Resource res = (Resource) _resourcesCache.get(source); + if (res == null) { + res = new URLResource(new URL(source)); + _resourcesCache.put(source, res); + } + return res; + } + + public void get(String source, File destination) throws IOException { + fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); + try { + Resource res = getResource(source); + long totalLength = res.getContentLength(); + if (totalLength > 0) { + _progress.setTotalLength(new Long(totalLength)); + } + FileUtil.copy(new URL(source), destination, _progress); + } catch (IOException ex) { + fireTransferError(ex); + throw ex; + } catch (RuntimeException ex) { + fireTransferError(ex); + throw ex; + } finally { + _progress.setTotalLength(null); + } + } + + public void put(File source, String destination, boolean overwrite) throws IOException { + throw new UnsupportedOperationException( + "URL repository is not able to put files for the moment"); + } + + private ApacheURLLister _lister = new ApacheURLLister(); + + public List list(String parent) throws IOException { + if (parent.startsWith("http")) { + List urls = _lister.listAll(new URL(parent)); + if (urls != null) { + List ret = new ArrayList(urls.size()); + for (ListIterator iter = urls.listIterator(); iter.hasNext();) { + URL url = (URL) iter.next(); + ret.add(url.toExternalForm()); + } + return ret; + } + } else if (parent.startsWith("file")) { + String path = new URL(parent).getPath(); + File file = new File(path); + if (file.exists() && file.isDirectory()) { + String[] files = file.list(); + List ret = new ArrayList(files.length); + URL context = path.endsWith("/") ? new URL(parent) : new URL(parent + "/"); + for (int i = 0; i < files.length; i++) { + ret.add(new URL(context, files[i]).toExternalForm()); + } + return ret; + } else { + return Collections.EMPTY_LIST; + } + + } + return null; + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/url/URLResource.java b/src/java/org/apache/ivy/plugins/repository/url/URLResource.java index d252862d..f051b568 100644 --- a/src/java/org/apache/ivy/plugins/repository/url/URLResource.java +++ b/src/java/org/apache/ivy/plugins/repository/url/URLResource.java @@ -1,101 +1,101 @@ -/* - * 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.url; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; - -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.util.url.URLHandlerRegistry; -import org.apache.ivy.util.url.URLHandler.URLInfo; - -public class URLResource implements Resource { - private URL _url; - - private boolean _init = false; - - private long _lastModified; - - private long _contentLength; - - private boolean _exists; - - public URLResource(URL url) { - _url = url; - } - - public String getName() { - return _url.toExternalForm(); - } - - public Resource clone(String cloneName) { - try { - return new URLResource(new URL(cloneName)); - } catch (MalformedURLException e) { - throw new IllegalArgumentException( - "bad clone name provided: not suitable for an URLResource: " + cloneName); - } - } - - public long getLastModified() { - if (!_init) { - init(); - } - return _lastModified; - } - - private void init() { - URLInfo info = URLHandlerRegistry.getDefault().getURLInfo(_url); - _contentLength = info.getContentLength(); - _lastModified = info.getLastModified(); - _exists = info.isReachable(); - _init = true; - } - - public long getContentLength() { - if (!_init) { - init(); - } - return _contentLength; - } - - public boolean exists() { - if (!_init) { - init(); - } - return _exists; - } - - public URL getURL() { - return _url; - } - - public String toString() { - return getName(); - } - - public boolean isLocal() { - return false; - } - - public InputStream openStream() throws IOException { - return _url.openStream(); - } -} +/* + * 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.url; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.util.url.URLHandlerRegistry; +import org.apache.ivy.util.url.URLHandler.URLInfo; + +public class URLResource implements Resource { + private URL _url; + + private boolean _init = false; + + private long _lastModified; + + private long _contentLength; + + private boolean _exists; + + public URLResource(URL url) { + _url = url; + } + + public String getName() { + return _url.toExternalForm(); + } + + public Resource clone(String cloneName) { + try { + return new URLResource(new URL(cloneName)); + } catch (MalformedURLException e) { + throw new IllegalArgumentException( + "bad clone name provided: not suitable for an URLResource: " + cloneName); + } + } + + public long getLastModified() { + if (!_init) { + init(); + } + return _lastModified; + } + + private void init() { + URLInfo info = URLHandlerRegistry.getDefault().getURLInfo(_url); + _contentLength = info.getContentLength(); + _lastModified = info.getLastModified(); + _exists = info.isReachable(); + _init = true; + } + + public long getContentLength() { + if (!_init) { + init(); + } + return _contentLength; + } + + public boolean exists() { + if (!_init) { + init(); + } + return _exists; + } + + public URL getURL() { + return _url; + } + + public String toString() { + return getName(); + } + + public boolean isLocal() { + return false; + } + + public InputStream openStream() throws IOException { + return _url.openStream(); + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavClientFactory.java b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavClientFactory.java index 34bbb5e5..3bfe59a9 100644 --- a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavClientFactory.java +++ b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavClientFactory.java @@ -1,87 +1,87 @@ -/* - * 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.vfs; - -import java.io.IOException; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpURL; -import org.apache.commons.vfs.FileSystemException; -import org.apache.commons.vfs.FileSystemOptions; -import org.apache.commons.vfs.provider.webdav.WebdavConnectionManager; -import org.apache.commons.vfs.provider.webdav.WebdavFileSystemConfigBuilder; -import org.apache.ivy.util.url.HttpClientHandler; -import org.apache.webdav.lib.WebdavResource; - -/*************************************************************************************************** - * Modified version of the WebdavClientFactory from VFS which adds support for httpclient 3.x. See - * http://issues.apache.org/jira/browse/VFS-74 for more info. Create a HttpClient instance - */ -class IvyWebdavClientFactory { - - private IvyWebdavClientFactory() { - } - - /*********************************************************************************************** - * Creates a new connection to the server. - */ - public static HttpClient createConnection(String hostname, int port, String username, - String password, FileSystemOptions fileSystemOptions) throws FileSystemException { - // Create an Http client - HttpClient client; - try { - final HttpURL url = new HttpURL(username, password, hostname, port, "/"); - - // WebdavResource resource = null; - WebdavResource resource = new WebdavResource() { - }; - - if (fileSystemOptions != null) { - String proxyHost = WebdavFileSystemConfigBuilder.getInstance().getProxyHost( - fileSystemOptions); - int proxyPort = WebdavFileSystemConfigBuilder.getInstance().getProxyPort( - fileSystemOptions); - - if (proxyHost != null && proxyPort > 0) { - // resource = new WebdavResource(url, proxyHost, proxyPort); - resource.setProxy(proxyHost, proxyPort); - } - } - - /* - * if (resource == null) { resource = new WebdavResource(url); } - * resource.setProperties(WebdavResource.NOACTION, 1); - */ - resource.setHttpURL(url, WebdavResource.NOACTION, 1); - - client = resource.retrieveSessionInstance(); - HttpClientHandler handler = new HttpClientHandler(); - int httpClientVersion = handler.getHttpClientMajorVersion(); - if (httpClientVersion == 2) { - // VFS only supports httpclient v2 for now... - client.setHttpConnectionManager(new WebdavConnectionManager()); - } else { - client.setHttpConnectionManager(new IvyWebdavConnectionManager()); - } - } catch (final IOException e) { - throw new FileSystemException("vfs.provider.webdav/connect.error", hostname, e); - } - - return client; - } -} +/* + * 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.vfs; + +import java.io.IOException; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpURL; +import org.apache.commons.vfs.FileSystemException; +import org.apache.commons.vfs.FileSystemOptions; +import org.apache.commons.vfs.provider.webdav.WebdavConnectionManager; +import org.apache.commons.vfs.provider.webdav.WebdavFileSystemConfigBuilder; +import org.apache.ivy.util.url.HttpClientHandler; +import org.apache.webdav.lib.WebdavResource; + +/*************************************************************************************************** + * Modified version of the WebdavClientFactory from VFS which adds support for httpclient 3.x. See + * http://issues.apache.org/jira/browse/VFS-74 for more info. Create a HttpClient instance + */ +class IvyWebdavClientFactory { + + private IvyWebdavClientFactory() { + } + + /*********************************************************************************************** + * Creates a new connection to the server. + */ + public static HttpClient createConnection(String hostname, int port, String username, + String password, FileSystemOptions fileSystemOptions) throws FileSystemException { + // Create an Http client + HttpClient client; + try { + final HttpURL url = new HttpURL(username, password, hostname, port, "/"); + + // WebdavResource resource = null; + WebdavResource resource = new WebdavResource() { + }; + + if (fileSystemOptions != null) { + String proxyHost = WebdavFileSystemConfigBuilder.getInstance().getProxyHost( + fileSystemOptions); + int proxyPort = WebdavFileSystemConfigBuilder.getInstance().getProxyPort( + fileSystemOptions); + + if (proxyHost != null && proxyPort > 0) { + // resource = new WebdavResource(url, proxyHost, proxyPort); + resource.setProxy(proxyHost, proxyPort); + } + } + + /* + * if (resource == null) { resource = new WebdavResource(url); } + * resource.setProperties(WebdavResource.NOACTION, 1); + */ + resource.setHttpURL(url, WebdavResource.NOACTION, 1); + + client = resource.retrieveSessionInstance(); + HttpClientHandler handler = new HttpClientHandler(); + int httpClientVersion = handler.getHttpClientMajorVersion(); + if (httpClientVersion == 2) { + // VFS only supports httpclient v2 for now... + client.setHttpConnectionManager(new WebdavConnectionManager()); + } else { + client.setHttpConnectionManager(new IvyWebdavConnectionManager()); + } + } catch (final IOException e) { + throw new FileSystemException("vfs.provider.webdav/connect.error", hostname, e); + } + + return client; + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavConnectionManager.java b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavConnectionManager.java index 3790187a..095ee734 100644 --- a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavConnectionManager.java +++ b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavConnectionManager.java @@ -1,225 +1,225 @@ -/* - * 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.vfs; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.commons.httpclient.HostConfiguration; -import org.apache.commons.httpclient.HttpConnection; -import org.apache.commons.httpclient.HttpConnectionManager; -import org.apache.commons.httpclient.params.HttpConnectionManagerParams; - -/** - * Modified version of the WebdavConnectionManager from VFS which adds support for httpclient 3.x. - * See http://issues.apache.org/jira/browse/VFS-74 for more info. A connection manager that provides - * access to a single HttpConnection. This manager makes no attempt to provide exclusive access to - * the contained HttpConnection.

      imario@apache.org: Keep connection in ThreadLocal. - */ -class IvyWebdavConnectionManager implements HttpConnectionManager { - - /** - * Since the same connection is about to be reused, make sure the previous request was - * completely processed, and if not consume it now. - * - * @param conn - * The connection - */ - static void finishLastResponse(HttpConnection conn) { - InputStream lastResponse = conn.getLastResponseInputStream(); - if (lastResponse != null) { - conn.setLastResponseInputStream(null); - try { - lastResponse.close(); - } catch (IOException ioe) { - // FIXME: badness - close to force reconnect. - conn.close(); - } - } - } - - /** - * The thread data - */ - protected ThreadLocal localHttpConnection = new ThreadLocal() { - protected Object initialValue() { - return new Entry(); - } - }; - - /** - * Collection of parameters associated with this connection manager. - */ - private HttpConnectionManagerParams params = new HttpConnectionManagerParams(); - - /** - * release the connection of the current thread - */ - public void releaseLocalConnection() { - if (getLocalHttpConnection() != null) { - releaseConnection(getLocalHttpConnection()); - } - } - - private static class Entry { - /** - * The http connection - */ - private HttpConnection conn = null; - - /** - * The time the connection was made idle. - */ - private long idleStartTime = Long.MAX_VALUE; - } - - public IvyWebdavConnectionManager() { - } - - protected HttpConnection getLocalHttpConnection() { - return ((Entry) localHttpConnection.get()).conn; - } - - protected void setLocalHttpConnection(HttpConnection conn) { - ((Entry) localHttpConnection.get()).conn = conn; - } - - protected long getIdleStartTime() { - return ((Entry) localHttpConnection.get()).idleStartTime; - } - - protected void setIdleStartTime(long idleStartTime) { - ((Entry) localHttpConnection.get()).idleStartTime = idleStartTime; - } - - /** - * @see HttpConnectionManager#getConnection(org.apache.commons.httpclient.HostConfiguration) - */ - public HttpConnection getConnection(HostConfiguration hostConfiguration) { - return getConnection(hostConfiguration, 0); - } - - /** - * Gets the staleCheckingEnabled value to be set on HttpConnections that are created. - * - * @return true if stale checking will be enabled on HttpConections - * @see HttpConnection#isStaleCheckingEnabled() - */ - public boolean isConnectionStaleCheckingEnabled() { - return this.params.isStaleCheckingEnabled(); - } - - /** - * Sets the staleCheckingEnabled value to be set on HttpConnections that are created. - * - * @param connectionStaleCheckingEnabled - * true if stale checking will be enabled on HttpConections - * @see HttpConnection#setStaleCheckingEnabled(boolean) - */ - public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled) { - this.params.setStaleCheckingEnabled(connectionStaleCheckingEnabled); - } - - /** - * @see HttpConnectionManager#getConnection(HostConfiguration, long) - * @since 3.0 - */ - public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout) { - - HttpConnection httpConnection = getLocalHttpConnection(); - if (httpConnection == null) { - httpConnection = new HttpConnection(hostConfiguration); - setLocalHttpConnection(httpConnection); - httpConnection.setHttpConnectionManager(this); - httpConnection.getParams().setDefaults(this.params); - } else { - - // make sure the host and proxy are correct for this connection - // close it and set the values if they are not - if (!hostConfiguration.hostEquals(httpConnection) - || !hostConfiguration.proxyEquals(httpConnection)) { - - if (httpConnection.isOpen()) { - httpConnection.close(); - } - - httpConnection.setHost(hostConfiguration.getHost()); - httpConnection.setPort(hostConfiguration.getPort()); - httpConnection.setProtocol(hostConfiguration.getProtocol()); - httpConnection.setLocalAddress(hostConfiguration.getLocalAddress()); - - httpConnection.setProxyHost(hostConfiguration.getProxyHost()); - httpConnection.setProxyPort(hostConfiguration.getProxyPort()); - } else { - finishLastResponse(httpConnection); - } - } - - // remove the connection from the timeout handler - setIdleStartTime(Long.MAX_VALUE); - - return httpConnection; - } - - /** - * @see HttpConnectionManager#getConnection(HostConfiguration, long) - * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) - */ - public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) { - return getConnectionWithTimeout(hostConfiguration, timeout); - } - - /** - * @see HttpConnectionManager#releaseConnection(org.apache.commons.httpclient.HttpConnection) - */ - public void releaseConnection(HttpConnection conn) { - if (conn != getLocalHttpConnection()) { - throw new IllegalStateException("Unexpected release of an unknown connection."); - } - - finishLastResponse(getLocalHttpConnection()); - - // track the time the connection was made idle - setIdleStartTime(System.currentTimeMillis()); - } - - /** - * @since 3.0 - */ - public void closeIdleConnections(long idleTimeout) { - long maxIdleTime = System.currentTimeMillis() - idleTimeout; - if (getIdleStartTime() <= maxIdleTime) { - getLocalHttpConnection().close(); - } - } - - /** - * {@inheritDoc} - */ - public HttpConnectionManagerParams getParams() { - return params; - } - - /** - * {@inheritDoc} - */ - public void setParams(HttpConnectionManagerParams params) { - this.params = params; - } - -} +/* + * 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.vfs; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.httpclient.HostConfiguration; +import org.apache.commons.httpclient.HttpConnection; +import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.params.HttpConnectionManagerParams; + +/** + * Modified version of the WebdavConnectionManager from VFS which adds support for httpclient 3.x. + * See http://issues.apache.org/jira/browse/VFS-74 for more info. A connection manager that provides + * access to a single HttpConnection. This manager makes no attempt to provide exclusive access to + * the contained HttpConnection.

      imario@apache.org: Keep connection in ThreadLocal. + */ +class IvyWebdavConnectionManager implements HttpConnectionManager { + + /** + * Since the same connection is about to be reused, make sure the previous request was + * completely processed, and if not consume it now. + * + * @param conn + * The connection + */ + static void finishLastResponse(HttpConnection conn) { + InputStream lastResponse = conn.getLastResponseInputStream(); + if (lastResponse != null) { + conn.setLastResponseInputStream(null); + try { + lastResponse.close(); + } catch (IOException ioe) { + // FIXME: badness - close to force reconnect. + conn.close(); + } + } + } + + /** + * The thread data + */ + protected ThreadLocal localHttpConnection = new ThreadLocal() { + protected Object initialValue() { + return new Entry(); + } + }; + + /** + * Collection of parameters associated with this connection manager. + */ + private HttpConnectionManagerParams params = new HttpConnectionManagerParams(); + + /** + * release the connection of the current thread + */ + public void releaseLocalConnection() { + if (getLocalHttpConnection() != null) { + releaseConnection(getLocalHttpConnection()); + } + } + + private static class Entry { + /** + * The http connection + */ + private HttpConnection conn = null; + + /** + * The time the connection was made idle. + */ + private long idleStartTime = Long.MAX_VALUE; + } + + public IvyWebdavConnectionManager() { + } + + protected HttpConnection getLocalHttpConnection() { + return ((Entry) localHttpConnection.get()).conn; + } + + protected void setLocalHttpConnection(HttpConnection conn) { + ((Entry) localHttpConnection.get()).conn = conn; + } + + protected long getIdleStartTime() { + return ((Entry) localHttpConnection.get()).idleStartTime; + } + + protected void setIdleStartTime(long idleStartTime) { + ((Entry) localHttpConnection.get()).idleStartTime = idleStartTime; + } + + /** + * @see HttpConnectionManager#getConnection(org.apache.commons.httpclient.HostConfiguration) + */ + public HttpConnection getConnection(HostConfiguration hostConfiguration) { + return getConnection(hostConfiguration, 0); + } + + /** + * Gets the staleCheckingEnabled value to be set on HttpConnections that are created. + * + * @return true if stale checking will be enabled on HttpConections + * @see HttpConnection#isStaleCheckingEnabled() + */ + public boolean isConnectionStaleCheckingEnabled() { + return this.params.isStaleCheckingEnabled(); + } + + /** + * Sets the staleCheckingEnabled value to be set on HttpConnections that are created. + * + * @param connectionStaleCheckingEnabled + * true if stale checking will be enabled on HttpConections + * @see HttpConnection#setStaleCheckingEnabled(boolean) + */ + public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled) { + this.params.setStaleCheckingEnabled(connectionStaleCheckingEnabled); + } + + /** + * @see HttpConnectionManager#getConnection(HostConfiguration, long) + * @since 3.0 + */ + public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration, long timeout) { + + HttpConnection httpConnection = getLocalHttpConnection(); + if (httpConnection == null) { + httpConnection = new HttpConnection(hostConfiguration); + setLocalHttpConnection(httpConnection); + httpConnection.setHttpConnectionManager(this); + httpConnection.getParams().setDefaults(this.params); + } else { + + // make sure the host and proxy are correct for this connection + // close it and set the values if they are not + if (!hostConfiguration.hostEquals(httpConnection) + || !hostConfiguration.proxyEquals(httpConnection)) { + + if (httpConnection.isOpen()) { + httpConnection.close(); + } + + httpConnection.setHost(hostConfiguration.getHost()); + httpConnection.setPort(hostConfiguration.getPort()); + httpConnection.setProtocol(hostConfiguration.getProtocol()); + httpConnection.setLocalAddress(hostConfiguration.getLocalAddress()); + + httpConnection.setProxyHost(hostConfiguration.getProxyHost()); + httpConnection.setProxyPort(hostConfiguration.getProxyPort()); + } else { + finishLastResponse(httpConnection); + } + } + + // remove the connection from the timeout handler + setIdleStartTime(Long.MAX_VALUE); + + return httpConnection; + } + + /** + * @see HttpConnectionManager#getConnection(HostConfiguration, long) + * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) + */ + public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) { + return getConnectionWithTimeout(hostConfiguration, timeout); + } + + /** + * @see HttpConnectionManager#releaseConnection(org.apache.commons.httpclient.HttpConnection) + */ + public void releaseConnection(HttpConnection conn) { + if (conn != getLocalHttpConnection()) { + throw new IllegalStateException("Unexpected release of an unknown connection."); + } + + finishLastResponse(getLocalHttpConnection()); + + // track the time the connection was made idle + setIdleStartTime(System.currentTimeMillis()); + } + + /** + * @since 3.0 + */ + public void closeIdleConnections(long idleTimeout) { + long maxIdleTime = System.currentTimeMillis() - idleTimeout; + if (getIdleStartTime() <= maxIdleTime) { + getLocalHttpConnection().close(); + } + } + + /** + * {@inheritDoc} + */ + public HttpConnectionManagerParams getParams() { + return params; + } + + /** + * {@inheritDoc} + */ + public void setParams(HttpConnectionManagerParams params) { + this.params = params; + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileProvider.java b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileProvider.java index 225a3668..dcf9318e 100644 --- a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileProvider.java +++ b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileProvider.java @@ -1,48 +1,48 @@ -/* - * 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.vfs; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.vfs.FileName; -import org.apache.commons.vfs.FileSystem; -import org.apache.commons.vfs.FileSystemException; -import org.apache.commons.vfs.FileSystemOptions; -import org.apache.commons.vfs.provider.GenericFileName; -import org.apache.commons.vfs.provider.webdav.WebdavFileProvider; - -/** - * Modified version of the WebdavFileProvider from VFS which adds support for httpclient 3.x. See - * http://issues.apache.org/jira/browse/VFS-74 for more info. A provider for WebDAV. - */ -public class IvyWebdavFileProvider extends WebdavFileProvider { - - /*********************************************************************************************** - * Creates a filesystem. - */ - protected FileSystem doCreateFileSystem(final FileName name, - final FileSystemOptions fileSystemOptions) throws FileSystemException { - // Create the file system - final GenericFileName rootName = (GenericFileName) name; - - HttpClient httpClient = IvyWebdavClientFactory.createConnection(rootName.getHostName(), - rootName.getPort(), rootName.getUserName(), rootName.getPassword(), fileSystemOptions); - - return new IvyWebdavFileSystem(rootName, httpClient, fileSystemOptions); - } - -} +/* + * 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.vfs; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.vfs.FileName; +import org.apache.commons.vfs.FileSystem; +import org.apache.commons.vfs.FileSystemException; +import org.apache.commons.vfs.FileSystemOptions; +import org.apache.commons.vfs.provider.GenericFileName; +import org.apache.commons.vfs.provider.webdav.WebdavFileProvider; + +/** + * Modified version of the WebdavFileProvider from VFS which adds support for httpclient 3.x. See + * http://issues.apache.org/jira/browse/VFS-74 for more info. A provider for WebDAV. + */ +public class IvyWebdavFileProvider extends WebdavFileProvider { + + /*********************************************************************************************** + * Creates a filesystem. + */ + protected FileSystem doCreateFileSystem(final FileName name, + final FileSystemOptions fileSystemOptions) throws FileSystemException { + // Create the file system + final GenericFileName rootName = (GenericFileName) name; + + HttpClient httpClient = IvyWebdavClientFactory.createConnection(rootName.getHostName(), + rootName.getPort(), rootName.getUserName(), rootName.getPassword(), fileSystemOptions); + + return new IvyWebdavFileSystem(rootName, httpClient, fileSystemOptions); + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileSystem.java b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileSystem.java index 8b23d69a..63b726ad 100644 --- a/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileSystem.java +++ b/src/java/org/apache/ivy/plugins/repository/vfs/IvyWebdavFileSystem.java @@ -1,34 +1,34 @@ -/* - * 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.vfs; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.vfs.FileSystemOptions; -import org.apache.commons.vfs.provider.GenericFileName; -import org.apache.commons.vfs.provider.webdav.WebDavFileSystem; - -/** - * This class extends from WebDavFileSystem because it doesn't provide an accessible constructor. - */ -class IvyWebdavFileSystem extends WebDavFileSystem { - - protected IvyWebdavFileSystem(GenericFileName arg0, HttpClient arg1, FileSystemOptions arg2) { - super(arg0, arg1, arg2); - } - -} +/* + * 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.vfs; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.vfs.FileSystemOptions; +import org.apache.commons.vfs.provider.GenericFileName; +import org.apache.commons.vfs.provider.webdav.WebDavFileSystem; + +/** + * This class extends from WebDavFileSystem because it doesn't provide an accessible constructor. + */ +class IvyWebdavFileSystem extends WebDavFileSystem { + + protected IvyWebdavFileSystem(GenericFileName arg0, HttpClient arg1, FileSystemOptions arg2) { + super(arg0, arg1, arg2); + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java b/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java index a5ff1bca..785c414e 100644 --- a/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java @@ -1,216 +1,216 @@ -/* - * 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.vfs; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.vfs.FileContent; -import org.apache.commons.vfs.FileObject; -import org.apache.commons.vfs.FileSystemException; -import org.apache.commons.vfs.FileSystemManager; -import org.apache.commons.vfs.FileType; -import org.apache.commons.vfs.impl.StandardFileSystemManager; -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.CopyProgressListener; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; - -/** - * Implementation of a VFS repository - */ -public class VfsRepository extends AbstractRepository { - /** - * Name of the resource defining the Ivy VFS Repo configuration. - */ - private static final String IVY_VFS_CONFIG = "ivy_vfs.xml"; - - private StandardFileSystemManager _manager = null; - - private final CopyProgressListener _progress = new RepositoryCopyProgressListener(this); - - /** - * Create a new Ivy VFS Repository Instance - */ - public VfsRepository() { - } - - private FileSystemManager getVFSManager() throws IOException { - synchronized (this) { - if (_manager == null) { - _manager = createVFSManager(); - } - } - return _manager; - } - - private StandardFileSystemManager createVFSManager() throws IOException { - StandardFileSystemManager result = null; - try { - /* - * The DefaultFileSystemManager gets its configuration from the jakarta-vfs-common - * implementation which includes the res and tmp schemes which are of no use to use - * here. Using StandardFileSystemManager lets us specify which schemes to support as - * well as providing a mechanism to change this support without recompilation. - */ - result = new StandardFileSystemManager() { - protected void configurePlugins() throws FileSystemException { - // disable automatic loading potential unsupported extensions - } - }; - result.setConfiguration(getClass().getResource(IVY_VFS_CONFIG)); - result.init(); - - // Generate and print a list of available schemes - Message.verbose("Available VFS schemes..."); - String[] schemes = result.getSchemes(); - Arrays.sort(schemes); - for (int i = 0; i < schemes.length; i++) { - Message.verbose("VFS Supported Scheme: " + schemes[i]); - } - } catch (FileSystemException e) { - /* - * If our attempt to initialize a VFS Repository fails we log the failure but continue - * on. Given that an Ivy instance may involve numerous different repository types, it - * seems overly cautious to throw a runtime exception on the initialization failure of - * just one repository type. - */ - Message.error("Unable to initialize VFS repository manager!"); - Message.error(e.getLocalizedMessage()); - IOException error = new IOException(e.getLocalizedMessage()); - error.initCause(e); - throw error; - } - - return result; - } - - protected void finalize() { - if (_manager != null) { - _manager.close(); - _manager = null; - } - } - - /** - * Get a VfsResource - * - * @param source - * a String identifying a VFS Resource - * @throws IOException on failure - * @see "Supported File Systems in the jakarta-commons-vfs documentation" - */ - public Resource getResource(String vfsURI) throws IOException { - return new VfsResource(vfsURI, getVFSManager()); - } - - /** - * Transfer a VFS Resource from the repository to the local file system. - * - * @param srcVfsURI - * a String identifying the VFS resource to be fetched - * @param destination - * a File identifying the destination file - * @throws IOException on failure - * @see "Supported File Systems in the jakarta-commons-vfs documentation" - */ - public void get(String srcVfsURI, File destination) throws IOException { - VfsResource src = new VfsResource(srcVfsURI, getVFSManager()); - fireTransferInitiated(src, TransferEvent.REQUEST_GET); - try { - FileContent content = src.getContent(); - if (content == null) { - throw new IllegalArgumentException("invalid vfs uri " + srcVfsURI - + ": no content found"); - } - FileUtil.copy(content.getInputStream(), destination, _progress); - } catch (IOException ex) { - fireTransferError(ex); - throw ex; - } catch (RuntimeException ex) { - fireTransferError(ex); - throw ex; - } - } - - /** - * Return a listing of the contents of a parent directory. Listing is a set of strings - * representing VFS URIs. - * - * @param vfsURI - * providing identifying a VFS provided resource - * @throws IOException - * on failure. - * @see "Supported File Systems in the jakarta-commons-vfs documentation" - */ - public List list(String vfsURI) throws IOException { - ArrayList list = new ArrayList(); - Message.debug("list called for URI" + vfsURI); - FileObject resourceImpl = getVFSManager().resolveFile(vfsURI); - Message.debug("resourceImpl=" + resourceImpl.toString()); - Message.debug("resourceImpl.exists()" + resourceImpl.exists()); - Message.debug("resourceImpl.getType()" + resourceImpl.getType()); - Message.debug("FileType.FOLDER" + FileType.FOLDER); - if ((resourceImpl != null) && resourceImpl.exists() - && (resourceImpl.getType() == FileType.FOLDER)) { - FileObject[] children = resourceImpl.getChildren(); - for (int i = 0; i < children.length; i++) { - FileObject child = children[i]; - Message.debug("child " + i + child.getName().getURI()); - list.add(VfsResource.normalize(child.getName().getURI())); - } - } - return list; - } - - /** - * Transfer an Ivy resource to a VFS repository - * - * @param source - * a File indentifying the local file to transfer to the repository - * @param vfsURI - * a String identifying the destination VFS Resource. - * @param overwrite - * whether to overwrite an existing resource. - * @throws IOException on failure. - * @see "Supported File Systems in the jakarta-commons-vfs documentation" - */ - public void put(File source, String vfsURI, boolean overwrite) throws IOException { - VfsResource dest = new VfsResource(vfsURI, getVFSManager()); - fireTransferInitiated(dest, TransferEvent.REQUEST_PUT); - if (dest.physicallyExists() && !overwrite) { - throw new IOException("Cannot copy. Destination file: " + dest.getName() - + " exists and overwrite not set."); - } - if (dest.getContent() == null) { - throw new IllegalArgumentException("invalid vfs uri " + vfsURI - + " to put data to: resource has no content"); - } - - FileUtil.copy(new FileInputStream(source), dest.getContent().getOutputStream(), _progress); - } - -} +/* + * 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.vfs; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.vfs.FileContent; +import org.apache.commons.vfs.FileObject; +import org.apache.commons.vfs.FileSystemException; +import org.apache.commons.vfs.FileSystemManager; +import org.apache.commons.vfs.FileType; +import org.apache.commons.vfs.impl.StandardFileSystemManager; +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.CopyProgressListener; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; + +/** + * Implementation of a VFS repository + */ +public class VfsRepository extends AbstractRepository { + /** + * Name of the resource defining the Ivy VFS Repo configuration. + */ + private static final String IVY_VFS_CONFIG = "ivy_vfs.xml"; + + private StandardFileSystemManager _manager = null; + + private final CopyProgressListener _progress = new RepositoryCopyProgressListener(this); + + /** + * Create a new Ivy VFS Repository Instance + */ + public VfsRepository() { + } + + private FileSystemManager getVFSManager() throws IOException { + synchronized (this) { + if (_manager == null) { + _manager = createVFSManager(); + } + } + return _manager; + } + + private StandardFileSystemManager createVFSManager() throws IOException { + StandardFileSystemManager result = null; + try { + /* + * The DefaultFileSystemManager gets its configuration from the jakarta-vfs-common + * implementation which includes the res and tmp schemes which are of no use to use + * here. Using StandardFileSystemManager lets us specify which schemes to support as + * well as providing a mechanism to change this support without recompilation. + */ + result = new StandardFileSystemManager() { + protected void configurePlugins() throws FileSystemException { + // disable automatic loading potential unsupported extensions + } + }; + result.setConfiguration(getClass().getResource(IVY_VFS_CONFIG)); + result.init(); + + // Generate and print a list of available schemes + Message.verbose("Available VFS schemes..."); + String[] schemes = result.getSchemes(); + Arrays.sort(schemes); + for (int i = 0; i < schemes.length; i++) { + Message.verbose("VFS Supported Scheme: " + schemes[i]); + } + } catch (FileSystemException e) { + /* + * If our attempt to initialize a VFS Repository fails we log the failure but continue + * on. Given that an Ivy instance may involve numerous different repository types, it + * seems overly cautious to throw a runtime exception on the initialization failure of + * just one repository type. + */ + Message.error("Unable to initialize VFS repository manager!"); + Message.error(e.getLocalizedMessage()); + IOException error = new IOException(e.getLocalizedMessage()); + error.initCause(e); + throw error; + } + + return result; + } + + protected void finalize() { + if (_manager != null) { + _manager.close(); + _manager = null; + } + } + + /** + * Get a VfsResource + * + * @param source + * a String identifying a VFS Resource + * @throws IOException on failure + * @see "Supported File Systems in the jakarta-commons-vfs documentation" + */ + public Resource getResource(String vfsURI) throws IOException { + return new VfsResource(vfsURI, getVFSManager()); + } + + /** + * Transfer a VFS Resource from the repository to the local file system. + * + * @param srcVfsURI + * a String identifying the VFS resource to be fetched + * @param destination + * a File identifying the destination file + * @throws IOException on failure + * @see "Supported File Systems in the jakarta-commons-vfs documentation" + */ + public void get(String srcVfsURI, File destination) throws IOException { + VfsResource src = new VfsResource(srcVfsURI, getVFSManager()); + fireTransferInitiated(src, TransferEvent.REQUEST_GET); + try { + FileContent content = src.getContent(); + if (content == null) { + throw new IllegalArgumentException("invalid vfs uri " + srcVfsURI + + ": no content found"); + } + FileUtil.copy(content.getInputStream(), destination, _progress); + } catch (IOException ex) { + fireTransferError(ex); + throw ex; + } catch (RuntimeException ex) { + fireTransferError(ex); + throw ex; + } + } + + /** + * Return a listing of the contents of a parent directory. Listing is a set of strings + * representing VFS URIs. + * + * @param vfsURI + * providing identifying a VFS provided resource + * @throws IOException + * on failure. + * @see "Supported File Systems in the jakarta-commons-vfs documentation" + */ + public List list(String vfsURI) throws IOException { + ArrayList list = new ArrayList(); + Message.debug("list called for URI" + vfsURI); + FileObject resourceImpl = getVFSManager().resolveFile(vfsURI); + Message.debug("resourceImpl=" + resourceImpl.toString()); + Message.debug("resourceImpl.exists()" + resourceImpl.exists()); + Message.debug("resourceImpl.getType()" + resourceImpl.getType()); + Message.debug("FileType.FOLDER" + FileType.FOLDER); + if ((resourceImpl != null) && resourceImpl.exists() + && (resourceImpl.getType() == FileType.FOLDER)) { + FileObject[] children = resourceImpl.getChildren(); + for (int i = 0; i < children.length; i++) { + FileObject child = children[i]; + Message.debug("child " + i + child.getName().getURI()); + list.add(VfsResource.normalize(child.getName().getURI())); + } + } + return list; + } + + /** + * Transfer an Ivy resource to a VFS repository + * + * @param source + * a File indentifying the local file to transfer to the repository + * @param vfsURI + * a String identifying the destination VFS Resource. + * @param overwrite + * whether to overwrite an existing resource. + * @throws IOException on failure. + * @see "Supported File Systems in the jakarta-commons-vfs documentation" + */ + public void put(File source, String vfsURI, boolean overwrite) throws IOException { + VfsResource dest = new VfsResource(vfsURI, getVFSManager()); + fireTransferInitiated(dest, TransferEvent.REQUEST_PUT); + if (dest.physicallyExists() && !overwrite) { + throw new IOException("Cannot copy. Destination file: " + dest.getName() + + " exists and overwrite not set."); + } + if (dest.getContent() == null) { + throw new IllegalArgumentException("invalid vfs uri " + vfsURI + + " to put data to: resource has no content"); + } + + FileUtil.copy(new FileInputStream(source), dest.getContent().getOutputStream(), _progress); + } + +} diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java b/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java index 286f9e7f..d18321e3 100644 --- a/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java +++ b/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java @@ -1,205 +1,205 @@ -/* - * 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.vfs; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.vfs.FileContent; -import org.apache.commons.vfs.FileObject; -import org.apache.commons.vfs.FileSystemException; -import org.apache.commons.vfs.FileSystemManager; -import org.apache.commons.vfs.FileType; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.resolver.VfsResolver; -import org.apache.ivy.util.Message; - -/** - * VFS implementation of the Resource interface - */ -public class VfsResource implements Resource { - private String _vfsURI; - - private FileSystemManager _fsManager; - - private transient boolean _init = false; - - private transient boolean _exists; - - private transient long _lastModified; - - private transient long _contentLength; - - private transient FileContent _content = null; - - private transient FileObject _resourceImpl; - - // Constructor - public VfsResource(String vfsURI, FileSystemManager fsManager) { - this._vfsURI = vfsURI; - this._fsManager = fsManager; - this._init = false; - } - - private void init() { - if (!_init) { - try { - _resourceImpl = _fsManager.resolveFile(_vfsURI); - _content = _resourceImpl.getContent(); - - _exists = _resourceImpl.exists(); - _lastModified = _content.getLastModifiedTime(); - _contentLength = _content.getSize(); - } catch (FileSystemException e) { - Message.verbose(e.getLocalizedMessage()); - _exists = false; - _lastModified = 0; - _contentLength = 0; - } - - _init = true; - } - } - - /** - * Get a list of direct descendents of the given resource. Note that attempts to get a list of - * children does not result in an error. Instead an error message is - * logged and an empty ArrayList returned. - * - * @return A ArrayList of VFSResources - */ - public List getChildren() { - init(); - ArrayList list = new ArrayList(); - try { - if ((_resourceImpl != null) && _resourceImpl.exists() - && (_resourceImpl.getType() == FileType.FOLDER)) { - FileObject[] children = _resourceImpl.getChildren(); - for (int i = 0; i < children.length; i++) { - FileObject child = children[i]; - list.add(normalize(child.getName().getURI())); - } - } - } catch (IOException e) { - Message.verbose(e.getLocalizedMessage()); - } - return list; - } - - public FileContent getContent() { - init(); - return _content; - } - - /** - * Get the name of the resource. - * - * @return a String representing the Resource URL. - */ - public String getName() { - return normalize(_vfsURI); - } - - public Resource clone(String cloneName) { - return new VfsResource(cloneName, _fsManager); - } - - /** - * The VFS FileName getURI method seems to have a bug in it where file: URIs will have 4 forward - * slashes instead of 3. - * - * @param vfsURI - * @return a normalized String representing the VFS URI - */ - public static String normalize(String vfsURI) { - if (vfsURI == null) { - return ""; - } - - if (vfsURI.startsWith("file:////")) { - vfsURI = vfsURI.replaceFirst("////", "///"); - } - return vfsURI; - } - - /** - * Get the last modification time of the resource. - * - * @return a long indicating last modified time. - */ - public long getLastModified() { - init(); - return _lastModified; - } - - /** - * Get the size of the resource - * - * @return a long representing the size of the resource (in bytes). - */ - public long getContentLength() { - init(); - return _contentLength; - } - - /** - * Flag indicating whether a resource is available for querying - * - * @return true if the resource is available for querying, false - * otherwise. - */ - public boolean exists() { - init(); - return _exists; - } - - /** - * Return a flag indicating whether a provided VFS resource physically exists - * - * @return true if the resource physically exists, false - * otherwise. - */ - public boolean physicallyExists() { - // TODO: there is no need for this method anymore, replace it by calling exists(); - init(); - - try { - return _resourceImpl.exists(); - // originally I only checked for a FileSystemException. I expanded it to - // include all exceptions when I found it would throw a NPE exception when the query was - // run on non-wellformed VFS URI. - } catch (Exception e) { - Message.verbose(e.getLocalizedMessage()); - return false; - } - } - - public String toString() { - return VfsResolver.prepareForDisplay(getName()); - } - - public boolean isLocal() { - return getName().startsWith("file:"); - } - - public InputStream openStream() throws IOException { - return getContent().getInputStream(); - } -} +/* + * 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.vfs; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.vfs.FileContent; +import org.apache.commons.vfs.FileObject; +import org.apache.commons.vfs.FileSystemException; +import org.apache.commons.vfs.FileSystemManager; +import org.apache.commons.vfs.FileType; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.resolver.VfsResolver; +import org.apache.ivy.util.Message; + +/** + * VFS implementation of the Resource interface + */ +public class VfsResource implements Resource { + private String _vfsURI; + + private FileSystemManager _fsManager; + + private transient boolean _init = false; + + private transient boolean _exists; + + private transient long _lastModified; + + private transient long _contentLength; + + private transient FileContent _content = null; + + private transient FileObject _resourceImpl; + + // Constructor + public VfsResource(String vfsURI, FileSystemManager fsManager) { + this._vfsURI = vfsURI; + this._fsManager = fsManager; + this._init = false; + } + + private void init() { + if (!_init) { + try { + _resourceImpl = _fsManager.resolveFile(_vfsURI); + _content = _resourceImpl.getContent(); + + _exists = _resourceImpl.exists(); + _lastModified = _content.getLastModifiedTime(); + _contentLength = _content.getSize(); + } catch (FileSystemException e) { + Message.verbose(e.getLocalizedMessage()); + _exists = false; + _lastModified = 0; + _contentLength = 0; + } + + _init = true; + } + } + + /** + * Get a list of direct descendents of the given resource. Note that attempts to get a list of + * children does not result in an error. Instead an error message is + * logged and an empty ArrayList returned. + * + * @return A ArrayList of VFSResources + */ + public List getChildren() { + init(); + ArrayList list = new ArrayList(); + try { + if ((_resourceImpl != null) && _resourceImpl.exists() + && (_resourceImpl.getType() == FileType.FOLDER)) { + FileObject[] children = _resourceImpl.getChildren(); + for (int i = 0; i < children.length; i++) { + FileObject child = children[i]; + list.add(normalize(child.getName().getURI())); + } + } + } catch (IOException e) { + Message.verbose(e.getLocalizedMessage()); + } + return list; + } + + public FileContent getContent() { + init(); + return _content; + } + + /** + * Get the name of the resource. + * + * @return a String representing the Resource URL. + */ + public String getName() { + return normalize(_vfsURI); + } + + public Resource clone(String cloneName) { + return new VfsResource(cloneName, _fsManager); + } + + /** + * The VFS FileName getURI method seems to have a bug in it where file: URIs will have 4 forward + * slashes instead of 3. + * + * @param vfsURI + * @return a normalized String representing the VFS URI + */ + public static String normalize(String vfsURI) { + if (vfsURI == null) { + return ""; + } + + if (vfsURI.startsWith("file:////")) { + vfsURI = vfsURI.replaceFirst("////", "///"); + } + return vfsURI; + } + + /** + * Get the last modification time of the resource. + * + * @return a long indicating last modified time. + */ + public long getLastModified() { + init(); + return _lastModified; + } + + /** + * Get the size of the resource + * + * @return a long representing the size of the resource (in bytes). + */ + public long getContentLength() { + init(); + return _contentLength; + } + + /** + * Flag indicating whether a resource is available for querying + * + * @return true if the resource is available for querying, false + * otherwise. + */ + public boolean exists() { + init(); + return _exists; + } + + /** + * Return a flag indicating whether a provided VFS resource physically exists + * + * @return true if the resource physically exists, false + * otherwise. + */ + public boolean physicallyExists() { + // TODO: there is no need for this method anymore, replace it by calling exists(); + init(); + + try { + return _resourceImpl.exists(); + // originally I only checked for a FileSystemException. I expanded it to + // include all exceptions when I found it would throw a NPE exception when the query was + // run on non-wellformed VFS URI. + } catch (Exception e) { + Message.verbose(e.getLocalizedMessage()); + return false; + } + } + + public String toString() { + return VfsResolver.prepareForDisplay(getName()); + } + + public boolean isLocal() { + return getName().startsWith("file:"); + } + + public InputStream openStream() throws IOException { + return getContent().getInputStream(); + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/vfs/ivy_vfs.xml b/src/java/org/apache/ivy/plugins/repository/vfs/ivy_vfs.xml index 4ac878f6..55702506 100644 --- a/src/java/org/apache/ivy/plugins/repository/vfs/ivy_vfs.xml +++ b/src/java/org/apache/ivy/plugins/repository/vfs/ivy_vfs.xml @@ -1,56 +1,56 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java index 9203b94b..ccfc3a8a 100644 --- a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java @@ -1,698 +1,698 @@ -/* - * 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.vsftp; - -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.io.Reader; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.regex.Pattern; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyThread; -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.core.event.IvyListener; -import org.apache.ivy.core.event.resolve.EndResolveEvent; -import org.apache.ivy.plugins.repository.AbstractRepository; -import org.apache.ivy.plugins.repository.BasicResource; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.repository.TransferEvent; -import org.apache.ivy.util.Message; - -/** - * Repository using SecureCRT vsftp command line program to access an sftp repository This is - * especially useful to leverage the gssapi authentication supported by SecureCRT. In caseswhere - * usual sftp is enough, prefer the 100% java solution of sftp repository. This requires SecureCRT - * to be in the PATH. Tested with SecureCRT 5.0.5 - */ -public class VsftpRepository extends AbstractRepository { - private static final String PROMPT = "vsftp> "; - - private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MMM dd, yyyy HH:mm", - Locale.US); - - private String _host; - - private String _username; - - private String _authentication = "gssapi"; - - private Reader _in; - - private Reader _err; - - private PrintWriter _out; - - private volatile StringBuffer _errors = new StringBuffer(); - - private long _readTimeout = 30000; - - private long _reuseConnection = 5 * 60 * 1000; // reuse connection during 5 minutes by default - - private volatile long _lastCommand; - - private volatile boolean _inCommand; - - private Process _process; - - private Thread _connectionCleaner; - - private Thread _errorsReader; - - private volatile long _errorsLastUpdateTime; - - private Ivy _ivy = null; - - public Resource getResource(String source) throws IOException { - initIvy(); - return new VsftpResource(this, source); - } - - private void initIvy() { - _ivy = IvyContext.getContext().getIvy(); - } - - protected Resource getInitResource(String source) throws IOException { - try { - return lslToResource(source, sendCommand("ls -l " + source, true, true)); - } catch (IOException ex) { - cleanup(ex); - throw ex; - } finally { - cleanup(); - } - } - - public void get(final String source, File destination) throws IOException { - initIvy(); - try { - fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); - File destDir = destination.getParentFile(); - if (destDir != null) { - sendCommand("lcd " + destDir.getAbsolutePath()); - } - if (destination.exists()) { - destination.delete(); - } - - int index = source.lastIndexOf('/'); - String srcName = index == -1 ? source : source.substring(index + 1); - final File to = destDir == null ? new File(srcName) : new File(destDir, srcName); - - final IOException ex[] = new IOException[1]; - Thread get = new IvyThread() { - public void run() { - initContext(); - try { - sendCommand("get " + source, getExpectedDownloadMessage(source, to), 0); - } catch (IOException e) { - ex[0] = e; - } - } - }; - get.start(); - - long prevLength = 0; - long lastUpdate = System.currentTimeMillis(); - long timeout = _readTimeout; - while (get.isAlive()) { - checkInterrupted(); - long length = to.exists() ? to.length() : 0; - if (length > prevLength) { - fireTransferProgress(length - prevLength); - lastUpdate = System.currentTimeMillis(); - prevLength = length; - } else { - if (System.currentTimeMillis() - lastUpdate > timeout) { - Message.verbose("download hang for more than " + timeout - + "ms. Interrupting."); - get.interrupt(); - if (to.exists()) - to.delete(); - throw new IOException(source + " download timeout from " + getHost()); - } - } - try { - get.join(100); - } catch (InterruptedException e) { - if (to.exists()) - to.delete(); - return; - } - } - if (ex[0] != null) { - if (to.exists()) - to.delete(); - throw ex[0]; - } - - to.renameTo(destination); - fireTransferCompleted(destination.length()); - } catch (IOException ex) { - fireTransferError(ex); - cleanup(ex); - throw ex; - } finally { - cleanup(); - } - } - - public List list(String parent) throws IOException { - initIvy(); - try { - if (!parent.endsWith("/")) { - parent = parent + "/"; - } - String response = sendCommand("ls -l " + parent, true, true); - if (response.startsWith("ls")) { - return null; - } - String[] lines = response.split("\n"); - List ret = new ArrayList(lines.length); - for (int i = 0; i < lines.length; i++) { - while (lines[i].endsWith("\r") || lines[i].endsWith("\n")) { - lines[i] = lines[i].substring(0, lines[i].length() - 1); - } - if (lines[i].trim().length() != 0) { - ret.add(parent + lines[i].substring(lines[i].lastIndexOf(' ') + 1)); - } - } - return ret; - } catch (IOException ex) { - cleanup(ex); - throw ex; - } finally { - cleanup(); - } - } - - public void put(File source, String destination, boolean overwrite) throws IOException { - initIvy(); - try { - if (getResource(destination).exists()) { - if (overwrite) { - sendCommand("rm " + destination, getExpectedRemoveMessage(destination)); - } else { - return; - } - } - int index = destination.lastIndexOf('/'); - String destDir = null; - if (index != -1) { - destDir = destination.substring(0, index); - mkdirs(destDir); - sendCommand("cd " + destDir); - } - String to = destDir != null ? destDir + "/" + source.getName() : source.getName(); - sendCommand("put " + source.getAbsolutePath(), getExpectedUploadMessage(source, to), 0); - sendCommand("mv " + to + " " + destination); - } catch (IOException ex) { - cleanup(ex); - throw ex; - } finally { - cleanup(); - } - } - - private void mkdirs(String destDir) throws IOException { - if (dirExists(destDir)) { - return; - } - if (destDir.endsWith("/")) { - destDir = destDir.substring(0, destDir.length() - 1); - } - int index = destDir.lastIndexOf('/'); - if (index != -1) { - mkdirs(destDir.substring(0, index)); - ; - } - sendCommand("mkdir " + destDir); - } - - private boolean dirExists(String dir) throws IOException { - return !sendCommand("ls " + dir, true).startsWith("ls: "); - } - - protected String sendCommand(String command) throws IOException { - return sendCommand(command, false, _readTimeout); - } - - protected void sendCommand(String command, Pattern expectedResponse) throws IOException { - sendCommand(command, expectedResponse, _readTimeout); - } - - /** - * The behaviour of vsftp with some commands is to log the resulting message on the error - * stream, even if everything is ok. So it's quite difficult if there was an error or not. Hence - * we compare the response with the expected message and deal with it. The problem is that this - * is very specific to the version of vsftp used for the test, That's why expected messages are - * obtained using overridable protected methods. - */ - protected void sendCommand(String command, Pattern expectedResponse, long timeout) - throws IOException { - String response = sendCommand(command, true, timeout); - if (!expectedResponse.matcher(response).matches()) { - Message.debug("invalid response from server:"); - Message.debug("expected: '" + expectedResponse + "'"); - Message.debug("was: '" + response + "'"); - throw new IOException(response); - } - } - - protected String sendCommand(String command, boolean sendErrorAsResponse) throws IOException { - return sendCommand(command, sendErrorAsResponse, _readTimeout); - } - - protected String sendCommand(String command, boolean sendErrorAsResponse, boolean single) - throws IOException { - return sendCommand(command, sendErrorAsResponse, single, _readTimeout); - } - - protected String sendCommand(String command, boolean sendErrorAsResponse, long timeout) - throws IOException { - return sendCommand(command, sendErrorAsResponse, false, timeout); - } - - protected String sendCommand(String command, boolean sendErrorAsResponse, boolean single, - long timeout) throws IOException { - single = false; // use of alone commands does not work properly due to a long delay between - // end of process and end of stream... - - checkInterrupted(); - _inCommand = true; - _errorsLastUpdateTime = 0; - synchronized (this) { - if (!single || _in != null) { - ensureConnectionOpened(); - Message.debug("sending command '" + command + "' to " + getHost()); - updateLastCommandTime(); - _out.println(command); - _out.flush(); - } else { - sendSingleCommand(command); - } - } - - try { - return readResponse(sendErrorAsResponse, timeout); - } finally { - _inCommand = false; - if (single) { - closeConnection(); - } - } - } - - protected String readResponse(boolean sendErrorAsResponse) throws IOException { - return readResponse(sendErrorAsResponse, _readTimeout); - } - - protected synchronized String readResponse(final boolean sendErrorAsResponse, long timeout) - throws IOException { - final StringBuffer response = new StringBuffer(); - final IOException[] exc = new IOException[1]; - final boolean[] done = new boolean[1]; - Runnable r = new Runnable() { - public void run() { - synchronized (VsftpRepository.this) { - try { - int c; - boolean getPrompt = false; - // the reading is done in a for loop making five attempts to read the stream - // if we do not reach the next prompt - for (int attempts = 0; !getPrompt && attempts < 5; attempts++) { - while ((c = _in.read()) != -1) { - attempts = 0; // we manage to read something, reset numer of - // attempts - response.append((char) c); - if (response.length() >= PROMPT.length() - && response.substring(response.length() - PROMPT.length(), - response.length()).equals(PROMPT)) { - response.setLength(response.length() - PROMPT.length()); - getPrompt = true; - break; - } - } - if (!getPrompt) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - break; - } - } - } - if (getPrompt) { - // wait enough for error stream to be fully read - if (_errorsLastUpdateTime == 0) { - // no error written yet, but it may be pending... - _errorsLastUpdateTime = _lastCommand; - } - - while ((System.currentTimeMillis() - _errorsLastUpdateTime) < 50) { - try { - Thread.sleep(30); - } catch (InterruptedException e) { - break; - } - } - } - if (_errors.length() > 0) { - if (sendErrorAsResponse) { - response.append(_errors); - _errors.setLength(0); - } else { - throw new IOException(chomp(_errors).toString()); - } - } - chomp(response); - done[0] = true; - } catch (IOException e) { - exc[0] = e; - } finally { - VsftpRepository.this.notify(); - } - } - } - }; - Thread reader = null; - if (timeout == 0) { - r.run(); - } else { - reader = new IvyThread(r); - reader.start(); - try { - wait(timeout); - } catch (InterruptedException e) { - } - } - updateLastCommandTime(); - if (exc[0] != null) { - throw exc[0]; - } else if (!done[0]) { - if (reader != null && reader.isAlive()) { - reader.interrupt(); - for (int i = 0; i < 5 && reader.isAlive(); i++) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - break; - } - } - if (reader.isAlive()) { - reader.stop(); // no way to interrupt it non abruptly - } - } - throw new IOException("connection timeout to " + getHost()); - } else { - if ("Not connected.".equals(response)) { - Message.info("vsftp connection to " + getHost() + " reset"); - closeConnection(); - throw new IOException("not connected to " + getHost()); - } - Message.debug("received response '" + response + "' from " + getHost()); - return response.toString(); - } - } - - private synchronized void sendSingleCommand(String command) throws IOException { - exec(getSingleCommand(command)); - } - - protected synchronized void ensureConnectionOpened() throws IOException { - if (_in == null) { - Message.verbose("connecting to " + getUsername() + "@" + getHost() + "... "); - String connectionCommand = getConnectionCommand(); - exec(connectionCommand); - - try { - readResponse(false); // waits for first prompt - - if (_reuseConnection > 0) { - _connectionCleaner = new IvyThread() { - public void run() { - initContext(); - try { - long sleep = 10; - while (_in != null && sleep > 0) { - sleep(sleep); - sleep = _reuseConnection - - (System.currentTimeMillis() - _lastCommand); - if (_inCommand) { - sleep = sleep <= 0 ? _reuseConnection : sleep; - } - } - } catch (InterruptedException e) { - } - disconnect(); - } - }; - _connectionCleaner.start(); - } - - if (_ivy != null) { - _ivy.getEventManager().addIvyListener(new IvyListener() { - public void progress(IvyEvent event) { - disconnect(); - event.getSource().removeIvyListener(this); - } - }, EndResolveEvent.NAME); - } - - } catch (IOException ex) { - closeConnection(); - throw new IOException("impossible to connect to " + getUsername() + "@" + getHost() - + " using " + getAuthentication() + ": " + ex.getMessage()); - } - Message.verbose("connected to " + getHost()); - } - } - - private void updateLastCommandTime() { - _lastCommand = System.currentTimeMillis(); - } - - private void exec(String command) throws IOException { - Message.debug("launching '" + command + "'"); - _process = Runtime.getRuntime().exec(command); - _in = new InputStreamReader(_process.getInputStream()); - _err = new InputStreamReader(_process.getErrorStream()); - _out = new PrintWriter(_process.getOutputStream()); - - _errorsReader = new IvyThread() { - public void run() { - initContext(); - int c; - try { - while (_err != null && (c = _err.read()) != -1) { - _errors.append((char) c); - _errorsLastUpdateTime = System.currentTimeMillis(); - } - } catch (IOException e) { - } - } - }; - _errorsReader.start(); - } - - private void checkInterrupted() { - if (_ivy != null) { - _ivy.checkInterrupted(); - } - } - - /** - * Called whenever an api level method end - */ - private void cleanup(Exception ex) { - if (ex.getMessage().equals("connection timeout to " + getHost())) { - closeConnection(); - } else { - disconnect(); - } - } - - /** - * Called whenever an api level method end - */ - private void cleanup() { - if (_reuseConnection == 0) { - disconnect(); - } - } - - public synchronized void disconnect() { - if (_in != null) { - Message.verbose("disconnecting from " + getHost() + "... "); - try { - sendCommand("exit", false, 300); - } catch (IOException e) { - } finally { - closeConnection(); - Message.verbose("disconnected of " + getHost()); - } - } - } - - private synchronized void closeConnection() { - if (_connectionCleaner != null) { - _connectionCleaner.interrupt(); - } - if (_errorsReader != null) { - _errorsReader.interrupt(); - } - try { - _process.destroy(); - } catch (Exception ex) { - } - try { - _in.close(); - } catch (Exception e) { - } - try { - _err.close(); - } catch (Exception e) { - } - try { - _out.close(); - } catch (Exception e) { - } - - _connectionCleaner = null; - _errorsReader = null; - _process = null; - _in = null; - _out = null; - _err = null; - Message.debug("connection to " + getHost() + " closed"); - } - - /** - * Parses a ls -l line and transforms it in a resource - * - * @param file - * @param responseLine - * @return - */ - protected Resource lslToResource(String file, String responseLine) { - if (responseLine == null || responseLine.startsWith("ls")) { - return new BasicResource(file, false, 0, 0, false); - } else { - String[] parts = responseLine.split("\\s+"); - if (parts.length != 9) { - Message.debug("unrecognized ls format: " + responseLine); - return new BasicResource(file, false, 0, 0, false); - } else { - try { - long contentLength = Long.parseLong(parts[3]); - String date = parts[4] + " " + parts[5] + " " + parts[6] + " " + parts[7]; - return new BasicResource(file, true, contentLength, FORMAT.parse(date) - .getTime(), false); - } catch (Exception ex) { - Message - .warn("impossible to parse server response: " + responseLine + ": " - + ex); - return new BasicResource(file, false, 0, 0, false); - } - } - } - } - - protected String getSingleCommand(String command) { - return "vsh -noprompt -auth " + _authentication + " " + _username + "@" + _host + " " - + command; - } - - protected String getConnectionCommand() { - return "vsftp -noprompt -auth " + _authentication + " " + _username + "@" + _host; - } - - protected Pattern getExpectedDownloadMessage(String source, File to) { - return Pattern.compile("Downloading " + to.getName() + " from [^\\s]+"); - } - - protected Pattern getExpectedRemoveMessage(String destination) { - return Pattern.compile("Removing [^\\s]+"); - } - - protected Pattern getExpectedUploadMessage(File source, String to) { - return Pattern.compile("Uploading " + source.getName() + " to [^\\s]+"); - } - - public String getAuthentication() { - return _authentication; - } - - public void setAuthentication(String authentication) { - _authentication = authentication; - } - - public String getHost() { - return _host; - } - - public void setHost(String host) { - _host = host; - } - - public String getUsername() { - return _username; - } - - public void setUsername(String username) { - _username = username; - } - - private static StringBuffer chomp(StringBuffer str) { - if (str == null || str.length() == 0) { - return str; - } - while ("\n".equals(str.substring(str.length() - 1)) - || "\r".equals(str.substring(str.length() - 1))) { - str.setLength(str.length() - 1); - } - return str; - } - - public String toString() { - return getName() + " " + getUsername() + "@" + getHost() + " (" + getAuthentication() + ")"; - } - - /** - * Sets the reuse connection time. The same connection will be reused if the time here does not - * last between two commands. O indicates that the connection should never be reused - * - * @param time - */ - public void setReuseConnection(long time) { - _reuseConnection = time; - } - - public long getReadTimeout() { - return _readTimeout; - } - - public void setReadTimeout(long readTimeout) { - _readTimeout = readTimeout; - } -} +/* + * 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.vsftp; + +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.Reader; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.regex.Pattern; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyThread; +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.core.event.IvyListener; +import org.apache.ivy.core.event.resolve.EndResolveEvent; +import org.apache.ivy.plugins.repository.AbstractRepository; +import org.apache.ivy.plugins.repository.BasicResource; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.TransferEvent; +import org.apache.ivy.util.Message; + +/** + * Repository using SecureCRT vsftp command line program to access an sftp repository This is + * especially useful to leverage the gssapi authentication supported by SecureCRT. In caseswhere + * usual sftp is enough, prefer the 100% java solution of sftp repository. This requires SecureCRT + * to be in the PATH. Tested with SecureCRT 5.0.5 + */ +public class VsftpRepository extends AbstractRepository { + private static final String PROMPT = "vsftp> "; + + private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MMM dd, yyyy HH:mm", + Locale.US); + + private String _host; + + private String _username; + + private String _authentication = "gssapi"; + + private Reader _in; + + private Reader _err; + + private PrintWriter _out; + + private volatile StringBuffer _errors = new StringBuffer(); + + private long _readTimeout = 30000; + + private long _reuseConnection = 5 * 60 * 1000; // reuse connection during 5 minutes by default + + private volatile long _lastCommand; + + private volatile boolean _inCommand; + + private Process _process; + + private Thread _connectionCleaner; + + private Thread _errorsReader; + + private volatile long _errorsLastUpdateTime; + + private Ivy _ivy = null; + + public Resource getResource(String source) throws IOException { + initIvy(); + return new VsftpResource(this, source); + } + + private void initIvy() { + _ivy = IvyContext.getContext().getIvy(); + } + + protected Resource getInitResource(String source) throws IOException { + try { + return lslToResource(source, sendCommand("ls -l " + source, true, true)); + } catch (IOException ex) { + cleanup(ex); + throw ex; + } finally { + cleanup(); + } + } + + public void get(final String source, File destination) throws IOException { + initIvy(); + try { + fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET); + File destDir = destination.getParentFile(); + if (destDir != null) { + sendCommand("lcd " + destDir.getAbsolutePath()); + } + if (destination.exists()) { + destination.delete(); + } + + int index = source.lastIndexOf('/'); + String srcName = index == -1 ? source : source.substring(index + 1); + final File to = destDir == null ? new File(srcName) : new File(destDir, srcName); + + final IOException ex[] = new IOException[1]; + Thread get = new IvyThread() { + public void run() { + initContext(); + try { + sendCommand("get " + source, getExpectedDownloadMessage(source, to), 0); + } catch (IOException e) { + ex[0] = e; + } + } + }; + get.start(); + + long prevLength = 0; + long lastUpdate = System.currentTimeMillis(); + long timeout = _readTimeout; + while (get.isAlive()) { + checkInterrupted(); + long length = to.exists() ? to.length() : 0; + if (length > prevLength) { + fireTransferProgress(length - prevLength); + lastUpdate = System.currentTimeMillis(); + prevLength = length; + } else { + if (System.currentTimeMillis() - lastUpdate > timeout) { + Message.verbose("download hang for more than " + timeout + + "ms. Interrupting."); + get.interrupt(); + if (to.exists()) + to.delete(); + throw new IOException(source + " download timeout from " + getHost()); + } + } + try { + get.join(100); + } catch (InterruptedException e) { + if (to.exists()) + to.delete(); + return; + } + } + if (ex[0] != null) { + if (to.exists()) + to.delete(); + throw ex[0]; + } + + to.renameTo(destination); + fireTransferCompleted(destination.length()); + } catch (IOException ex) { + fireTransferError(ex); + cleanup(ex); + throw ex; + } finally { + cleanup(); + } + } + + public List list(String parent) throws IOException { + initIvy(); + try { + if (!parent.endsWith("/")) { + parent = parent + "/"; + } + String response = sendCommand("ls -l " + parent, true, true); + if (response.startsWith("ls")) { + return null; + } + String[] lines = response.split("\n"); + List ret = new ArrayList(lines.length); + for (int i = 0; i < lines.length; i++) { + while (lines[i].endsWith("\r") || lines[i].endsWith("\n")) { + lines[i] = lines[i].substring(0, lines[i].length() - 1); + } + if (lines[i].trim().length() != 0) { + ret.add(parent + lines[i].substring(lines[i].lastIndexOf(' ') + 1)); + } + } + return ret; + } catch (IOException ex) { + cleanup(ex); + throw ex; + } finally { + cleanup(); + } + } + + public void put(File source, String destination, boolean overwrite) throws IOException { + initIvy(); + try { + if (getResource(destination).exists()) { + if (overwrite) { + sendCommand("rm " + destination, getExpectedRemoveMessage(destination)); + } else { + return; + } + } + int index = destination.lastIndexOf('/'); + String destDir = null; + if (index != -1) { + destDir = destination.substring(0, index); + mkdirs(destDir); + sendCommand("cd " + destDir); + } + String to = destDir != null ? destDir + "/" + source.getName() : source.getName(); + sendCommand("put " + source.getAbsolutePath(), getExpectedUploadMessage(source, to), 0); + sendCommand("mv " + to + " " + destination); + } catch (IOException ex) { + cleanup(ex); + throw ex; + } finally { + cleanup(); + } + } + + private void mkdirs(String destDir) throws IOException { + if (dirExists(destDir)) { + return; + } + if (destDir.endsWith("/")) { + destDir = destDir.substring(0, destDir.length() - 1); + } + int index = destDir.lastIndexOf('/'); + if (index != -1) { + mkdirs(destDir.substring(0, index)); + ; + } + sendCommand("mkdir " + destDir); + } + + private boolean dirExists(String dir) throws IOException { + return !sendCommand("ls " + dir, true).startsWith("ls: "); + } + + protected String sendCommand(String command) throws IOException { + return sendCommand(command, false, _readTimeout); + } + + protected void sendCommand(String command, Pattern expectedResponse) throws IOException { + sendCommand(command, expectedResponse, _readTimeout); + } + + /** + * The behaviour of vsftp with some commands is to log the resulting message on the error + * stream, even if everything is ok. So it's quite difficult if there was an error or not. Hence + * we compare the response with the expected message and deal with it. The problem is that this + * is very specific to the version of vsftp used for the test, That's why expected messages are + * obtained using overridable protected methods. + */ + protected void sendCommand(String command, Pattern expectedResponse, long timeout) + throws IOException { + String response = sendCommand(command, true, timeout); + if (!expectedResponse.matcher(response).matches()) { + Message.debug("invalid response from server:"); + Message.debug("expected: '" + expectedResponse + "'"); + Message.debug("was: '" + response + "'"); + throw new IOException(response); + } + } + + protected String sendCommand(String command, boolean sendErrorAsResponse) throws IOException { + return sendCommand(command, sendErrorAsResponse, _readTimeout); + } + + protected String sendCommand(String command, boolean sendErrorAsResponse, boolean single) + throws IOException { + return sendCommand(command, sendErrorAsResponse, single, _readTimeout); + } + + protected String sendCommand(String command, boolean sendErrorAsResponse, long timeout) + throws IOException { + return sendCommand(command, sendErrorAsResponse, false, timeout); + } + + protected String sendCommand(String command, boolean sendErrorAsResponse, boolean single, + long timeout) throws IOException { + single = false; // use of alone commands does not work properly due to a long delay between + // end of process and end of stream... + + checkInterrupted(); + _inCommand = true; + _errorsLastUpdateTime = 0; + synchronized (this) { + if (!single || _in != null) { + ensureConnectionOpened(); + Message.debug("sending command '" + command + "' to " + getHost()); + updateLastCommandTime(); + _out.println(command); + _out.flush(); + } else { + sendSingleCommand(command); + } + } + + try { + return readResponse(sendErrorAsResponse, timeout); + } finally { + _inCommand = false; + if (single) { + closeConnection(); + } + } + } + + protected String readResponse(boolean sendErrorAsResponse) throws IOException { + return readResponse(sendErrorAsResponse, _readTimeout); + } + + protected synchronized String readResponse(final boolean sendErrorAsResponse, long timeout) + throws IOException { + final StringBuffer response = new StringBuffer(); + final IOException[] exc = new IOException[1]; + final boolean[] done = new boolean[1]; + Runnable r = new Runnable() { + public void run() { + synchronized (VsftpRepository.this) { + try { + int c; + boolean getPrompt = false; + // the reading is done in a for loop making five attempts to read the stream + // if we do not reach the next prompt + for (int attempts = 0; !getPrompt && attempts < 5; attempts++) { + while ((c = _in.read()) != -1) { + attempts = 0; // we manage to read something, reset numer of + // attempts + response.append((char) c); + if (response.length() >= PROMPT.length() + && response.substring(response.length() - PROMPT.length(), + response.length()).equals(PROMPT)) { + response.setLength(response.length() - PROMPT.length()); + getPrompt = true; + break; + } + } + if (!getPrompt) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + break; + } + } + } + if (getPrompt) { + // wait enough for error stream to be fully read + if (_errorsLastUpdateTime == 0) { + // no error written yet, but it may be pending... + _errorsLastUpdateTime = _lastCommand; + } + + while ((System.currentTimeMillis() - _errorsLastUpdateTime) < 50) { + try { + Thread.sleep(30); + } catch (InterruptedException e) { + break; + } + } + } + if (_errors.length() > 0) { + if (sendErrorAsResponse) { + response.append(_errors); + _errors.setLength(0); + } else { + throw new IOException(chomp(_errors).toString()); + } + } + chomp(response); + done[0] = true; + } catch (IOException e) { + exc[0] = e; + } finally { + VsftpRepository.this.notify(); + } + } + } + }; + Thread reader = null; + if (timeout == 0) { + r.run(); + } else { + reader = new IvyThread(r); + reader.start(); + try { + wait(timeout); + } catch (InterruptedException e) { + } + } + updateLastCommandTime(); + if (exc[0] != null) { + throw exc[0]; + } else if (!done[0]) { + if (reader != null && reader.isAlive()) { + reader.interrupt(); + for (int i = 0; i < 5 && reader.isAlive(); i++) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + break; + } + } + if (reader.isAlive()) { + reader.stop(); // no way to interrupt it non abruptly + } + } + throw new IOException("connection timeout to " + getHost()); + } else { + if ("Not connected.".equals(response)) { + Message.info("vsftp connection to " + getHost() + " reset"); + closeConnection(); + throw new IOException("not connected to " + getHost()); + } + Message.debug("received response '" + response + "' from " + getHost()); + return response.toString(); + } + } + + private synchronized void sendSingleCommand(String command) throws IOException { + exec(getSingleCommand(command)); + } + + protected synchronized void ensureConnectionOpened() throws IOException { + if (_in == null) { + Message.verbose("connecting to " + getUsername() + "@" + getHost() + "... "); + String connectionCommand = getConnectionCommand(); + exec(connectionCommand); + + try { + readResponse(false); // waits for first prompt + + if (_reuseConnection > 0) { + _connectionCleaner = new IvyThread() { + public void run() { + initContext(); + try { + long sleep = 10; + while (_in != null && sleep > 0) { + sleep(sleep); + sleep = _reuseConnection + - (System.currentTimeMillis() - _lastCommand); + if (_inCommand) { + sleep = sleep <= 0 ? _reuseConnection : sleep; + } + } + } catch (InterruptedException e) { + } + disconnect(); + } + }; + _connectionCleaner.start(); + } + + if (_ivy != null) { + _ivy.getEventManager().addIvyListener(new IvyListener() { + public void progress(IvyEvent event) { + disconnect(); + event.getSource().removeIvyListener(this); + } + }, EndResolveEvent.NAME); + } + + } catch (IOException ex) { + closeConnection(); + throw new IOException("impossible to connect to " + getUsername() + "@" + getHost() + + " using " + getAuthentication() + ": " + ex.getMessage()); + } + Message.verbose("connected to " + getHost()); + } + } + + private void updateLastCommandTime() { + _lastCommand = System.currentTimeMillis(); + } + + private void exec(String command) throws IOException { + Message.debug("launching '" + command + "'"); + _process = Runtime.getRuntime().exec(command); + _in = new InputStreamReader(_process.getInputStream()); + _err = new InputStreamReader(_process.getErrorStream()); + _out = new PrintWriter(_process.getOutputStream()); + + _errorsReader = new IvyThread() { + public void run() { + initContext(); + int c; + try { + while (_err != null && (c = _err.read()) != -1) { + _errors.append((char) c); + _errorsLastUpdateTime = System.currentTimeMillis(); + } + } catch (IOException e) { + } + } + }; + _errorsReader.start(); + } + + private void checkInterrupted() { + if (_ivy != null) { + _ivy.checkInterrupted(); + } + } + + /** + * Called whenever an api level method end + */ + private void cleanup(Exception ex) { + if (ex.getMessage().equals("connection timeout to " + getHost())) { + closeConnection(); + } else { + disconnect(); + } + } + + /** + * Called whenever an api level method end + */ + private void cleanup() { + if (_reuseConnection == 0) { + disconnect(); + } + } + + public synchronized void disconnect() { + if (_in != null) { + Message.verbose("disconnecting from " + getHost() + "... "); + try { + sendCommand("exit", false, 300); + } catch (IOException e) { + } finally { + closeConnection(); + Message.verbose("disconnected of " + getHost()); + } + } + } + + private synchronized void closeConnection() { + if (_connectionCleaner != null) { + _connectionCleaner.interrupt(); + } + if (_errorsReader != null) { + _errorsReader.interrupt(); + } + try { + _process.destroy(); + } catch (Exception ex) { + } + try { + _in.close(); + } catch (Exception e) { + } + try { + _err.close(); + } catch (Exception e) { + } + try { + _out.close(); + } catch (Exception e) { + } + + _connectionCleaner = null; + _errorsReader = null; + _process = null; + _in = null; + _out = null; + _err = null; + Message.debug("connection to " + getHost() + " closed"); + } + + /** + * Parses a ls -l line and transforms it in a resource + * + * @param file + * @param responseLine + * @return + */ + protected Resource lslToResource(String file, String responseLine) { + if (responseLine == null || responseLine.startsWith("ls")) { + return new BasicResource(file, false, 0, 0, false); + } else { + String[] parts = responseLine.split("\\s+"); + if (parts.length != 9) { + Message.debug("unrecognized ls format: " + responseLine); + return new BasicResource(file, false, 0, 0, false); + } else { + try { + long contentLength = Long.parseLong(parts[3]); + String date = parts[4] + " " + parts[5] + " " + parts[6] + " " + parts[7]; + return new BasicResource(file, true, contentLength, FORMAT.parse(date) + .getTime(), false); + } catch (Exception ex) { + Message + .warn("impossible to parse server response: " + responseLine + ": " + + ex); + return new BasicResource(file, false, 0, 0, false); + } + } + } + } + + protected String getSingleCommand(String command) { + return "vsh -noprompt -auth " + _authentication + " " + _username + "@" + _host + " " + + command; + } + + protected String getConnectionCommand() { + return "vsftp -noprompt -auth " + _authentication + " " + _username + "@" + _host; + } + + protected Pattern getExpectedDownloadMessage(String source, File to) { + return Pattern.compile("Downloading " + to.getName() + " from [^\\s]+"); + } + + protected Pattern getExpectedRemoveMessage(String destination) { + return Pattern.compile("Removing [^\\s]+"); + } + + protected Pattern getExpectedUploadMessage(File source, String to) { + return Pattern.compile("Uploading " + source.getName() + " to [^\\s]+"); + } + + public String getAuthentication() { + return _authentication; + } + + public void setAuthentication(String authentication) { + _authentication = authentication; + } + + public String getHost() { + return _host; + } + + public void setHost(String host) { + _host = host; + } + + public String getUsername() { + return _username; + } + + public void setUsername(String username) { + _username = username; + } + + private static StringBuffer chomp(StringBuffer str) { + if (str == null || str.length() == 0) { + return str; + } + while ("\n".equals(str.substring(str.length() - 1)) + || "\r".equals(str.substring(str.length() - 1))) { + str.setLength(str.length() - 1); + } + return str; + } + + public String toString() { + return getName() + " " + getUsername() + "@" + getHost() + " (" + getAuthentication() + ")"; + } + + /** + * Sets the reuse connection time. The same connection will be reused if the time here does not + * last between two commands. O indicates that the connection should never be reused + * + * @param time + */ + public void setReuseConnection(long time) { + _reuseConnection = time; + } + + public long getReadTimeout() { + return _readTimeout; + } + + public void setReadTimeout(long readTimeout) { + _readTimeout = readTimeout; + } +} diff --git a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java index 94cc9530..50d1c97e 100644 --- a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java +++ b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java @@ -1,56 +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. - * - */ -package org.apache.ivy.plugins.repository.vsftp; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.ivy.plugins.repository.LazyResource; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.util.Message; - -public class VsftpResource extends LazyResource { - private VsftpRepository _repository; - - public VsftpResource(VsftpRepository repository, String file) { - super(file); - _repository = repository; - } - - protected void init() { - try { - init(_repository.getInitResource(getName())); - } catch (IOException e) { - Message.verbose(e.toString()); - } - } - - public InputStream openStream() throws IOException { - throw new UnsupportedOperationException( - "vsftp resource does not support openStream operation"); - } - - public Resource clone(String cloneName) { - try { - return _repository.getResource(cloneName); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - -} +/* + * 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.vsftp; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.ivy.plugins.repository.LazyResource; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.util.Message; + +public class VsftpResource extends LazyResource { + private VsftpRepository _repository; + + public VsftpResource(VsftpRepository repository, String file) { + super(file); + _repository = repository; + } + + protected void init() { + try { + init(_repository.getInitResource(getName())); + } catch (IOException e) { + Message.verbose(e.toString()); + } + } + + public InputStream openStream() throws IOException { + throw new UnsupportedOperationException( + "vsftp resource does not support openStream operation"); + } + + public Resource clone(String cloneName) { + try { + return _repository.getResource(cloneName); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java b/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java index 547b5fa5..64a4b594 100644 --- a/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java @@ -1,315 +1,315 @@ -/* - * 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.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.IvySettingsAware; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.plugins.matcher.Matcher; -import org.apache.ivy.plugins.matcher.NoMatcher; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.namespace.NameSpaceHelper; -import org.apache.ivy.plugins.namespace.Namespace; -import org.apache.ivy.plugins.resolver.util.HasLatestStrategy; -import org.apache.ivy.util.Message; - -/** - * This abstract resolver only provides handling for resolver name - */ -public abstract class AbstractResolver implements DependencyResolver, IvySettingsAware, - HasLatestStrategy { - - /** - * True if parsed ivy files should be validated against xsd, false if they should not, null if - * default behaviour should be used - */ - private Boolean _validate = null; - - private String _name; - - private String _changingPattern; - - private String _changingMatcherName = PatternMatcher.EXACT_OR_REGEXP; - - private IvySettings _settings; - - /** - * The latest strategy to use to find latest among several artifacts - */ - private LatestStrategy _latestStrategy; - - private String _latestStrategyName; - - /** - * The namespace to which this resolver belongs - */ - private Namespace _namespace; - - private String _namespaceName; - - public IvySettings getSettings() { - return _settings; - } - - public void setSettings(IvySettings ivy) { - _settings = ivy; - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - /** - * this method should remove sensitive information from a location to be displayed in a log - * - * @param name - * location - * @return location with sensitive data replaced by stars - */ - public String hidePassword(String name) { - return name; - } - - protected boolean doValidate(ResolveData data) { - if (_validate != null) { - return _validate.booleanValue(); - } else { - return data.isValidate(); - } - } - - public boolean isValidate() { - return _validate == null ? true : _validate.booleanValue(); - } - - public void setValidate(boolean validate) { - _validate = Boolean.valueOf(validate); - } - - protected void checkInterrupted() { - IvyContext.getContext().getIvy().checkInterrupted(); - } - - public void reportFailure() { - Message.verbose("no failure report implemented by " + getName()); - } - - public void reportFailure(Artifact art) { - Message.verbose("no failure report implemented by " + getName()); - } - - public String[] listTokenValues(String token, Map otherTokenValues) { - return new String[0]; - } - - public OrganisationEntry[] listOrganisations() { - return new OrganisationEntry[0]; - } - - public ModuleEntry[] listModules(OrganisationEntry org) { - return new ModuleEntry[0]; - } - - public RevisionEntry[] listRevisions(ModuleEntry module) { - return new RevisionEntry[0]; - } - - public String toString() { - return getName(); - } - - public void dumpSettings() { - Message.verbose("\t" + getName() + " [" + getTypeName() + "]"); - Message.debug("\t\tchangingPattern: " + getChangingPattern()); - Message.debug("\t\tchangingMatcher: " + getChangingMatcherName()); - } - - public String getTypeName() { - return getClass().getName(); - } - - /** - * Default implementation actually download the artifact Subclasses should overwrite this to - * avoid the download - */ - public boolean exists(Artifact artifact) { - DownloadReport dr = download(new Artifact[] {artifact}, new DownloadOptions(getSettings(), - new CacheManager(getSettings(), getSettings().getDefaultCache()), null, true)); - ArtifactDownloadReport adr = dr.getArtifactReport(artifact); - return adr.getDownloadStatus() != DownloadStatus.FAILED; - } - - public LatestStrategy getLatestStrategy() { - if (_latestStrategy == null) { - if (getSettings() != null) { - if (_latestStrategyName != null && !"default".equals(_latestStrategyName)) { - _latestStrategy = getSettings().getLatestStrategy(_latestStrategyName); - if (_latestStrategy == null) { - Message.error("unknown latest strategy: " + _latestStrategyName); - _latestStrategy = getSettings().getDefaultLatestStrategy(); - } - } else { - _latestStrategy = getSettings().getDefaultLatestStrategy(); - Message.debug(getName() + ": no latest strategy defined: using default"); - } - } else { - throw new IllegalStateException( - "no ivy instance found: impossible to get a latest strategy without ivy instance"); - } - } - return _latestStrategy; - } - - public void setLatestStrategy(LatestStrategy latestStrategy) { - _latestStrategy = latestStrategy; - } - - public void setLatest(String strategyName) { - _latestStrategyName = strategyName; - } - - public String getLatest() { - if (_latestStrategyName == null) { - _latestStrategyName = "default"; - } - return _latestStrategyName; - } - - public Namespace getNamespace() { - if (_namespace == null) { - if (getSettings() != null) { - if (_namespaceName != null) { - _namespace = getSettings().getNamespace(_namespaceName); - if (_namespace == null) { - Message.error("unknown namespace: " + _namespaceName); - _namespace = getSettings().getSystemNamespace(); - } - } else { - _namespace = getSettings().getSystemNamespace(); - Message.debug(getName() + ": no namespace defined: using system"); - } - } else { - Message.verbose(getName() - + ": no namespace defined nor ivy instance: using system namespace"); - _namespace = Namespace.SYSTEM_NAMESPACE; - } - } - return _namespace; - } - - public void setNamespace(String namespaceName) { - _namespaceName = namespaceName; - } - - // Namespace conversion methods - protected ModuleDescriptor toSystem(ModuleDescriptor md) { - return NameSpaceHelper.toSystem(md, getNamespace()); - } - - protected Artifact fromSystem(Artifact artifact) { - return NameSpaceHelper.transform(artifact, getNamespace().getFromSystemTransformer()); - } - - protected Artifact toSystem(Artifact artifact) { - return NameSpaceHelper.transform(artifact, getNamespace().getToSystemTransformer()); - } - - protected ResolvedModuleRevision toSystem(ResolvedModuleRevision rmr) { - return NameSpaceHelper.toSystem(rmr, getNamespace()); - } - - protected ModuleRevisionId toSystem(ModuleRevisionId resolvedMrid) { - return getNamespace().getToSystemTransformer().transform(resolvedMrid); - } - - protected DependencyDescriptor fromSystem(DependencyDescriptor dd) { - return NameSpaceHelper.transform(dd, getNamespace().getFromSystemTransformer(), true); - } - - protected IvyNode getSystemNode(ResolveData data, ModuleRevisionId resolvedMrid) { - return data.getNode(toSystem(resolvedMrid)); - } - - protected ResolvedModuleRevision findModuleInCache(ResolveData data, ModuleRevisionId mrid) { - ResolvedModuleRevision moduleFromCache = data.getCacheManager().findModuleInCache( - toSystem(mrid), doValidate(data)); - if (moduleFromCache == null) { - return null; - } - if ((getName() == null ? moduleFromCache.getResolver().getName() == null : moduleFromCache - .getResolver() == null ? false : getName().equals( - moduleFromCache.getResolver().getName()))) { - return moduleFromCache; - } else { - Message.debug("found module in cache but with a different resolver: discarding: " - + moduleFromCache); - return null; - } - } - - public String getChangingMatcherName() { - return _changingMatcherName; - } - - public void setChangingMatcher(String changingMatcherName) { - _changingMatcherName = changingMatcherName; - } - - public String getChangingPattern() { - return _changingPattern; - } - - public void setChangingPattern(String changingPattern) { - _changingPattern = changingPattern; - } - - public Matcher getChangingMatcher() { - if (_changingPattern == null) { - return NoMatcher.INSTANCE; - } - PatternMatcher matcher = _settings.getMatcher(_changingMatcherName); - if (matcher == null) { - throw new IllegalStateException("unknown matcher '" + _changingMatcherName - + "'. It is set as changing matcher in " + this); - } - return matcher.getMatcher(_changingPattern); - } - -} +/* + * 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.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.IvySettingsAware; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.plugins.matcher.Matcher; +import org.apache.ivy.plugins.matcher.NoMatcher; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.namespace.NameSpaceHelper; +import org.apache.ivy.plugins.namespace.Namespace; +import org.apache.ivy.plugins.resolver.util.HasLatestStrategy; +import org.apache.ivy.util.Message; + +/** + * This abstract resolver only provides handling for resolver name + */ +public abstract class AbstractResolver implements DependencyResolver, IvySettingsAware, + HasLatestStrategy { + + /** + * True if parsed ivy files should be validated against xsd, false if they should not, null if + * default behaviour should be used + */ + private Boolean _validate = null; + + private String _name; + + private String _changingPattern; + + private String _changingMatcherName = PatternMatcher.EXACT_OR_REGEXP; + + private IvySettings _settings; + + /** + * The latest strategy to use to find latest among several artifacts + */ + private LatestStrategy _latestStrategy; + + private String _latestStrategyName; + + /** + * The namespace to which this resolver belongs + */ + private Namespace _namespace; + + private String _namespaceName; + + public IvySettings getSettings() { + return _settings; + } + + public void setSettings(IvySettings ivy) { + _settings = ivy; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + /** + * this method should remove sensitive information from a location to be displayed in a log + * + * @param name + * location + * @return location with sensitive data replaced by stars + */ + public String hidePassword(String name) { + return name; + } + + protected boolean doValidate(ResolveData data) { + if (_validate != null) { + return _validate.booleanValue(); + } else { + return data.isValidate(); + } + } + + public boolean isValidate() { + return _validate == null ? true : _validate.booleanValue(); + } + + public void setValidate(boolean validate) { + _validate = Boolean.valueOf(validate); + } + + protected void checkInterrupted() { + IvyContext.getContext().getIvy().checkInterrupted(); + } + + public void reportFailure() { + Message.verbose("no failure report implemented by " + getName()); + } + + public void reportFailure(Artifact art) { + Message.verbose("no failure report implemented by " + getName()); + } + + public String[] listTokenValues(String token, Map otherTokenValues) { + return new String[0]; + } + + public OrganisationEntry[] listOrganisations() { + return new OrganisationEntry[0]; + } + + public ModuleEntry[] listModules(OrganisationEntry org) { + return new ModuleEntry[0]; + } + + public RevisionEntry[] listRevisions(ModuleEntry module) { + return new RevisionEntry[0]; + } + + public String toString() { + return getName(); + } + + public void dumpSettings() { + Message.verbose("\t" + getName() + " [" + getTypeName() + "]"); + Message.debug("\t\tchangingPattern: " + getChangingPattern()); + Message.debug("\t\tchangingMatcher: " + getChangingMatcherName()); + } + + public String getTypeName() { + return getClass().getName(); + } + + /** + * Default implementation actually download the artifact Subclasses should overwrite this to + * avoid the download + */ + public boolean exists(Artifact artifact) { + DownloadReport dr = download(new Artifact[] {artifact}, new DownloadOptions(getSettings(), + new CacheManager(getSettings(), getSettings().getDefaultCache()), null, true)); + ArtifactDownloadReport adr = dr.getArtifactReport(artifact); + return adr.getDownloadStatus() != DownloadStatus.FAILED; + } + + public LatestStrategy getLatestStrategy() { + if (_latestStrategy == null) { + if (getSettings() != null) { + if (_latestStrategyName != null && !"default".equals(_latestStrategyName)) { + _latestStrategy = getSettings().getLatestStrategy(_latestStrategyName); + if (_latestStrategy == null) { + Message.error("unknown latest strategy: " + _latestStrategyName); + _latestStrategy = getSettings().getDefaultLatestStrategy(); + } + } else { + _latestStrategy = getSettings().getDefaultLatestStrategy(); + Message.debug(getName() + ": no latest strategy defined: using default"); + } + } else { + throw new IllegalStateException( + "no ivy instance found: impossible to get a latest strategy without ivy instance"); + } + } + return _latestStrategy; + } + + public void setLatestStrategy(LatestStrategy latestStrategy) { + _latestStrategy = latestStrategy; + } + + public void setLatest(String strategyName) { + _latestStrategyName = strategyName; + } + + public String getLatest() { + if (_latestStrategyName == null) { + _latestStrategyName = "default"; + } + return _latestStrategyName; + } + + public Namespace getNamespace() { + if (_namespace == null) { + if (getSettings() != null) { + if (_namespaceName != null) { + _namespace = getSettings().getNamespace(_namespaceName); + if (_namespace == null) { + Message.error("unknown namespace: " + _namespaceName); + _namespace = getSettings().getSystemNamespace(); + } + } else { + _namespace = getSettings().getSystemNamespace(); + Message.debug(getName() + ": no namespace defined: using system"); + } + } else { + Message.verbose(getName() + + ": no namespace defined nor ivy instance: using system namespace"); + _namespace = Namespace.SYSTEM_NAMESPACE; + } + } + return _namespace; + } + + public void setNamespace(String namespaceName) { + _namespaceName = namespaceName; + } + + // Namespace conversion methods + protected ModuleDescriptor toSystem(ModuleDescriptor md) { + return NameSpaceHelper.toSystem(md, getNamespace()); + } + + protected Artifact fromSystem(Artifact artifact) { + return NameSpaceHelper.transform(artifact, getNamespace().getFromSystemTransformer()); + } + + protected Artifact toSystem(Artifact artifact) { + return NameSpaceHelper.transform(artifact, getNamespace().getToSystemTransformer()); + } + + protected ResolvedModuleRevision toSystem(ResolvedModuleRevision rmr) { + return NameSpaceHelper.toSystem(rmr, getNamespace()); + } + + protected ModuleRevisionId toSystem(ModuleRevisionId resolvedMrid) { + return getNamespace().getToSystemTransformer().transform(resolvedMrid); + } + + protected DependencyDescriptor fromSystem(DependencyDescriptor dd) { + return NameSpaceHelper.transform(dd, getNamespace().getFromSystemTransformer(), true); + } + + protected IvyNode getSystemNode(ResolveData data, ModuleRevisionId resolvedMrid) { + return data.getNode(toSystem(resolvedMrid)); + } + + protected ResolvedModuleRevision findModuleInCache(ResolveData data, ModuleRevisionId mrid) { + ResolvedModuleRevision moduleFromCache = data.getCacheManager().findModuleInCache( + toSystem(mrid), doValidate(data)); + if (moduleFromCache == null) { + return null; + } + if ((getName() == null ? moduleFromCache.getResolver().getName() == null : moduleFromCache + .getResolver() == null ? false : getName().equals( + moduleFromCache.getResolver().getName()))) { + return moduleFromCache; + } else { + Message.debug("found module in cache but with a different resolver: discarding: " + + moduleFromCache); + return null; + } + } + + public String getChangingMatcherName() { + return _changingMatcherName; + } + + public void setChangingMatcher(String changingMatcherName) { + _changingMatcherName = changingMatcherName; + } + + public String getChangingPattern() { + return _changingPattern; + } + + public void setChangingPattern(String changingPattern) { + _changingPattern = changingPattern; + } + + public Matcher getChangingMatcher() { + if (_changingPattern == null) { + return NoMatcher.INSTANCE; + } + PatternMatcher matcher = _settings.getMatcher(_changingMatcherName); + if (matcher == null) { + throw new IllegalStateException("unknown matcher '" + _changingMatcherName + + "'. It is set as changing matcher in " + this); + } + return matcher.getMatcher(_changingPattern); + } + +} diff --git a/src/java/org/apache/ivy/plugins/resolver/AbstractResourceResolver.java b/src/java/org/apache/ivy/plugins/resolver/AbstractResourceResolver.java index 8e957471..886e1a7a 100644 --- a/src/java/org/apache/ivy/plugins/resolver/AbstractResourceResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/AbstractResourceResolver.java @@ -1,280 +1,280 @@ -/* - * 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.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.settings.IvyPattern; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.plugins.resolver.util.MDResolvedResource; -import org.apache.ivy.plugins.resolver.util.ResolvedResource; -import org.apache.ivy.plugins.resolver.util.ResourceMDParser; -import org.apache.ivy.plugins.version.VersionMatcher; -import org.apache.ivy.util.Message; - -/** - * - */ -public abstract class AbstractResourceResolver extends BasicResolver { - - private static final Map IVY_ARTIFACT_ATTRIBUTES = new HashMap(); - static { - IVY_ARTIFACT_ATTRIBUTES.put(IvyPatternHelper.ARTIFACT_KEY, "ivy"); - IVY_ARTIFACT_ATTRIBUTES.put(IvyPatternHelper.TYPE_KEY, "ivy"); - IVY_ARTIFACT_ATTRIBUTES.put(IvyPatternHelper.EXT_KEY, "xml"); - } - - private List _ivyPatterns = new ArrayList(); // List (String pattern) - - private List _artifactPatterns = new ArrayList(); // List (String pattern) - - private boolean _m2compatible = false; - - public AbstractResourceResolver() { - } - - protected ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data) { - ModuleRevisionId mrid = dd.getDependencyRevisionId(); - if (isM2compatible()) { - mrid = convertM2IdForResourceSearch(mrid); - } - return findResourceUsingPatterns(mrid, _ivyPatterns, DefaultArtifact.newIvyArtifact(mrid, - data.getDate()), getRMDParser(dd, data), data.getDate()); - } - - protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { - ModuleRevisionId mrid = artifact.getModuleRevisionId(); - if (isM2compatible()) { - mrid = convertM2IdForResourceSearch(mrid); - } - return findResourceUsingPatterns(mrid, _artifactPatterns, artifact, - getDefaultRMDParser(artifact.getModuleRevisionId().getModuleId()), date); - } - - protected ResolvedResource findResourceUsingPatterns(ModuleRevisionId moduleRevision, - List patternList, Artifact artifact, ResourceMDParser rmdparser, Date date) { - ResolvedResource rres = null; - - List resolvedResources = new ArrayList(); - boolean dynamic = getSettings().getVersionMatcher().isDynamic(moduleRevision); - boolean stop = false; - for (Iterator iter = patternList.iterator(); iter.hasNext() && !stop;) { - String pattern = (String) iter.next(); - rres = findResourceUsingPattern(moduleRevision, pattern, artifact, rmdparser, date); - if (rres != null) { - resolvedResources.add(rres); - stop = !dynamic; // stop iterating if we are not searching a dynamic revision - } - } - - if (resolvedResources.size() > 1) { - ResolvedResource[] rress = (ResolvedResource[]) resolvedResources - .toArray(new ResolvedResource[resolvedResources.size()]); - rres = findResource(rress, getName(), getLatestStrategy(), getSettings() - .getVersionMatcher(), rmdparser, moduleRevision, date); - } - - return rres; - } - - protected abstract ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, - String pattern, Artifact artifact, ResourceMDParser rmdparser, Date date); - - public static ResolvedResource findResource(ResolvedResource[] rress, String name, - LatestStrategy strategy, VersionMatcher versionMatcher, ResourceMDParser rmdparser, - ModuleRevisionId mrid, Date date) { - ResolvedResource found = null; - List sorted = strategy.sort(rress); - List rejected = new ArrayList(); - for (ListIterator iter = sorted.listIterator(sorted.size()); iter.hasPrevious();) { - ResolvedResource rres = (ResolvedResource) iter.previous(); - if ((date != null && rres.getLastModified() > date.getTime())) { - Message.verbose("\t" + name + ": too young: " + rres); - rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")"); - continue; - } - ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision()); - if (!versionMatcher.accept(mrid, foundMrid)) { - Message.debug("\t" + name + ": rejected by version matcher: " + rres); - rejected.add(rres.getRevision()); - continue; - } - if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) { - ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision()); - ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision() - .getDescriptor(); - if (md.isDefault()) { - Message - .debug("\t" - + name - + ": default md rejected by version matcher requiring module descriptor: " - + rres); - rejected.add(rres.getRevision() + " (MD)"); - continue; - } else if (!versionMatcher.accept(mrid, md)) { - Message.debug("\t" + name + ": md rejected by version matcher: " + rres); - rejected.add(rres.getRevision() + " (MD)"); - continue; - } else { - found = r; - } - } else { - found = rres; - } - - if (found != null) { - if (!found.getResource().exists()) { - Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res=" - + found.getResource()); - logAttempt(found.getResource().toString()); - continue; - } - break; - } - } - if (found == null && !rejected.isEmpty()) { - logAttempt(rejected.toString()); - } - - return found; - } - - protected Collection findNames(Map tokenValues, String token) { - Collection names = new HashSet(); - names.addAll(findIvyNames(tokenValues, token)); - if (isAllownomd()) { - names.addAll(findArtifactNames(tokenValues, token)); - } - return names; - } - - protected Collection findIvyNames(Map tokenValues, String token) { - Collection names = new HashSet(); - tokenValues = new HashMap(tokenValues); - tokenValues.put(IvyPatternHelper.ARTIFACT_KEY, "ivy"); - tokenValues.put(IvyPatternHelper.TYPE_KEY, "ivy"); - tokenValues.put(IvyPatternHelper.EXT_KEY, "xml"); - findTokenValues(names, getIvyPatterns(), tokenValues, token); - getSettings().filterIgnore(names); - return names; - } - - protected Collection findArtifactNames(Map tokenValues, String token) { - Collection names = new HashSet(); - tokenValues = new HashMap(tokenValues); - tokenValues - .put(IvyPatternHelper.ARTIFACT_KEY, tokenValues.get(IvyPatternHelper.MODULE_KEY)); - tokenValues.put(IvyPatternHelper.TYPE_KEY, "jar"); - tokenValues.put(IvyPatternHelper.EXT_KEY, "jar"); - findTokenValues(names, getArtifactPatterns(), tokenValues, token); - getSettings().filterIgnore(names); - return names; - } - - // should be overridden by subclasses wanting to have listing features - protected void findTokenValues(Collection names, List patterns, Map tokenValues, String token) { - } - - /** - * example of pattern : ~/Workspace/[module]/[module].ivy.xml - * - * @param pattern - */ - public void addIvyPattern(String pattern) { - _ivyPatterns.add(pattern); - } - - public void addArtifactPattern(String pattern) { - _artifactPatterns.add(pattern); - } - - public List getIvyPatterns() { - return Collections.unmodifiableList(_ivyPatterns); - } - - public List getArtifactPatterns() { - return Collections.unmodifiableList(_artifactPatterns); - } - - protected void setIvyPatterns(List ivyPatterns) { - _ivyPatterns = ivyPatterns; - } - - protected void setArtifactPatterns(List artifactPatterns) { - _artifactPatterns = artifactPatterns; - } - - /* - * Methods respecting ivy conf method specifications - */ - public void addConfiguredIvy(IvyPattern p) { - _ivyPatterns.add(p.getPattern()); - } - - public void addConfiguredArtifact(IvyPattern p) { - _artifactPatterns.add(p.getPattern()); - } - - public void dumpSettings() { - super.dumpSettings(); - Message.debug("\t\tm2compatible: " + isM2compatible()); - Message.debug("\t\tivy patterns:"); - for (ListIterator iter = getIvyPatterns().listIterator(); iter.hasNext();) { - String p = (String) iter.next(); - Message.debug("\t\t\t" + p); - } - Message.debug("\t\tartifact patterns:"); - for (ListIterator iter = getArtifactPatterns().listIterator(); iter.hasNext();) { - String p = (String) iter.next(); - Message.debug("\t\t\t" + p); - } - } - - public boolean isM2compatible() { - return _m2compatible; - } - - public void setM2compatible(boolean m2compatible) { - _m2compatible = m2compatible; - } - - protected ModuleRevisionId convertM2IdForResourceSearch(ModuleRevisionId mrid) { - if (mrid.getOrganisation().indexOf('.') == -1) { - return mrid; - } - return ModuleRevisionId.newInstance(mrid.getOrganisation().replace('.', '/'), mrid - .getName(), mrid.getBranch(), mrid.getRevision(), mrid.getExtraAttributes()); - } - -} +/* + * 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.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.settings.IvyPattern; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.plugins.resolver.util.MDResolvedResource; +import org.apache.ivy.plugins.resolver.util.ResolvedResource; +import org.apache.ivy.plugins.resolver.util.ResourceMDParser; +import org.apache.ivy.plugins.version.VersionMatcher; +import org.apache.ivy.util.Message; + +/** + * + */ +public abstract class AbstractResourceResolver extends BasicResolver { + + private static final Map IVY_ARTIFACT_ATTRIBUTES = new HashMap(); + static { + IVY_ARTIFACT_ATTRIBUTES.put(IvyPatternHelper.ARTIFACT_KEY, "ivy"); + IVY_ARTIFACT_ATTRIBUTES.put(IvyPatternHelper.TYPE_KEY, "ivy"); + IVY_ARTIFACT_ATTRIBUTES.put(IvyPatternHelper.EXT_KEY, "xml"); + } + + private List _ivyPatterns = new ArrayList(); // List (String pattern) + + private List _artifactPatterns = new ArrayList(); // List (String pattern) + + private boolean _m2compatible = false; + + public AbstractResourceResolver() { + } + + protected ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data) { + ModuleRevisionId mrid = dd.getDependencyRevisionId(); + if (isM2compatible()) { + mrid = convertM2IdForResourceSearch(mrid); + } + return findResourceUsingPatterns(mrid, _ivyPatterns, DefaultArtifact.newIvyArtifact(mrid, + data.getDate()), getRMDParser(dd, data), data.getDate()); + } + + protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { + ModuleRevisionId mrid = artifact.getModuleRevisionId(); + if (isM2compatible()) { + mrid = convertM2IdForResourceSearch(mrid); + } + return findResourceUsingPatterns(mrid, _artifactPatterns, artifact, + getDefaultRMDParser(artifact.getModuleRevisionId().getModuleId()), date); + } + + protected ResolvedResource findResourceUsingPatterns(ModuleRevisionId moduleRevision, + List patternList, Artifact artifact, ResourceMDParser rmdparser, Date date) { + ResolvedResource rres = null; + + List resolvedResources = new ArrayList(); + boolean dynamic = getSettings().getVersionMatcher().isDynamic(moduleRevision); + boolean stop = false; + for (Iterator iter = patternList.iterator(); iter.hasNext() && !stop;) { + String pattern = (String) iter.next(); + rres = findResourceUsingPattern(moduleRevision, pattern, artifact, rmdparser, date); + if (rres != null) { + resolvedResources.add(rres); + stop = !dynamic; // stop iterating if we are not searching a dynamic revision + } + } + + if (resolvedResources.size() > 1) { + ResolvedResource[] rress = (ResolvedResource[]) resolvedResources + .toArray(new ResolvedResource[resolvedResources.size()]); + rres = findResource(rress, getName(), getLatestStrategy(), getSettings() + .getVersionMatcher(), rmdparser, moduleRevision, date); + } + + return rres; + } + + protected abstract ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, + String pattern, Artifact artifact, ResourceMDParser rmdparser, Date date); + + public static ResolvedResource findResource(ResolvedResource[] rress, String name, + LatestStrategy strategy, VersionMatcher versionMatcher, ResourceMDParser rmdparser, + ModuleRevisionId mrid, Date date) { + ResolvedResource found = null; + List sorted = strategy.sort(rress); + List rejected = new ArrayList(); + for (ListIterator iter = sorted.listIterator(sorted.size()); iter.hasPrevious();) { + ResolvedResource rres = (ResolvedResource) iter.previous(); + if ((date != null && rres.getLastModified() > date.getTime())) { + Message.verbose("\t" + name + ": too young: " + rres); + rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")"); + continue; + } + ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision()); + if (!versionMatcher.accept(mrid, foundMrid)) { + Message.debug("\t" + name + ": rejected by version matcher: " + rres); + rejected.add(rres.getRevision()); + continue; + } + if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) { + ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision()); + ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision() + .getDescriptor(); + if (md.isDefault()) { + Message + .debug("\t" + + name + + ": default md rejected by version matcher requiring module descriptor: " + + rres); + rejected.add(rres.getRevision() + " (MD)"); + continue; + } else if (!versionMatcher.accept(mrid, md)) { + Message.debug("\t" + name + ": md rejected by version matcher: " + rres); + rejected.add(rres.getRevision() + " (MD)"); + continue; + } else { + found = r; + } + } else { + found = rres; + } + + if (found != null) { + if (!found.getResource().exists()) { + Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res=" + + found.getResource()); + logAttempt(found.getResource().toString()); + continue; + } + break; + } + } + if (found == null && !rejected.isEmpty()) { + logAttempt(rejected.toString()); + } + + return found; + } + + protected Collection findNames(Map tokenValues, String token) { + Collection names = new HashSet(); + names.addAll(findIvyNames(tokenValues, token)); + if (isAllownomd()) { + names.addAll(findArtifactNames(tokenValues, token)); + } + return names; + } + + protected Collection findIvyNames(Map tokenValues, String token) { + Collection names = new HashSet(); + tokenValues = new HashMap(tokenValues); + tokenValues.put(IvyPatternHelper.ARTIFACT_KEY, "ivy"); + tokenValues.put(IvyPatternHelper.TYPE_KEY, "ivy"); + tokenValues.put(IvyPatternHelper.EXT_KEY, "xml"); + findTokenValues(names, getIvyPatterns(), tokenValues, token); + getSettings().filterIgnore(names); + return names; + } + + protected Collection findArtifactNames(Map tokenValues, String token) { + Collection names = new HashSet(); + tokenValues = new HashMap(tokenValues); + tokenValues + .put(IvyPatternHelper.ARTIFACT_KEY, tokenValues.get(IvyPatternHelper.MODULE_KEY)); + tokenValues.put(IvyPatternHelper.TYPE_KEY, "jar"); + tokenValues.put(IvyPatternHelper.EXT_KEY, "jar"); + findTokenValues(names, getArtifactPatterns(), tokenValues, token); + getSettings().filterIgnore(names); + return names; + } + + // should be overridden by subclasses wanting to have listing features + protected void findTokenValues(Collection names, List patterns, Map tokenValues, String token) { + } + + /** + * example of pattern : ~/Workspace/[module]/[module].ivy.xml + * + * @param pattern + */ + public void addIvyPattern(String pattern) { + _ivyPatterns.add(pattern); + } + + public void addArtifactPattern(String pattern) { + _artifactPatterns.add(pattern); + } + + public List getIvyPatterns() { + return Collections.unmodifiableList(_ivyPatterns); + } + + public List getArtifactPatterns() { + return Collections.unmodifiableList(_artifactPatterns); + } + + protected void setIvyPatterns(List ivyPatterns) { + _ivyPatterns = ivyPatterns; + } + + protected void setArtifactPatterns(List artifactPatterns) { + _artifactPatterns = artifactPatterns; + } + + /* + * Methods respecting ivy conf method specifications + */ + public void addConfiguredIvy(IvyPattern p) { + _ivyPatterns.add(p.getPattern()); + } + + public void addConfiguredArtifact(IvyPattern p) { + _artifactPatterns.add(p.getPattern()); + } + + public void dumpSettings() { + super.dumpSettings(); + Message.debug("\t\tm2compatible: " + isM2compatible()); + Message.debug("\t\tivy patterns:"); + for (ListIterator iter = getIvyPatterns().listIterator(); iter.hasNext();) { + String p = (String) iter.next(); + Message.debug("\t\t\t" + p); + } + Message.debug("\t\tartifact patterns:"); + for (ListIterator iter = getArtifactPatterns().listIterator(); iter.hasNext();) { + String p = (String) iter.next(); + Message.debug("\t\t\t" + p); + } + } + + public boolean isM2compatible() { + return _m2compatible; + } + + public void setM2compatible(boolean m2compatible) { + _m2compatible = m2compatible; + } + + protected ModuleRevisionId convertM2IdForResourceSearch(ModuleRevisionId mrid) { + if (mrid.getOrganisation().indexOf('.') == -1) { + return mrid; + } + return ModuleRevisionId.newInstance(mrid.getOrganisation().replace('.', '/'), mrid + .getName(), mrid.getBranch(), mrid.getRevision(), mrid.getExtraAttributes()); + } + +} diff --git a/src/java/org/apache/ivy/plugins/resolver/AbstractSshBasedResolver.java b/src/java/org/apache/ivy/plugins/resolver/AbstractSshBasedResolver.java index 9893e156..4aa624c2 100644 --- a/src/java/org/apache/ivy/plugins/resolver/AbstractSshBasedResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/AbstractSshBasedResolver.java @@ -134,4 +134,4 @@ public abstract class AbstractSshBasedResolver extends RepositoryResolver { } abstract public String getTypeName(); -} \ No newline at end of file +} diff --git a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java index 069c9d71..5d55c02e 100644 --- a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java @@ -1,1042 +1,1042 @@ -/* - * 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.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.cache.ArtifactOrigin; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.event.download.EndArtifactDownloadEvent; -import org.apache.ivy.core.event.download.NeedArtifactEvent; -import org.apache.ivy.core.event.download.StartArtifactDownloadEvent; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DefaultModuleRevision; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.plugins.parser.ModuleDescriptorParser; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.repository.ResourceHelper; -import org.apache.ivy.plugins.repository.url.URLRepository; -import org.apache.ivy.plugins.repository.url.URLResource; -import org.apache.ivy.plugins.resolver.util.MDResolvedResource; -import org.apache.ivy.plugins.resolver.util.ResolvedResource; -import org.apache.ivy.plugins.resolver.util.ResourceMDParser; -import org.apache.ivy.util.ChecksumHelper; -import org.apache.ivy.util.HostUtil; -import org.apache.ivy.util.Message; - -/** - * - */ -public abstract class BasicResolver extends AbstractResolver { - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); - - protected String _workspaceName; - - /** - * True if the files resolved are dependent of the environment from which they have been - * resolved, false otherwise. In general, relative paths are dependent of the environment, and - * absolute paths including machine reference are not. - */ - private boolean _envDependent = true; - - private List _ivyattempts = new ArrayList(); - - private Map _artattempts = new HashMap(); - - private Boolean _checkmodified = null; - - private boolean _checkconsistency = true; - - private boolean _allownomd = true; - - private String _checksums = null; - - private URLRepository _extartifactrep = new URLRepository(); // used only to download - - // external artifacts - - public BasicResolver() { - _workspaceName = HostUtil.getLocalHostName(); - } - - public String getWorkspaceName() { - return _workspaceName; - } - - public void setWorkspaceName(String workspaceName) { - _workspaceName = workspaceName; - } - - public boolean isEnvDependent() { - return _envDependent; - } - - public void setEnvDependent(boolean envDependent) { - _envDependent = envDependent; - } - - /** - * True if this resolver should check lastmodified date to know if ivy files are up to date. - * - * @return - */ - public boolean isCheckmodified() { - if (_checkmodified == null) { - if (getSettings() != null) { - String check = getSettings().getVariable("ivy.resolver.default.check.modified"); - return check != null ? Boolean.valueOf(check).booleanValue() : false; - } else { - return false; - } - } else { - return _checkmodified.booleanValue(); - } - } - - public void setCheckmodified(boolean check) { - _checkmodified = Boolean.valueOf(check); - } - - public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException { - IvyContext.getContext().pushResolver(this); - try { - DependencyDescriptor systemDd = dd; - dd = fromSystem(dd); - - clearIvyAttempts(); - clearArtifactAttempts(); - boolean downloaded = false; - boolean searched = false; - ModuleRevisionId mrid = dd.getDependencyRevisionId(); - // check revision - int index = mrid.getRevision().indexOf("@"); - if (index != -1 && !mrid.getRevision().substring(index + 1).equals(_workspaceName)) { - Message.verbose("\t" + getName() + ": unhandled revision => " + mrid.getRevision()); - return null; - } - - boolean isDynamic = getSettings().getVersionMatcher().isDynamic(mrid); - if (isDynamic && !acceptLatest()) { - Message.error("dynamic revisions not handled by " + getClass().getName() - + ". impossible to resolve " + mrid); - return null; - } - - boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision()); - boolean isChangingDependency = isChangingRevision || dd.isChanging(); - - // if we do not have to check modified and if the revision is exact and not changing, - // we first search for it in cache - ResolvedModuleRevision cachedRmr = null; - boolean checkedCache = false; - if (!isDynamic && !isCheckmodified() && !isChangingDependency) { - cachedRmr = findModuleInCache(data, mrid); - checkedCache = true; - if (cachedRmr != null) { - if (cachedRmr.getDescriptor().isDefault() && cachedRmr.getResolver() != this) { - Message.verbose("\t" + getName() + ": found revision in cache: " + mrid - + " (resolved by " + cachedRmr.getResolver().getName() - + "): but it's a default one, maybe we can find a better one"); - } else { - Message.verbose("\t" + getName() + ": revision in cache: " + mrid); - return toSystem(cachedRmr); - } - } - } - checkInterrupted(); - URL cachedIvyURL = null; - ResolvedResource ivyRef = findIvyFileRef(dd, data); - checkInterrupted(); - searched = true; - - // get module descriptor - ModuleDescriptorParser parser; - ModuleDescriptor md; - ModuleDescriptor systemMd = null; - if (ivyRef == null) { - if (!isAllownomd()) { - Message.verbose("\t" + getName() + ": no ivy file found for " + mrid); - return null; - } - parser = XmlModuleDescriptorParser.getInstance(); - md = DefaultModuleDescriptor.newDefaultInstance(mrid, dd - .getAllDependencyArtifacts()); - ResolvedResource artifactRef = findFirstArtifactRef(md, dd, data); - checkInterrupted(); - if (artifactRef == null) { - Message.verbose("\t" + getName() + ": no ivy file nor artifact found for " - + mrid); - String[] conf = md.getConfigurationsNames(); - for (int i = 0; i < conf.length; i++) { - Artifact[] artifacts = md.getArtifacts(conf[i]); - for (int j = 0; j < artifacts.length; j++) { - } - } - if (!checkedCache) { - cachedRmr = findModuleInCache(data, mrid); - } - if (cachedRmr != null) { - Message.verbose("\t" + getName() + ": revision in cache: " + mrid); - return toSystem(cachedRmr); - } - return null; - } else { - long lastModified = artifactRef.getLastModified(); - if (lastModified != 0 && md instanceof DefaultModuleDescriptor) { - ((DefaultModuleDescriptor) md).setLastModified(lastModified); - } - Message.verbose("\t" + getName() + ": no ivy file found for " + mrid - + ": using default data"); - if (isDynamic) { - md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(mrid, - artifactRef.getRevision())); - } - } - } else { - ResolvedModuleRevision rmr = null; - if (ivyRef instanceof MDResolvedResource) { - rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision(); - } - if (rmr == null) { - rmr = parse(ivyRef, dd, data); - if (rmr == null) { - return null; - } - } - if (!rmr.isDownloaded()) { - return toSystem(rmr); - } else { - md = rmr.getDescriptor(); - parser = ModuleDescriptorParserRegistry.getInstance().getParser( - ivyRef.getResource()); - cachedIvyURL = rmr.getLocalMDUrl(); - - // check descriptor data is in sync with resource revision and names - systemMd = toSystem(md); - if (_checkconsistency) { - checkDescriptorConsistency(mrid, md, ivyRef); - checkDescriptorConsistency(systemDd.getDependencyRevisionId(), systemMd, - ivyRef); - } else { - if (md instanceof DefaultModuleDescriptor) { - String revision = getRevision(ivyRef, mrid, md); - ((DefaultModuleDescriptor) md).setModuleRevisionId(ModuleRevisionId - .newInstance(mrid, revision)); - } else { - Message - .warn("consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done"); - checkDescriptorConsistency(mrid, md, ivyRef); - checkDescriptorConsistency(systemDd.getDependencyRevisionId(), - systemMd, ivyRef); - } - } - } - } - - if (systemMd == null) { - systemMd = toSystem(md); - } - - // resolve revision - ModuleRevisionId resolvedMrid = mrid; - if (isDynamic) { - resolvedMrid = md.getResolvedModuleRevisionId(); - if (resolvedMrid.getRevision() == null || resolvedMrid.getRevision().length() == 0) { - if (ivyRef.getRevision() == null || ivyRef.getRevision().length() == 0) { - resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, "working@" - + getName()); - } else { - resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, ivyRef - .getRevision()); - } - } - Message.verbose("\t\t[" + resolvedMrid.getRevision() + "] " + mrid.getModuleId()); - } - md.setResolvedModuleRevisionId(resolvedMrid); - systemMd.setResolvedModuleRevisionId(toSystem(resolvedMrid)); // keep system md in - // sync with md - - // check module descriptor revision - if (!getSettings().getVersionMatcher().accept(mrid, md)) { - Message.info("\t" + getName() + ": unacceptable revision => was=" - + md.getModuleRevisionId().getRevision() + " required=" - + mrid.getRevision()); - return null; - } - - // resolve and check publication date - if (data.getDate() != null) { - long pubDate = getPublicationDate(md, dd, data); - if (pubDate > data.getDate().getTime()) { - Message.info("\t" + getName() + ": unacceptable publication date => was=" - + new Date(pubDate) + " required=" + data.getDate()); - return null; - } else if (pubDate == -1) { - Message.info("\t" + getName() - + ": impossible to guess publication date: artifact missing for " - + mrid); - return null; - } - md.setResolvedPublicationDate(new Date(pubDate)); - systemMd.setResolvedPublicationDate(new Date(pubDate)); // keep system md in sync - // with md - } - - try { - File ivyFile = data.getCacheManager().getIvyFileInCache( - systemMd.getResolvedModuleRevisionId()); - if (ivyRef == null) { - // a basic ivy file is written containing default data - XmlModuleDescriptorWriter.write(systemMd, ivyFile); - } else { - if (md instanceof DefaultModuleDescriptor) { - DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md; - if (data.getSettings().logNotConvertedExclusionRule() - && dmd.isNamespaceUseful()) { - Message - .warn("the module descriptor " - + ivyRef.getResource() - + " has information which can't be converted into the system namespace. It will require the availability of the namespace '" - + getNamespace().getName() + "' to be fully usable."); - } - } - // copy and update ivy file from source to cache - parser.toIvyFile(cachedIvyURL.openStream(), ivyRef.getResource(), ivyFile, - systemMd); - long repLastModified = ivyRef.getLastModified(); - if (repLastModified > 0) { - ivyFile.setLastModified(repLastModified); - } - } - } catch (Exception e) { - if (ivyRef == null) { - Message.warn("impossible to create ivy file in cache for module : " - + resolvedMrid); - } else { - e.printStackTrace(); - Message.warn("impossible to copy ivy file to cache : " + ivyRef.getResource()); - } - } - - data.getCacheManager().saveResolver(systemMd, getName()); - data.getCacheManager().saveArtResolver(systemMd, getName()); - return new DefaultModuleRevision(this, this, systemMd, searched, downloaded, - cachedIvyURL); - } finally { - IvyContext.getContext().popResolver(); - } - } - - private String getRevision(ResolvedResource ivyRef, ModuleRevisionId askedMrid, - ModuleDescriptor md) throws ParseException { - String revision = ivyRef.getRevision(); - if (revision == null) { - Message.debug("no revision found in reference for " + askedMrid); - if (getSettings().getVersionMatcher().isDynamic(askedMrid)) { - if (md.getModuleRevisionId().getRevision() == null) { - return "working@" + getName(); - } else { - Message.debug("using " + askedMrid); - revision = md.getModuleRevisionId().getRevision(); - } - } else { - Message.debug("using " + askedMrid); - revision = askedMrid.getRevision(); - } - } - return revision; - } - - public ResolvedModuleRevision parse(ResolvedResource ivyRef, DependencyDescriptor dd, - ResolveData data) throws ParseException { - - ModuleRevisionId mrid = dd.getDependencyRevisionId(); - ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser( - ivyRef.getResource()); - if (parser == null) { - Message.warn("no module descriptor parser available for " + ivyRef.getResource()); - return null; - } - Message.verbose("\t" + getName() + ": found md file for " + mrid); - Message.verbose("\t\t=> " + ivyRef); - Message.debug("\tparser = " + parser); - - boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision()); - boolean isChangingDependency = isChangingRevision || dd.isChanging(); - Date cachedPublicationDate = null; - ModuleRevisionId resolvedMrid = mrid; - - // first check if this dependency has not yet been resolved - if (getSettings().getVersionMatcher().isDynamic(mrid)) { - resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef.getRevision()); - IvyNode node = getSystemNode(data, resolvedMrid); - if (node != null && node.getModuleRevision() != null) { - // this revision has already be resolved : return it - if (node.getDescriptor() != null && node.getDescriptor().isDefault()) { - Message.verbose("\t" + getName() + ": found already resolved revision: " - + resolvedMrid - + ": but it's a default one, maybe we can find a better one"); - } else { - Message.verbose("\t" + getName() + ": revision already resolved: " - + resolvedMrid); - return searchedRmr(node.getModuleRevision()); - } - } - } - - // now let's see if we can find it in cache and if it is up to date - ResolvedModuleRevision rmr = findModuleInCache(data, resolvedMrid); - if (rmr != null) { - if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) { - Message.verbose("\t" + getName() + ": found revision in cache: " + mrid - + " (resolved by " + rmr.getResolver().getName() - + "): but it's a default one, maybe we can find a better one"); - } else { - if (!isCheckmodified() && !isChangingDependency) { - Message.verbose("\t" + getName() + ": revision in cache: " + mrid); - return searchedRmr(rmr); - } - long repLastModified = ivyRef.getLastModified(); - long cacheLastModified = rmr.getDescriptor().getLastModified(); - if (!rmr.getDescriptor().isDefault() && repLastModified <= cacheLastModified) { - Message.verbose("\t" + getName() + ": revision in cache (not updated): " - + resolvedMrid); - return searchedRmr(rmr); - } else { - Message.verbose("\t" + getName() + ": revision in cache is not up to date: " - + resolvedMrid); - if (isChangingDependency) { - // ivy file has been updated, we should see if it has a new publication date - // to see if a new download is required (in case the dependency is a - // changing one) - cachedPublicationDate = rmr.getDescriptor().getResolvedPublicationDate(); - } - } - } - } - - // now download ivy file and parse it - URL cachedIvyURL = null; - File ivyTempFile = null; - try { - // first check if source file is not cache file itself - if (ResourceHelper.equals(ivyRef.getResource(), data.getCacheManager() - .getIvyFileInCache(toSystem(resolvedMrid)))) { - Message.error("invalid configuration for resolver '" + getName() - + "': pointing ivy files to ivy cache is forbidden !"); - return null; - } - - // temp file is used to prevent downloading twice - ivyTempFile = File.createTempFile("ivy", "xml"); - ivyTempFile.deleteOnExit(); - Message.debug("\t" + getName() + ": downloading " + ivyRef.getResource() + " to " - + ivyTempFile); - getAndCheck(ivyRef.getResource(), ivyTempFile); - try { - cachedIvyURL = ivyTempFile.toURL(); - } catch (MalformedURLException ex) { - Message.warn("malformed url exception for temp file: " + ivyTempFile + ": " - + ex.getMessage()); - return null; - } - } catch (IOException ex) { - Message.warn("problem while downloading ivy file: " + ivyRef.getResource() + " to " - + ivyTempFile + ": " + ex.getMessage()); - return null; - } - try { - ModuleDescriptor md = parser.parseDescriptor(data.getSettings(), cachedIvyURL, ivyRef - .getResource(), doValidate(data)); - Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid + " parsed=" - + md.getModuleRevisionId()); - - // check if we should delete old artifacts - boolean deleteOldArtifacts = false; - if (cachedPublicationDate != null - && !cachedPublicationDate.equals(md.getResolvedPublicationDate())) { - // artifacts have changed, they should be downloaded again - Message.verbose(dd + " has changed: deleting old artifacts"); - deleteOldArtifacts = true; - } - if (deleteOldArtifacts) { - String[] confs = rmr.getDescriptor().getConfigurationsNames(); - for (int i = 0; i < confs.length; i++) { - Artifact[] arts = rmr.getDescriptor().getArtifacts(confs[i]); - for (int j = 0; j < arts.length; j++) { - Artifact transformedArtifact = toSystem(arts[j]); - ArtifactOrigin origin = data.getCacheManager().getSavedArtifactOrigin( - transformedArtifact); - File artFile = data.getCacheManager().getArchiveFileInCache( - transformedArtifact, origin, false); - if (artFile.exists()) { - Message.debug("deleting " + artFile); - artFile.delete(); - } - data.getCacheManager().removeSavedArtifactOrigin(transformedArtifact); - } - } - } else if (isChangingDependency) { - Message.verbose(dd - + " is changing, but has not changed: will trust cached artifacts if any"); - } - return new DefaultModuleRevision(this, this, md, true, true, cachedIvyURL); - } catch (IOException ex) { - Message.warn("io problem while parsing ivy file: " + ivyRef.getResource() + ": " - + ex.getMessage()); - return null; - } - - } - - protected ResourceMDParser getRMDParser(final DependencyDescriptor dd, final ResolveData data) { - return new ResourceMDParser() { - public MDResolvedResource parse(Resource resource, String rev) { - try { - ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource( - resource, rev), dd, data); - if (rmr == null) { - return null; - } else { - return new MDResolvedResource(resource, rev, rmr); - } - } catch (ParseException e) { - return null; - } - } - - }; - } - - protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) { - return new ResourceMDParser() { - public MDResolvedResource parse(Resource resource, String rev) { - return new MDResolvedResource(resource, rev, new DefaultModuleRevision( - BasicResolver.this, BasicResolver.this, DefaultModuleDescriptor - .newDefaultInstance(new ModuleRevisionId(mid, rev)), false, false, - null)); - } - }; - } - - // private boolean isResolved(ResolveData data, ModuleRevisionId mrid) { - // IvyNode node = getSystemNode(data, mrid); - // return node != null && node.getModuleRevision() != null; - // } - // - private void checkDescriptorConsistency(ModuleRevisionId mrid, ModuleDescriptor md, - ResolvedResource ivyRef) throws ParseException { - boolean ok = true; - StringBuffer errors = new StringBuffer(); - if (!mrid.getOrganisation().equals(md.getModuleRevisionId().getOrganisation())) { - Message.error("\t" + getName() + ": bad organisation found in " + ivyRef.getResource() - + ": expected='" + mrid.getOrganisation() + "' found='" - + md.getModuleRevisionId().getOrganisation() + "'"); - errors.append("bad organisation: expected='" + mrid.getOrganisation() + "' found='" - + md.getModuleRevisionId().getOrganisation() + "'; "); - ok = false; - } - if (!mrid.getName().equals(md.getModuleRevisionId().getName())) { - Message.error("\t" + getName() + ": bad module name found in " + ivyRef.getResource() - + ": expected='" + mrid.getName() + " found='" - + md.getModuleRevisionId().getName() + "'"); - errors.append("bad module name: expected='" + mrid.getName() + "' found='" - + md.getModuleRevisionId().getName() + "'; "); - ok = false; - } - if (ivyRef.getRevision() != null && !ivyRef.getRevision().startsWith("working@")) { - ModuleRevisionId expectedMrid = ModuleRevisionId - .newInstance(mrid, ivyRef.getRevision()); - if (!getSettings().getVersionMatcher().accept(expectedMrid, md)) { - Message.error("\t" + getName() + ": bad revision found in " + ivyRef.getResource() - + ": expected='" + ivyRef.getRevision() + " found='" - + md.getModuleRevisionId().getRevision() + "'"); - errors.append("bad revision: expected='" + ivyRef.getRevision() + "' found='" - + md.getModuleRevisionId().getRevision() + "'; "); - ok = false; - } - } - if (!getSettings().getStatusManager().isStatus(md.getStatus())) { - Message.error("\t" + getName() + ": bad status found in " + ivyRef.getResource() - + ": '" + md.getStatus() + "'"); - errors.append("bad status: '" + md.getStatus() + "'; "); - ok = false; - } - if (!ok) { - throw new ParseException("inconsistent module descriptor file found in '" - + ivyRef.getResource() + "': " + errors, 0); - } - } - - protected void clearIvyAttempts() { - _ivyattempts.clear(); - clearArtifactAttempts(); - } - - protected ResolvedModuleRevision searchedRmr(final ResolvedModuleRevision rmr) { - // delegate all to previously found except isSearched - return new ResolvedModuleRevision() { - public boolean isSearched() { - return true; - } - - public boolean isDownloaded() { - return rmr.isDownloaded(); - } - - public ModuleDescriptor getDescriptor() { - return rmr.getDescriptor(); - } - - public Date getPublicationDate() { - return rmr.getPublicationDate(); - } - - public ModuleRevisionId getId() { - return rmr.getId(); - } - - public DependencyResolver getResolver() { - return rmr.getResolver(); - } - - public DependencyResolver getArtifactResolver() { - return rmr.getArtifactResolver(); - } - - public URL getLocalMDUrl() { - return rmr.getLocalMDUrl(); - } - }; - } - - protected void logIvyAttempt(String attempt) { - _ivyattempts.add(attempt); - Message.verbose("\t\ttried " + attempt); - } - - protected void logArtifactAttempt(Artifact art, String attempt) { - List attempts = (List) _artattempts.get(art); - if (attempts == null) { - attempts = new ArrayList(); - _artattempts.put(art, attempts); - } - attempts.add(attempt); - Message.verbose("\t\ttried " + attempt); - } - - protected static void logAttempt(String attempt) { - DependencyResolver resolver = IvyContext.getContext().getResolver(); - if (resolver instanceof BasicResolver) { - Artifact currentArtifact = (Artifact) IvyContext.getContext().get( - resolver.getName() + ".artifact"); - if (currentArtifact != null) { - ((BasicResolver) resolver).logArtifactAttempt(currentArtifact, attempt); - } else { - ((BasicResolver) resolver).logIvyAttempt(attempt); - } - } - } - - public void reportFailure() { - Message.warn("==== " + getName() + ": tried"); - for (ListIterator iter = _ivyattempts.listIterator(); iter.hasNext();) { - String m = (String) iter.next(); - Message.warn(" " + m); - } - for (Iterator iter = _artattempts.keySet().iterator(); iter.hasNext();) { - Artifact art = (Artifact) iter.next(); - List attempts = (List) _artattempts.get(art); - if (attempts != null) { - Message.warn(" -- artifact " + art + ":"); - for (ListIterator iterator = attempts.listIterator(); iterator.hasNext();) { - String m = (String) iterator.next(); - Message.warn(" " + m); - } - } - } - } - - public void reportFailure(Artifact art) { - Message.warn("==== " + getName() + ": tried"); - List attempts = (List) _artattempts.get(art); - if (attempts != null) { - for (ListIterator iter = attempts.listIterator(); iter.hasNext();) { - String m = (String) iter.next(); - Message.warn(" " + m); - } - } - } - - protected boolean acceptLatest() { - return true; - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - IvyContext.getContext().pushResolver(this); - try { - CacheManager cacheManager = options.getCacheManager(); - EventManager eventManager = options.getEventManager(); - - boolean useOrigin = options.isUseOrigin(); - - clearArtifactAttempts(); - DownloadReport dr = new DownloadReport(); - for (int i = 0; i < artifacts.length; i++) { - final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]); - dr.addArtifactReport(adr); - if (eventManager != null) { - eventManager.fireIvyEvent(new NeedArtifactEvent(this, artifacts[i])); - } - ArtifactOrigin origin = cacheManager.getSavedArtifactOrigin(artifacts[i]); - // if we can use origin file, we just ask ivy for the file in cache, and it will - // return - // the original one if possible. If we are not in useOrigin mode, we use the - // getArchivePath - // method which always return a path in the actual cache - File archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], origin, options - .isUseOrigin()); - - if (archiveFile.exists()) { - Message.verbose("\t[NOT REQUIRED] " + artifacts[i]); - adr.setDownloadStatus(DownloadStatus.NO); - adr.setSize(archiveFile.length()); - adr.setArtifactOrigin(origin); - } else { - Artifact artifact = fromSystem(artifacts[i]); - if (!artifact.equals(artifacts[i])) { - Message.verbose("\t" + getName() + "looking for artifact " + artifact - + " (is " + artifacts[i] + " in system namespace)"); - } - long start = System.currentTimeMillis(); - try { - ResolvedResource artifactRef = getArtifactRef(artifact, null); - if (artifactRef != null) { - origin = new ArtifactOrigin(artifactRef.getResource().isLocal(), - artifactRef.getResource().getName()); - if (useOrigin && artifactRef.getResource().isLocal()) { - Message.verbose("\t[NOT REQUIRED] " + artifacts[i]); - cacheManager.saveArtifactOrigin(artifacts[i], origin); - archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], - origin); - adr.setDownloadStatus(DownloadStatus.NO); - adr.setSize(archiveFile.length()); - adr.setArtifactOrigin(origin); - } else { - // refresh archive file now that we better now its origin - archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], - origin, useOrigin); - if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) { - Message.error("invalid configuration for resolver '" - + getName() - + "': pointing artifacts to ivy cache is forbidden !"); - return null; - } - Message.info("downloading " + artifactRef.getResource() + " ..."); - if (eventManager != null) { - eventManager.fireIvyEvent(new StartArtifactDownloadEvent(this, - artifacts[i], origin)); - } - - File tmp = cacheManager.getArchiveFileInCache(new DefaultArtifact( - artifacts[i].getModuleRevisionId(), artifacts[i] - .getPublicationDate(), artifacts[i].getName(), - artifacts[i].getType(), artifacts[i].getExt() + ".part", - artifacts[i].getExtraAttributes()), origin, useOrigin); - - // deal with artifact with url special case - if (artifactRef.getResource().getName().equals( - String.valueOf(artifacts[i].getUrl()))) { - Message.verbose("\t" + getName() + ": downloading " - + artifactRef.getResource().getName()); - Message.debug("\t\tto " + tmp); - if (tmp.getParentFile() != null) { - tmp.getParentFile().mkdirs(); - } - _extartifactrep.get(artifactRef.getResource().getName(), tmp); - adr.setSize(tmp.length()); - } else { - adr.setSize(getAndCheck(artifactRef.getResource(), tmp)); - } - if (!tmp.renameTo(archiveFile)) { - Message.warn("\t[FAILED ] " + artifacts[i] - + " impossible to move temp file to definitive one (" - + (System.currentTimeMillis() - start) + "ms)"); - adr.setDownloadStatus(DownloadStatus.FAILED); - } else { - cacheManager.saveArtifactOrigin(artifacts[i], origin); - Message.info("\t[SUCCESSFUL ] " + artifacts[i] + " (" - + (System.currentTimeMillis() - start) + "ms)"); - adr.setDownloadStatus(DownloadStatus.SUCCESSFUL); - adr.setArtifactOrigin(origin); - } - } - } else { - adr.setDownloadStatus(DownloadStatus.FAILED); - } - } catch (Exception ex) { - Message.warn("\t[FAILED ] " + artifacts[i] + " : " + ex.getMessage() - + " (" + (System.currentTimeMillis() - start) + "ms)"); - adr.setDownloadStatus(DownloadStatus.FAILED); - } - checkInterrupted(); - } - if (eventManager != null) { - eventManager.fireIvyEvent(new EndArtifactDownloadEvent(this, artifacts[i], adr, - archiveFile)); - } - } - return dr; - } finally { - IvyContext.getContext().popResolver(); - } - } - - protected void clearArtifactAttempts() { - _artattempts.clear(); - } - - public boolean exists(Artifact artifact) { - ResolvedResource artifactRef = getArtifactRef(artifact, null); - if (artifactRef != null) { - return artifactRef.getResource().exists(); - } - return false; - } - - protected long getPublicationDate(ModuleDescriptor md, DependencyDescriptor dd, ResolveData data) { - if (md.getPublicationDate() != null) { - return md.getPublicationDate().getTime(); - } - ResolvedResource artifactRef = findFirstArtifactRef(md, dd, data); - if (artifactRef != null) { - return artifactRef.getLastModified(); - } - return -1; - } - - public String toString() { - return getName(); - } - - public String[] listTokenValues(String token, Map otherTokenValues) { - Collection ret = findNames(otherTokenValues, token); - return (String[]) ret.toArray(new String[ret.size()]); - } - - public OrganisationEntry[] listOrganisations() { - Collection names = findNames(Collections.EMPTY_MAP, IvyPatternHelper.ORGANISATION_KEY); - OrganisationEntry[] ret = new OrganisationEntry[names.size()]; - int i = 0; - for (Iterator iter = names.iterator(); iter.hasNext(); i++) { - String org = (String) iter.next(); - ret[i] = new OrganisationEntry(this, org); - } - return ret; - } - - public ModuleEntry[] listModules(OrganisationEntry org) { - Map tokenValues = new HashMap(); - tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation()); - Collection names = findNames(tokenValues, IvyPatternHelper.MODULE_KEY); - ModuleEntry[] ret = new ModuleEntry[names.size()]; - int i = 0; - for (Iterator iter = names.iterator(); iter.hasNext(); i++) { - String name = (String) iter.next(); - ret[i] = new ModuleEntry(org, name); - } - return ret; - } - - public RevisionEntry[] listRevisions(ModuleEntry mod) { - Map tokenValues = new HashMap(); - tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, mod.getOrganisation()); - tokenValues.put(IvyPatternHelper.MODULE_KEY, mod.getModule()); - Collection names = findNames(tokenValues, IvyPatternHelper.REVISION_KEY); - RevisionEntry[] ret = new RevisionEntry[names.size()]; - int i = 0; - for (Iterator iter = names.iterator(); iter.hasNext(); i++) { - String name = (String) iter.next(); - ret[i] = new RevisionEntry(mod, name); - } - return ret; - } - - protected abstract Collection findNames(Map tokenValues, String token); - - protected abstract ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data); - - protected ResolvedResource findFirstArtifactRef(ModuleDescriptor md, DependencyDescriptor dd, - ResolveData data) { - ResolvedResource ret = null; - String[] conf = md.getConfigurationsNames(); - for (int i = 0; i < conf.length; i++) { - Artifact[] artifacts = md.getArtifacts(conf[i]); - for (int j = 0; j < artifacts.length; j++) { - ret = getArtifactRef(artifacts[j], data.getDate()); - if (ret != null) { - return ret; - } - } - } - return null; - } - - protected long getAndCheck(Resource resource, File dest) throws IOException { - long size = get(resource, dest); - String[] checksums = getChecksumAlgorithms(); - boolean checked = false; - for (int i = 0; i < checksums.length && !checked; i++) { - checked = check(resource, dest, checksums[i]); - } - return size; - } - - /** - * Checks the given resource checksum if a checksum resource exists. - * - * @param resource - * the resource to check - * @param dest - * the file where the resource has been downloaded - * @param algorithm - * the checksum algorithm to use - * @return true if the checksum has been successfully checked, false if the checksum wasn't - * available - * @throws IOException - * if a checksum exist but do not match the downloaded file checksum - */ - private boolean check(Resource resource, File dest, String algorithm) throws IOException { - Resource csRes = resource.clone(resource.getName() + "." + algorithm); - if (csRes.exists()) { - Message.debug(algorithm + " file found for " + resource + ": checking..."); - File csFile = File.createTempFile("ivytmp", algorithm); - try { - get(csRes, csFile); - try { - ChecksumHelper.check(dest, csFile, algorithm); - Message.verbose(algorithm + " OK for " + resource); - return true; - } catch (IOException ex) { - dest.delete(); - throw ex; - } - } finally { - csFile.delete(); - } - } else { - return false; - } - } - - protected ResolvedResource getArtifactRef(Artifact artifact, Date date) { - IvyContext.getContext().set(getName() + ".artifact", artifact); - try { - ResolvedResource ret = findArtifactRef(artifact, date); - if (ret == null && artifact.getUrl() != null) { - URL url = artifact.getUrl(); - Message.verbose("\tusing url for " + artifact + ": " + url); - logArtifactAttempt(artifact, url.toExternalForm()); - ret = new ResolvedResource(new URLResource(url), artifact.getModuleRevisionId() - .getRevision()); - } - return ret; - } finally { - IvyContext.getContext().set(getName() + ".artifact", null); - } - } - - protected abstract ResolvedResource findArtifactRef(Artifact artifact, Date date); - - protected abstract long get(Resource resource, File dest) throws IOException; - - public boolean isCheckconsistency() { - return _checkconsistency; - } - - public void setCheckconsistency(boolean checkConsitency) { - _checkconsistency = checkConsitency; - } - - public boolean isAllownomd() { - return _allownomd; - } - - public void setAllownomd(boolean b) { - _allownomd = b; - } - - public String[] getChecksumAlgorithms() { - String csDef = _checksums == null ? getSettings().getVariable("ivy.checksums") : _checksums; - if (csDef == null) { - return new String[0]; - } - // csDef is a comma separated list of checksum algorithms to use with this resolver - // we parse and return it as a String[] - String[] checksums = csDef.split(","); - List algos = new ArrayList(); - for (int i = 0; i < checksums.length; i++) { - String cs = checksums[i].trim(); - if (!"".equals(cs) && !"none".equals(cs)) { - algos.add(cs); - } - } - return (String[]) algos.toArray(new String[algos.size()]); - } - - public void setChecksums(String checksums) { - _checksums = checksums; - } - -} +/* + * 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.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.event.download.EndArtifactDownloadEvent; +import org.apache.ivy.core.event.download.NeedArtifactEvent; +import org.apache.ivy.core.event.download.StartArtifactDownloadEvent; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DefaultModuleRevision; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.plugins.parser.ModuleDescriptorParser; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.repository.ResourceHelper; +import org.apache.ivy.plugins.repository.url.URLRepository; +import org.apache.ivy.plugins.repository.url.URLResource; +import org.apache.ivy.plugins.resolver.util.MDResolvedResource; +import org.apache.ivy.plugins.resolver.util.ResolvedResource; +import org.apache.ivy.plugins.resolver.util.ResourceMDParser; +import org.apache.ivy.util.ChecksumHelper; +import org.apache.ivy.util.HostUtil; +import org.apache.ivy.util.Message; + +/** + * + */ +public abstract class BasicResolver extends AbstractResolver { + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss"); + + protected String _workspaceName; + + /** + * True if the files resolved are dependent of the environment from which they have been + * resolved, false otherwise. In general, relative paths are dependent of the environment, and + * absolute paths including machine reference are not. + */ + private boolean _envDependent = true; + + private List _ivyattempts = new ArrayList(); + + private Map _artattempts = new HashMap(); + + private Boolean _checkmodified = null; + + private boolean _checkconsistency = true; + + private boolean _allownomd = true; + + private String _checksums = null; + + private URLRepository _extartifactrep = new URLRepository(); // used only to download + + // external artifacts + + public BasicResolver() { + _workspaceName = HostUtil.getLocalHostName(); + } + + public String getWorkspaceName() { + return _workspaceName; + } + + public void setWorkspaceName(String workspaceName) { + _workspaceName = workspaceName; + } + + public boolean isEnvDependent() { + return _envDependent; + } + + public void setEnvDependent(boolean envDependent) { + _envDependent = envDependent; + } + + /** + * True if this resolver should check lastmodified date to know if ivy files are up to date. + * + * @return + */ + public boolean isCheckmodified() { + if (_checkmodified == null) { + if (getSettings() != null) { + String check = getSettings().getVariable("ivy.resolver.default.check.modified"); + return check != null ? Boolean.valueOf(check).booleanValue() : false; + } else { + return false; + } + } else { + return _checkmodified.booleanValue(); + } + } + + public void setCheckmodified(boolean check) { + _checkmodified = Boolean.valueOf(check); + } + + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException { + IvyContext.getContext().pushResolver(this); + try { + DependencyDescriptor systemDd = dd; + dd = fromSystem(dd); + + clearIvyAttempts(); + clearArtifactAttempts(); + boolean downloaded = false; + boolean searched = false; + ModuleRevisionId mrid = dd.getDependencyRevisionId(); + // check revision + int index = mrid.getRevision().indexOf("@"); + if (index != -1 && !mrid.getRevision().substring(index + 1).equals(_workspaceName)) { + Message.verbose("\t" + getName() + ": unhandled revision => " + mrid.getRevision()); + return null; + } + + boolean isDynamic = getSettings().getVersionMatcher().isDynamic(mrid); + if (isDynamic && !acceptLatest()) { + Message.error("dynamic revisions not handled by " + getClass().getName() + + ". impossible to resolve " + mrid); + return null; + } + + boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision()); + boolean isChangingDependency = isChangingRevision || dd.isChanging(); + + // if we do not have to check modified and if the revision is exact and not changing, + // we first search for it in cache + ResolvedModuleRevision cachedRmr = null; + boolean checkedCache = false; + if (!isDynamic && !isCheckmodified() && !isChangingDependency) { + cachedRmr = findModuleInCache(data, mrid); + checkedCache = true; + if (cachedRmr != null) { + if (cachedRmr.getDescriptor().isDefault() && cachedRmr.getResolver() != this) { + Message.verbose("\t" + getName() + ": found revision in cache: " + mrid + + " (resolved by " + cachedRmr.getResolver().getName() + + "): but it's a default one, maybe we can find a better one"); + } else { + Message.verbose("\t" + getName() + ": revision in cache: " + mrid); + return toSystem(cachedRmr); + } + } + } + checkInterrupted(); + URL cachedIvyURL = null; + ResolvedResource ivyRef = findIvyFileRef(dd, data); + checkInterrupted(); + searched = true; + + // get module descriptor + ModuleDescriptorParser parser; + ModuleDescriptor md; + ModuleDescriptor systemMd = null; + if (ivyRef == null) { + if (!isAllownomd()) { + Message.verbose("\t" + getName() + ": no ivy file found for " + mrid); + return null; + } + parser = XmlModuleDescriptorParser.getInstance(); + md = DefaultModuleDescriptor.newDefaultInstance(mrid, dd + .getAllDependencyArtifacts()); + ResolvedResource artifactRef = findFirstArtifactRef(md, dd, data); + checkInterrupted(); + if (artifactRef == null) { + Message.verbose("\t" + getName() + ": no ivy file nor artifact found for " + + mrid); + String[] conf = md.getConfigurationsNames(); + for (int i = 0; i < conf.length; i++) { + Artifact[] artifacts = md.getArtifacts(conf[i]); + for (int j = 0; j < artifacts.length; j++) { + } + } + if (!checkedCache) { + cachedRmr = findModuleInCache(data, mrid); + } + if (cachedRmr != null) { + Message.verbose("\t" + getName() + ": revision in cache: " + mrid); + return toSystem(cachedRmr); + } + return null; + } else { + long lastModified = artifactRef.getLastModified(); + if (lastModified != 0 && md instanceof DefaultModuleDescriptor) { + ((DefaultModuleDescriptor) md).setLastModified(lastModified); + } + Message.verbose("\t" + getName() + ": no ivy file found for " + mrid + + ": using default data"); + if (isDynamic) { + md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(mrid, + artifactRef.getRevision())); + } + } + } else { + ResolvedModuleRevision rmr = null; + if (ivyRef instanceof MDResolvedResource) { + rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision(); + } + if (rmr == null) { + rmr = parse(ivyRef, dd, data); + if (rmr == null) { + return null; + } + } + if (!rmr.isDownloaded()) { + return toSystem(rmr); + } else { + md = rmr.getDescriptor(); + parser = ModuleDescriptorParserRegistry.getInstance().getParser( + ivyRef.getResource()); + cachedIvyURL = rmr.getLocalMDUrl(); + + // check descriptor data is in sync with resource revision and names + systemMd = toSystem(md); + if (_checkconsistency) { + checkDescriptorConsistency(mrid, md, ivyRef); + checkDescriptorConsistency(systemDd.getDependencyRevisionId(), systemMd, + ivyRef); + } else { + if (md instanceof DefaultModuleDescriptor) { + String revision = getRevision(ivyRef, mrid, md); + ((DefaultModuleDescriptor) md).setModuleRevisionId(ModuleRevisionId + .newInstance(mrid, revision)); + } else { + Message + .warn("consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done"); + checkDescriptorConsistency(mrid, md, ivyRef); + checkDescriptorConsistency(systemDd.getDependencyRevisionId(), + systemMd, ivyRef); + } + } + } + } + + if (systemMd == null) { + systemMd = toSystem(md); + } + + // resolve revision + ModuleRevisionId resolvedMrid = mrid; + if (isDynamic) { + resolvedMrid = md.getResolvedModuleRevisionId(); + if (resolvedMrid.getRevision() == null || resolvedMrid.getRevision().length() == 0) { + if (ivyRef.getRevision() == null || ivyRef.getRevision().length() == 0) { + resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, "working@" + + getName()); + } else { + resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, ivyRef + .getRevision()); + } + } + Message.verbose("\t\t[" + resolvedMrid.getRevision() + "] " + mrid.getModuleId()); + } + md.setResolvedModuleRevisionId(resolvedMrid); + systemMd.setResolvedModuleRevisionId(toSystem(resolvedMrid)); // keep system md in + // sync with md + + // check module descriptor revision + if (!getSettings().getVersionMatcher().accept(mrid, md)) { + Message.info("\t" + getName() + ": unacceptable revision => was=" + + md.getModuleRevisionId().getRevision() + " required=" + + mrid.getRevision()); + return null; + } + + // resolve and check publication date + if (data.getDate() != null) { + long pubDate = getPublicationDate(md, dd, data); + if (pubDate > data.getDate().getTime()) { + Message.info("\t" + getName() + ": unacceptable publication date => was=" + + new Date(pubDate) + " required=" + data.getDate()); + return null; + } else if (pubDate == -1) { + Message.info("\t" + getName() + + ": impossible to guess publication date: artifact missing for " + + mrid); + return null; + } + md.setResolvedPublicationDate(new Date(pubDate)); + systemMd.setResolvedPublicationDate(new Date(pubDate)); // keep system md in sync + // with md + } + + try { + File ivyFile = data.getCacheManager().getIvyFileInCache( + systemMd.getResolvedModuleRevisionId()); + if (ivyRef == null) { + // a basic ivy file is written containing default data + XmlModuleDescriptorWriter.write(systemMd, ivyFile); + } else { + if (md instanceof DefaultModuleDescriptor) { + DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md; + if (data.getSettings().logNotConvertedExclusionRule() + && dmd.isNamespaceUseful()) { + Message + .warn("the module descriptor " + + ivyRef.getResource() + + " has information which can't be converted into the system namespace. It will require the availability of the namespace '" + + getNamespace().getName() + "' to be fully usable."); + } + } + // copy and update ivy file from source to cache + parser.toIvyFile(cachedIvyURL.openStream(), ivyRef.getResource(), ivyFile, + systemMd); + long repLastModified = ivyRef.getLastModified(); + if (repLastModified > 0) { + ivyFile.setLastModified(repLastModified); + } + } + } catch (Exception e) { + if (ivyRef == null) { + Message.warn("impossible to create ivy file in cache for module : " + + resolvedMrid); + } else { + e.printStackTrace(); + Message.warn("impossible to copy ivy file to cache : " + ivyRef.getResource()); + } + } + + data.getCacheManager().saveResolver(systemMd, getName()); + data.getCacheManager().saveArtResolver(systemMd, getName()); + return new DefaultModuleRevision(this, this, systemMd, searched, downloaded, + cachedIvyURL); + } finally { + IvyContext.getContext().popResolver(); + } + } + + private String getRevision(ResolvedResource ivyRef, ModuleRevisionId askedMrid, + ModuleDescriptor md) throws ParseException { + String revision = ivyRef.getRevision(); + if (revision == null) { + Message.debug("no revision found in reference for " + askedMrid); + if (getSettings().getVersionMatcher().isDynamic(askedMrid)) { + if (md.getModuleRevisionId().getRevision() == null) { + return "working@" + getName(); + } else { + Message.debug("using " + askedMrid); + revision = md.getModuleRevisionId().getRevision(); + } + } else { + Message.debug("using " + askedMrid); + revision = askedMrid.getRevision(); + } + } + return revision; + } + + public ResolvedModuleRevision parse(ResolvedResource ivyRef, DependencyDescriptor dd, + ResolveData data) throws ParseException { + + ModuleRevisionId mrid = dd.getDependencyRevisionId(); + ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser( + ivyRef.getResource()); + if (parser == null) { + Message.warn("no module descriptor parser available for " + ivyRef.getResource()); + return null; + } + Message.verbose("\t" + getName() + ": found md file for " + mrid); + Message.verbose("\t\t=> " + ivyRef); + Message.debug("\tparser = " + parser); + + boolean isChangingRevision = getChangingMatcher().matches(mrid.getRevision()); + boolean isChangingDependency = isChangingRevision || dd.isChanging(); + Date cachedPublicationDate = null; + ModuleRevisionId resolvedMrid = mrid; + + // first check if this dependency has not yet been resolved + if (getSettings().getVersionMatcher().isDynamic(mrid)) { + resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef.getRevision()); + IvyNode node = getSystemNode(data, resolvedMrid); + if (node != null && node.getModuleRevision() != null) { + // this revision has already be resolved : return it + if (node.getDescriptor() != null && node.getDescriptor().isDefault()) { + Message.verbose("\t" + getName() + ": found already resolved revision: " + + resolvedMrid + + ": but it's a default one, maybe we can find a better one"); + } else { + Message.verbose("\t" + getName() + ": revision already resolved: " + + resolvedMrid); + return searchedRmr(node.getModuleRevision()); + } + } + } + + // now let's see if we can find it in cache and if it is up to date + ResolvedModuleRevision rmr = findModuleInCache(data, resolvedMrid); + if (rmr != null) { + if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) { + Message.verbose("\t" + getName() + ": found revision in cache: " + mrid + + " (resolved by " + rmr.getResolver().getName() + + "): but it's a default one, maybe we can find a better one"); + } else { + if (!isCheckmodified() && !isChangingDependency) { + Message.verbose("\t" + getName() + ": revision in cache: " + mrid); + return searchedRmr(rmr); + } + long repLastModified = ivyRef.getLastModified(); + long cacheLastModified = rmr.getDescriptor().getLastModified(); + if (!rmr.getDescriptor().isDefault() && repLastModified <= cacheLastModified) { + Message.verbose("\t" + getName() + ": revision in cache (not updated): " + + resolvedMrid); + return searchedRmr(rmr); + } else { + Message.verbose("\t" + getName() + ": revision in cache is not up to date: " + + resolvedMrid); + if (isChangingDependency) { + // ivy file has been updated, we should see if it has a new publication date + // to see if a new download is required (in case the dependency is a + // changing one) + cachedPublicationDate = rmr.getDescriptor().getResolvedPublicationDate(); + } + } + } + } + + // now download ivy file and parse it + URL cachedIvyURL = null; + File ivyTempFile = null; + try { + // first check if source file is not cache file itself + if (ResourceHelper.equals(ivyRef.getResource(), data.getCacheManager() + .getIvyFileInCache(toSystem(resolvedMrid)))) { + Message.error("invalid configuration for resolver '" + getName() + + "': pointing ivy files to ivy cache is forbidden !"); + return null; + } + + // temp file is used to prevent downloading twice + ivyTempFile = File.createTempFile("ivy", "xml"); + ivyTempFile.deleteOnExit(); + Message.debug("\t" + getName() + ": downloading " + ivyRef.getResource() + " to " + + ivyTempFile); + getAndCheck(ivyRef.getResource(), ivyTempFile); + try { + cachedIvyURL = ivyTempFile.toURL(); + } catch (MalformedURLException ex) { + Message.warn("malformed url exception for temp file: " + ivyTempFile + ": " + + ex.getMessage()); + return null; + } + } catch (IOException ex) { + Message.warn("problem while downloading ivy file: " + ivyRef.getResource() + " to " + + ivyTempFile + ": " + ex.getMessage()); + return null; + } + try { + ModuleDescriptor md = parser.parseDescriptor(data.getSettings(), cachedIvyURL, ivyRef + .getResource(), doValidate(data)); + Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid + " parsed=" + + md.getModuleRevisionId()); + + // check if we should delete old artifacts + boolean deleteOldArtifacts = false; + if (cachedPublicationDate != null + && !cachedPublicationDate.equals(md.getResolvedPublicationDate())) { + // artifacts have changed, they should be downloaded again + Message.verbose(dd + " has changed: deleting old artifacts"); + deleteOldArtifacts = true; + } + if (deleteOldArtifacts) { + String[] confs = rmr.getDescriptor().getConfigurationsNames(); + for (int i = 0; i < confs.length; i++) { + Artifact[] arts = rmr.getDescriptor().getArtifacts(confs[i]); + for (int j = 0; j < arts.length; j++) { + Artifact transformedArtifact = toSystem(arts[j]); + ArtifactOrigin origin = data.getCacheManager().getSavedArtifactOrigin( + transformedArtifact); + File artFile = data.getCacheManager().getArchiveFileInCache( + transformedArtifact, origin, false); + if (artFile.exists()) { + Message.debug("deleting " + artFile); + artFile.delete(); + } + data.getCacheManager().removeSavedArtifactOrigin(transformedArtifact); + } + } + } else if (isChangingDependency) { + Message.verbose(dd + + " is changing, but has not changed: will trust cached artifacts if any"); + } + return new DefaultModuleRevision(this, this, md, true, true, cachedIvyURL); + } catch (IOException ex) { + Message.warn("io problem while parsing ivy file: " + ivyRef.getResource() + ": " + + ex.getMessage()); + return null; + } + + } + + protected ResourceMDParser getRMDParser(final DependencyDescriptor dd, final ResolveData data) { + return new ResourceMDParser() { + public MDResolvedResource parse(Resource resource, String rev) { + try { + ResolvedModuleRevision rmr = BasicResolver.this.parse(new ResolvedResource( + resource, rev), dd, data); + if (rmr == null) { + return null; + } else { + return new MDResolvedResource(resource, rev, rmr); + } + } catch (ParseException e) { + return null; + } + } + + }; + } + + protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) { + return new ResourceMDParser() { + public MDResolvedResource parse(Resource resource, String rev) { + return new MDResolvedResource(resource, rev, new DefaultModuleRevision( + BasicResolver.this, BasicResolver.this, DefaultModuleDescriptor + .newDefaultInstance(new ModuleRevisionId(mid, rev)), false, false, + null)); + } + }; + } + + // private boolean isResolved(ResolveData data, ModuleRevisionId mrid) { + // IvyNode node = getSystemNode(data, mrid); + // return node != null && node.getModuleRevision() != null; + // } + // + private void checkDescriptorConsistency(ModuleRevisionId mrid, ModuleDescriptor md, + ResolvedResource ivyRef) throws ParseException { + boolean ok = true; + StringBuffer errors = new StringBuffer(); + if (!mrid.getOrganisation().equals(md.getModuleRevisionId().getOrganisation())) { + Message.error("\t" + getName() + ": bad organisation found in " + ivyRef.getResource() + + ": expected='" + mrid.getOrganisation() + "' found='" + + md.getModuleRevisionId().getOrganisation() + "'"); + errors.append("bad organisation: expected='" + mrid.getOrganisation() + "' found='" + + md.getModuleRevisionId().getOrganisation() + "'; "); + ok = false; + } + if (!mrid.getName().equals(md.getModuleRevisionId().getName())) { + Message.error("\t" + getName() + ": bad module name found in " + ivyRef.getResource() + + ": expected='" + mrid.getName() + " found='" + + md.getModuleRevisionId().getName() + "'"); + errors.append("bad module name: expected='" + mrid.getName() + "' found='" + + md.getModuleRevisionId().getName() + "'; "); + ok = false; + } + if (ivyRef.getRevision() != null && !ivyRef.getRevision().startsWith("working@")) { + ModuleRevisionId expectedMrid = ModuleRevisionId + .newInstance(mrid, ivyRef.getRevision()); + if (!getSettings().getVersionMatcher().accept(expectedMrid, md)) { + Message.error("\t" + getName() + ": bad revision found in " + ivyRef.getResource() + + ": expected='" + ivyRef.getRevision() + " found='" + + md.getModuleRevisionId().getRevision() + "'"); + errors.append("bad revision: expected='" + ivyRef.getRevision() + "' found='" + + md.getModuleRevisionId().getRevision() + "'; "); + ok = false; + } + } + if (!getSettings().getStatusManager().isStatus(md.getStatus())) { + Message.error("\t" + getName() + ": bad status found in " + ivyRef.getResource() + + ": '" + md.getStatus() + "'"); + errors.append("bad status: '" + md.getStatus() + "'; "); + ok = false; + } + if (!ok) { + throw new ParseException("inconsistent module descriptor file found in '" + + ivyRef.getResource() + "': " + errors, 0); + } + } + + protected void clearIvyAttempts() { + _ivyattempts.clear(); + clearArtifactAttempts(); + } + + protected ResolvedModuleRevision searchedRmr(final ResolvedModuleRevision rmr) { + // delegate all to previously found except isSearched + return new ResolvedModuleRevision() { + public boolean isSearched() { + return true; + } + + public boolean isDownloaded() { + return rmr.isDownloaded(); + } + + public ModuleDescriptor getDescriptor() { + return rmr.getDescriptor(); + } + + public Date getPublicationDate() { + return rmr.getPublicationDate(); + } + + public ModuleRevisionId getId() { + return rmr.getId(); + } + + public DependencyResolver getResolver() { + return rmr.getResolver(); + } + + public DependencyResolver getArtifactResolver() { + return rmr.getArtifactResolver(); + } + + public URL getLocalMDUrl() { + return rmr.getLocalMDUrl(); + } + }; + } + + protected void logIvyAttempt(String attempt) { + _ivyattempts.add(attempt); + Message.verbose("\t\ttried " + attempt); + } + + protected void logArtifactAttempt(Artifact art, String attempt) { + List attempts = (List) _artattempts.get(art); + if (attempts == null) { + attempts = new ArrayList(); + _artattempts.put(art, attempts); + } + attempts.add(attempt); + Message.verbose("\t\ttried " + attempt); + } + + protected static void logAttempt(String attempt) { + DependencyResolver resolver = IvyContext.getContext().getResolver(); + if (resolver instanceof BasicResolver) { + Artifact currentArtifact = (Artifact) IvyContext.getContext().get( + resolver.getName() + ".artifact"); + if (currentArtifact != null) { + ((BasicResolver) resolver).logArtifactAttempt(currentArtifact, attempt); + } else { + ((BasicResolver) resolver).logIvyAttempt(attempt); + } + } + } + + public void reportFailure() { + Message.warn("==== " + getName() + ": tried"); + for (ListIterator iter = _ivyattempts.listIterator(); iter.hasNext();) { + String m = (String) iter.next(); + Message.warn(" " + m); + } + for (Iterator iter = _artattempts.keySet().iterator(); iter.hasNext();) { + Artifact art = (Artifact) iter.next(); + List attempts = (List) _artattempts.get(art); + if (attempts != null) { + Message.warn(" -- artifact " + art + ":"); + for (ListIterator iterator = attempts.listIterator(); iterator.hasNext();) { + String m = (String) iterator.next(); + Message.warn(" " + m); + } + } + } + } + + public void reportFailure(Artifact art) { + Message.warn("==== " + getName() + ": tried"); + List attempts = (List) _artattempts.get(art); + if (attempts != null) { + for (ListIterator iter = attempts.listIterator(); iter.hasNext();) { + String m = (String) iter.next(); + Message.warn(" " + m); + } + } + } + + protected boolean acceptLatest() { + return true; + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + IvyContext.getContext().pushResolver(this); + try { + CacheManager cacheManager = options.getCacheManager(); + EventManager eventManager = options.getEventManager(); + + boolean useOrigin = options.isUseOrigin(); + + clearArtifactAttempts(); + DownloadReport dr = new DownloadReport(); + for (int i = 0; i < artifacts.length; i++) { + final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]); + dr.addArtifactReport(adr); + if (eventManager != null) { + eventManager.fireIvyEvent(new NeedArtifactEvent(this, artifacts[i])); + } + ArtifactOrigin origin = cacheManager.getSavedArtifactOrigin(artifacts[i]); + // if we can use origin file, we just ask ivy for the file in cache, and it will + // return + // the original one if possible. If we are not in useOrigin mode, we use the + // getArchivePath + // method which always return a path in the actual cache + File archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], origin, options + .isUseOrigin()); + + if (archiveFile.exists()) { + Message.verbose("\t[NOT REQUIRED] " + artifacts[i]); + adr.setDownloadStatus(DownloadStatus.NO); + adr.setSize(archiveFile.length()); + adr.setArtifactOrigin(origin); + } else { + Artifact artifact = fromSystem(artifacts[i]); + if (!artifact.equals(artifacts[i])) { + Message.verbose("\t" + getName() + "looking for artifact " + artifact + + " (is " + artifacts[i] + " in system namespace)"); + } + long start = System.currentTimeMillis(); + try { + ResolvedResource artifactRef = getArtifactRef(artifact, null); + if (artifactRef != null) { + origin = new ArtifactOrigin(artifactRef.getResource().isLocal(), + artifactRef.getResource().getName()); + if (useOrigin && artifactRef.getResource().isLocal()) { + Message.verbose("\t[NOT REQUIRED] " + artifacts[i]); + cacheManager.saveArtifactOrigin(artifacts[i], origin); + archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], + origin); + adr.setDownloadStatus(DownloadStatus.NO); + adr.setSize(archiveFile.length()); + adr.setArtifactOrigin(origin); + } else { + // refresh archive file now that we better now its origin + archiveFile = cacheManager.getArchiveFileInCache(artifacts[i], + origin, useOrigin); + if (ResourceHelper.equals(artifactRef.getResource(), archiveFile)) { + Message.error("invalid configuration for resolver '" + + getName() + + "': pointing artifacts to ivy cache is forbidden !"); + return null; + } + Message.info("downloading " + artifactRef.getResource() + " ..."); + if (eventManager != null) { + eventManager.fireIvyEvent(new StartArtifactDownloadEvent(this, + artifacts[i], origin)); + } + + File tmp = cacheManager.getArchiveFileInCache(new DefaultArtifact( + artifacts[i].getModuleRevisionId(), artifacts[i] + .getPublicationDate(), artifacts[i].getName(), + artifacts[i].getType(), artifacts[i].getExt() + ".part", + artifacts[i].getExtraAttributes()), origin, useOrigin); + + // deal with artifact with url special case + if (artifactRef.getResource().getName().equals( + String.valueOf(artifacts[i].getUrl()))) { + Message.verbose("\t" + getName() + ": downloading " + + artifactRef.getResource().getName()); + Message.debug("\t\tto " + tmp); + if (tmp.getParentFile() != null) { + tmp.getParentFile().mkdirs(); + } + _extartifactrep.get(artifactRef.getResource().getName(), tmp); + adr.setSize(tmp.length()); + } else { + adr.setSize(getAndCheck(artifactRef.getResource(), tmp)); + } + if (!tmp.renameTo(archiveFile)) { + Message.warn("\t[FAILED ] " + artifacts[i] + + " impossible to move temp file to definitive one (" + + (System.currentTimeMillis() - start) + "ms)"); + adr.setDownloadStatus(DownloadStatus.FAILED); + } else { + cacheManager.saveArtifactOrigin(artifacts[i], origin); + Message.info("\t[SUCCESSFUL ] " + artifacts[i] + " (" + + (System.currentTimeMillis() - start) + "ms)"); + adr.setDownloadStatus(DownloadStatus.SUCCESSFUL); + adr.setArtifactOrigin(origin); + } + } + } else { + adr.setDownloadStatus(DownloadStatus.FAILED); + } + } catch (Exception ex) { + Message.warn("\t[FAILED ] " + artifacts[i] + " : " + ex.getMessage() + + " (" + (System.currentTimeMillis() - start) + "ms)"); + adr.setDownloadStatus(DownloadStatus.FAILED); + } + checkInterrupted(); + } + if (eventManager != null) { + eventManager.fireIvyEvent(new EndArtifactDownloadEvent(this, artifacts[i], adr, + archiveFile)); + } + } + return dr; + } finally { + IvyContext.getContext().popResolver(); + } + } + + protected void clearArtifactAttempts() { + _artattempts.clear(); + } + + public boolean exists(Artifact artifact) { + ResolvedResource artifactRef = getArtifactRef(artifact, null); + if (artifactRef != null) { + return artifactRef.getResource().exists(); + } + return false; + } + + protected long getPublicationDate(ModuleDescriptor md, DependencyDescriptor dd, ResolveData data) { + if (md.getPublicationDate() != null) { + return md.getPublicationDate().getTime(); + } + ResolvedResource artifactRef = findFirstArtifactRef(md, dd, data); + if (artifactRef != null) { + return artifactRef.getLastModified(); + } + return -1; + } + + public String toString() { + return getName(); + } + + public String[] listTokenValues(String token, Map otherTokenValues) { + Collection ret = findNames(otherTokenValues, token); + return (String[]) ret.toArray(new String[ret.size()]); + } + + public OrganisationEntry[] listOrganisations() { + Collection names = findNames(Collections.EMPTY_MAP, IvyPatternHelper.ORGANISATION_KEY); + OrganisationEntry[] ret = new OrganisationEntry[names.size()]; + int i = 0; + for (Iterator iter = names.iterator(); iter.hasNext(); i++) { + String org = (String) iter.next(); + ret[i] = new OrganisationEntry(this, org); + } + return ret; + } + + public ModuleEntry[] listModules(OrganisationEntry org) { + Map tokenValues = new HashMap(); + tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation()); + Collection names = findNames(tokenValues, IvyPatternHelper.MODULE_KEY); + ModuleEntry[] ret = new ModuleEntry[names.size()]; + int i = 0; + for (Iterator iter = names.iterator(); iter.hasNext(); i++) { + String name = (String) iter.next(); + ret[i] = new ModuleEntry(org, name); + } + return ret; + } + + public RevisionEntry[] listRevisions(ModuleEntry mod) { + Map tokenValues = new HashMap(); + tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, mod.getOrganisation()); + tokenValues.put(IvyPatternHelper.MODULE_KEY, mod.getModule()); + Collection names = findNames(tokenValues, IvyPatternHelper.REVISION_KEY); + RevisionEntry[] ret = new RevisionEntry[names.size()]; + int i = 0; + for (Iterator iter = names.iterator(); iter.hasNext(); i++) { + String name = (String) iter.next(); + ret[i] = new RevisionEntry(mod, name); + } + return ret; + } + + protected abstract Collection findNames(Map tokenValues, String token); + + protected abstract ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data); + + protected ResolvedResource findFirstArtifactRef(ModuleDescriptor md, DependencyDescriptor dd, + ResolveData data) { + ResolvedResource ret = null; + String[] conf = md.getConfigurationsNames(); + for (int i = 0; i < conf.length; i++) { + Artifact[] artifacts = md.getArtifacts(conf[i]); + for (int j = 0; j < artifacts.length; j++) { + ret = getArtifactRef(artifacts[j], data.getDate()); + if (ret != null) { + return ret; + } + } + } + return null; + } + + protected long getAndCheck(Resource resource, File dest) throws IOException { + long size = get(resource, dest); + String[] checksums = getChecksumAlgorithms(); + boolean checked = false; + for (int i = 0; i < checksums.length && !checked; i++) { + checked = check(resource, dest, checksums[i]); + } + return size; + } + + /** + * Checks the given resource checksum if a checksum resource exists. + * + * @param resource + * the resource to check + * @param dest + * the file where the resource has been downloaded + * @param algorithm + * the checksum algorithm to use + * @return true if the checksum has been successfully checked, false if the checksum wasn't + * available + * @throws IOException + * if a checksum exist but do not match the downloaded file checksum + */ + private boolean check(Resource resource, File dest, String algorithm) throws IOException { + Resource csRes = resource.clone(resource.getName() + "." + algorithm); + if (csRes.exists()) { + Message.debug(algorithm + " file found for " + resource + ": checking..."); + File csFile = File.createTempFile("ivytmp", algorithm); + try { + get(csRes, csFile); + try { + ChecksumHelper.check(dest, csFile, algorithm); + Message.verbose(algorithm + " OK for " + resource); + return true; + } catch (IOException ex) { + dest.delete(); + throw ex; + } + } finally { + csFile.delete(); + } + } else { + return false; + } + } + + protected ResolvedResource getArtifactRef(Artifact artifact, Date date) { + IvyContext.getContext().set(getName() + ".artifact", artifact); + try { + ResolvedResource ret = findArtifactRef(artifact, date); + if (ret == null && artifact.getUrl() != null) { + URL url = artifact.getUrl(); + Message.verbose("\tusing url for " + artifact + ": " + url); + logArtifactAttempt(artifact, url.toExternalForm()); + ret = new ResolvedResource(new URLResource(url), artifact.getModuleRevisionId() + .getRevision()); + } + return ret; + } finally { + IvyContext.getContext().set(getName() + ".artifact", null); + } + } + + protected abstract ResolvedResource findArtifactRef(Artifact artifact, Date date); + + protected abstract long get(Resource resource, File dest) throws IOException; + + public boolean isCheckconsistency() { + return _checkconsistency; + } + + public void setCheckconsistency(boolean checkConsitency) { + _checkconsistency = checkConsitency; + } + + public boolean isAllownomd() { + return _allownomd; + } + + public void setAllownomd(boolean b) { + _allownomd = b; + } + + public String[] getChecksumAlgorithms() { + String csDef = _checksums == null ? getSettings().getVariable("ivy.checksums") : _checksums; + if (csDef == null) { + return new String[0]; + } + // csDef is a comma separated list of checksum algorithms to use with this resolver + // we parse and return it as a String[] + String[] checksums = csDef.split(","); + List algos = new ArrayList(); + for (int i = 0; i < checksums.length; i++) { + String cs = checksums[i].trim(); + if (!"".equals(cs) && !"none".equals(cs)) { + algos.add(cs); + } + } + return (String[]) algos.toArray(new String[algos.size()]); + } + + public void setChecksums(String checksums) { + _checksums = checksums; + } + +} diff --git a/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java b/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java index e29c38b0..9a64948f 100644 --- a/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java @@ -1,176 +1,176 @@ -/* - * 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.text.ParseException; -import java.util.Collections; -import java.util.Date; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.resolver.util.ResolvedResource; -import org.apache.ivy.util.Message; - -public class CacheResolver extends FileSystemResolver { - private File _configured = null; - - public CacheResolver() { - } - - public CacheResolver(IvySettings settings) { - setSettings(settings); - setName("cache"); - } - - public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException { - clearIvyAttempts(); - - ModuleRevisionId mrid = dd.getDependencyRevisionId(); - // check revision - - // if we do not have to check modified and if the revision is exact and not changing, - // we first search for it in cache - if (!getSettings().getVersionMatcher().isDynamic(mrid)) { - ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(mrid, - doValidate(data)); - if (rmr != null) { - Message.verbose("\t" + getName() + ": revision in cache: " + mrid); - return rmr; - } else { - logIvyAttempt(data.getCacheManager().getArchiveFileInCache( - DefaultArtifact.newIvyArtifact(mrid, new Date())).getAbsolutePath()); - Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid); - return null; - } - } else { - ensureConfigured(data.getSettings(), data.getCacheManager().getCache()); - ResolvedResource ivyRef = findIvyFileRef(dd, data); - if (ivyRef != null) { - Message.verbose("\t" + getName() + ": found ivy file in cache for " + mrid); - Message.verbose("\t\t=> " + ivyRef); - - ModuleRevisionId resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef - .getRevision()); - IvyNode node = data.getNode(resolvedMrid); - if (node != null && node.getModuleRevision() != null) { - // this revision has already be resolved : return it - Message.verbose("\t" + getName() + ": revision already resolved: " - + resolvedMrid); - return searchedRmr(node.getModuleRevision()); - } - ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(resolvedMrid, - doValidate(data)); - if (rmr != null) { - Message.verbose("\t" + getName() + ": revision in cache: " + resolvedMrid); - return searchedRmr(rmr); - } else { - Message.error("\t" + getName() - + ": inconsistent cache: clean it and resolve again"); - return null; - } - } else { - Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid); - return null; - } - } - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - clearArtifactAttempts(); - DownloadReport dr = new DownloadReport(); - for (int i = 0; i < artifacts.length; i++) { - final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]); - dr.addArtifactReport(adr); - File archiveFile = options.getCacheManager().getArchiveFileInCache(artifacts[i]); - if (archiveFile.exists()) { - Message.verbose("\t[NOT REQUIRED] " + artifacts[i]); - adr.setDownloadStatus(DownloadStatus.NO); - adr.setSize(archiveFile.length()); - } else { - logArtifactAttempt(artifacts[i], archiveFile.getAbsolutePath()); - adr.setDownloadStatus(DownloadStatus.FAILED); - } - } - return dr; - } - - public boolean exists(Artifact artifact) { - ensureConfigured(); - return super.exists(artifact); - } - - public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { - ensureConfigured(); - super.publish(artifact, src, overwrite); - } - - public OrganisationEntry[] listOrganisations() { - ensureConfigured(); - return super.listOrganisations(); - } - - public ModuleEntry[] listModules(OrganisationEntry org) { - ensureConfigured(); - return super.listModules(org); - } - - public RevisionEntry[] listRevisions(ModuleEntry module) { - ensureConfigured(); - return super.listRevisions(module); - } - - public void dumpSettings() { - Message.verbose("\t" + getName() + " [cache]"); - } - - private void ensureConfigured() { - if (getSettings() != null) { - ensureConfigured(getSettings(), getSettings().getDefaultCache()); - } - } - - private void ensureConfigured(IvySettings settings, File cache) { - if (settings == null || cache == null || (_configured != null && _configured.equals(cache))) { - return; - } - setIvyPatterns(Collections.singletonList(cache.getAbsolutePath() + "/" - + settings.getCacheIvyPattern())); - setArtifactPatterns(Collections.singletonList(cache.getAbsolutePath() + "/" - + settings.getCacheArtifactPattern())); - } - - public String getTypeName() { - return "cache"; - } -} +/* + * 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.text.ParseException; +import java.util.Collections; +import java.util.Date; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.resolver.util.ResolvedResource; +import org.apache.ivy.util.Message; + +public class CacheResolver extends FileSystemResolver { + private File _configured = null; + + public CacheResolver() { + } + + public CacheResolver(IvySettings settings) { + setSettings(settings); + setName("cache"); + } + + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException { + clearIvyAttempts(); + + ModuleRevisionId mrid = dd.getDependencyRevisionId(); + // check revision + + // if we do not have to check modified and if the revision is exact and not changing, + // we first search for it in cache + if (!getSettings().getVersionMatcher().isDynamic(mrid)) { + ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(mrid, + doValidate(data)); + if (rmr != null) { + Message.verbose("\t" + getName() + ": revision in cache: " + mrid); + return rmr; + } else { + logIvyAttempt(data.getCacheManager().getArchiveFileInCache( + DefaultArtifact.newIvyArtifact(mrid, new Date())).getAbsolutePath()); + Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid); + return null; + } + } else { + ensureConfigured(data.getSettings(), data.getCacheManager().getCache()); + ResolvedResource ivyRef = findIvyFileRef(dd, data); + if (ivyRef != null) { + Message.verbose("\t" + getName() + ": found ivy file in cache for " + mrid); + Message.verbose("\t\t=> " + ivyRef); + + ModuleRevisionId resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef + .getRevision()); + IvyNode node = data.getNode(resolvedMrid); + if (node != null && node.getModuleRevision() != null) { + // this revision has already be resolved : return it + Message.verbose("\t" + getName() + ": revision already resolved: " + + resolvedMrid); + return searchedRmr(node.getModuleRevision()); + } + ResolvedModuleRevision rmr = data.getCacheManager().findModuleInCache(resolvedMrid, + doValidate(data)); + if (rmr != null) { + Message.verbose("\t" + getName() + ": revision in cache: " + resolvedMrid); + return searchedRmr(rmr); + } else { + Message.error("\t" + getName() + + ": inconsistent cache: clean it and resolve again"); + return null; + } + } else { + Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid); + return null; + } + } + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + clearArtifactAttempts(); + DownloadReport dr = new DownloadReport(); + for (int i = 0; i < artifacts.length; i++) { + final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifacts[i]); + dr.addArtifactReport(adr); + File archiveFile = options.getCacheManager().getArchiveFileInCache(artifacts[i]); + if (archiveFile.exists()) { + Message.verbose("\t[NOT REQUIRED] " + artifacts[i]); + adr.setDownloadStatus(DownloadStatus.NO); + adr.setSize(archiveFile.length()); + } else { + logArtifactAttempt(artifacts[i], archiveFile.getAbsolutePath()); + adr.setDownloadStatus(DownloadStatus.FAILED); + } + } + return dr; + } + + public boolean exists(Artifact artifact) { + ensureConfigured(); + return super.exists(artifact); + } + + public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { + ensureConfigured(); + super.publish(artifact, src, overwrite); + } + + public OrganisationEntry[] listOrganisations() { + ensureConfigured(); + return super.listOrganisations(); + } + + public ModuleEntry[] listModules(OrganisationEntry org) { + ensureConfigured(); + return super.listModules(org); + } + + public RevisionEntry[] listRevisions(ModuleEntry module) { + ensureConfigured(); + return super.listRevisions(module); + } + + public void dumpSettings() { + Message.verbose("\t" + getName() + " [cache]"); + } + + private void ensureConfigured() { + if (getSettings() != null) { + ensureConfigured(getSettings(), getSettings().getDefaultCache()); + } + } + + private void ensureConfigured(IvySettings settings, File cache) { + if (settings == null || cache == null || (_configured != null && _configured.equals(cache))) { + return; + } + setIvyPatterns(Collections.singletonList(cache.getAbsolutePath() + "/" + + settings.getCacheIvyPattern())); + setArtifactPatterns(Collections.singletonList(cache.getAbsolutePath() + "/" + + settings.getCacheArtifactPattern())); + } + + public String getTypeName() { + return "cache"; + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java b/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java index f0619547..c74f4182 100644 --- a/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java @@ -1,297 +1,297 @@ -/* - * 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.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.plugins.latest.ArtifactInfo; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.plugins.resolver.util.HasLatestStrategy; -import org.apache.ivy.plugins.resolver.util.ResolvedModuleRevisionProxy; -import org.apache.ivy.util.Message; - -/** - * - */ -public class ChainResolver extends AbstractResolver { - public static class ResolvedModuleRevisionArtifactInfo implements ArtifactInfo { - private ResolvedModuleRevision _rmr; - - public ResolvedModuleRevisionArtifactInfo(ResolvedModuleRevision rmr) { - _rmr = rmr; - } - - public String getRevision() { - return _rmr.getId().getRevision(); - } - - public long getLastModified() { - return _rmr.getPublicationDate().getTime(); - } - - } - - private boolean _returnFirst = false; - - private List _chain = new ArrayList(); - - private boolean _dual; - - public void add(DependencyResolver resolver) { - _chain.add(resolver); - } - - public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException { - data = new ResolveData(data, doValidate(data)); - ResolvedModuleRevision ret = null; - - List errors = new ArrayList(); - - for (Iterator iter = _chain.iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - LatestStrategy oldLatest = setLatestIfRequired(resolver, getLatestStrategy()); - ResolvedModuleRevision mr = null; - try { - mr = resolver.getDependency(dd, data); - } catch (Exception ex) { - Message.verbose("problem occured while resolving " + dd + " with " + resolver - + ": " + ex); - errors.add(ex); - } finally { - if (oldLatest != null) { - setLatest(resolver, oldLatest); - } - } - checkInterrupted(); - if (mr != null) { - boolean shouldReturn = _returnFirst; - shouldReturn |= !getSettings().getVersionMatcher().isDynamic( - dd.getDependencyRevisionId()) - && ret != null && !ret.getDescriptor().isDefault(); - if (!shouldReturn) { - // check if latest is asked and compare to return the most recent - String mrDesc = mr.getId() - + (mr.getDescriptor().isDefault() ? "[default]" : "") + " from " - + mr.getResolver().getName(); - Message.debug("\tchecking " + mrDesc + " against " + ret); - if (ret == null) { - Message.debug("\tmodule revision kept as first found: " + mrDesc); - ret = mr; - } else if (isAfter(mr, ret, data.getDate())) { - Message.debug("\tmodule revision kept as younger: " + mrDesc); - ret = mr; - } else if (!mr.getDescriptor().isDefault() && ret.getDescriptor().isDefault()) { - Message.debug("\tmodule revision kept as better (not default): " + mrDesc); - ret = mr; - } else { - Message.debug("\tmodule revision discarded as older: " + mrDesc); - } - if (!getSettings().getVersionMatcher().isDynamic(dd.getDependencyRevisionId()) - && !ret.getDescriptor().isDefault()) { - Message.debug("\tmodule revision found and is not default: returning " - + mrDesc); - return resolvedRevision(mr); - } - } else { - return resolvedRevision(mr); - } - } - } - if (ret == null && !errors.isEmpty()) { - if (errors.size() == 1) { - Exception ex = (Exception) errors.get(0); - if (ex instanceof RuntimeException) { - throw (RuntimeException) ex; - } else if (ex instanceof ParseException) { - throw (ParseException) ex; - } else { - throw new RuntimeException(ex.toString(), ex); - } - } else { - StringBuffer err = new StringBuffer(); - for (Iterator iter = errors.iterator(); iter.hasNext();) { - Exception ex = (Exception) iter.next(); - err.append(ex).append("\n"); - } - err.setLength(err.length() - 1); - throw new RuntimeException("several problems occured while resolving " + dd + ":\n" - + err); - } - } - return resolvedRevision(ret); - } - - private ResolvedModuleRevision resolvedRevision(ResolvedModuleRevision mr) { - if (isDual() && mr != null) { - return new ResolvedModuleRevisionProxy(mr, this); - } else { - return mr; - } - } - - private LatestStrategy setLatestIfRequired(DependencyResolver resolver, - LatestStrategy latestStrategy) { - String latestName = getLatestStrategyName(resolver); - if (latestName != null && !"default".equals(latestName)) { - LatestStrategy oldLatest = getLatest(resolver); - setLatest(resolver, latestStrategy); - return oldLatest; - } else { - return null; - } - } - - /** - * Returns true if rmr1 is after rmr2, using the latest strategy to determine which is the - * latest - * - * @param rmr1 - * @param rmr2 - * @return - */ - private boolean isAfter(ResolvedModuleRevision rmr1, ResolvedModuleRevision rmr2, Date date) { - ArtifactInfo[] ais = new ArtifactInfo[] {new ResolvedModuleRevisionArtifactInfo(rmr2), - new ResolvedModuleRevisionArtifactInfo(rmr1)}; - return getLatestStrategy().findLatest(ais, date) != ais[0]; - } - - public void reportFailure() { - for (Iterator iter = _chain.iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - resolver.reportFailure(); - } - } - - public void reportFailure(Artifact art) { - for (Iterator iter = _chain.iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - resolver.reportFailure(art); - } - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - List artifactsToDownload = new ArrayList(Arrays.asList(artifacts)); - DownloadReport report = new DownloadReport(); - for (Iterator iter = _chain.iterator(); iter.hasNext() && !artifactsToDownload.isEmpty();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - DownloadReport r = resolver.download((Artifact[]) artifactsToDownload - .toArray(new Artifact[artifactsToDownload.size()]), options); - ArtifactDownloadReport[] adr = r.getArtifactsReports(); - for (int i = 0; i < adr.length; i++) { - if (adr[i].getDownloadStatus() != DownloadStatus.FAILED) { - artifactsToDownload.remove(adr[i].getArtifact()); - report.addArtifactReport(adr[i]); - } - } - } - for (Iterator iter = artifactsToDownload.iterator(); iter.hasNext();) { - Artifact art = (Artifact) iter.next(); - ArtifactDownloadReport adr = new ArtifactDownloadReport(art); - adr.setDownloadStatus(DownloadStatus.FAILED); - report.addArtifactReport(adr); - } - return report; - } - - public List getResolvers() { - return _chain; - } - - public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { - if (_chain.isEmpty()) { - throw new IllegalStateException("invalid chain resolver with no sub resolver"); - } - ((DependencyResolver) _chain.get(0)).publish(artifact, src, overwrite); - } - - public boolean isReturnFirst() { - return _returnFirst; - } - - public void setReturnFirst(boolean returnFirst) { - _returnFirst = returnFirst; - } - - public void dumpSettings() { - Message.verbose("\t" + getName() + " [chain] " + _chain); - Message.debug("\t\treturn first: " + isReturnFirst()); - Message.debug("\t\tdual: " + isDual()); - for (Iterator iter = _chain.iterator(); iter.hasNext();) { - DependencyResolver r = (DependencyResolver) iter.next(); - Message.debug("\t\t-> " + r.getName()); - } - } - - public boolean exists(Artifact artifact) { - for (Iterator iter = _chain.iterator(); iter.hasNext();) { - DependencyResolver resolver = (DependencyResolver) iter.next(); - if (resolver.exists(artifact)) { - return true; - } - } - return false; - } - - private static void setLatest(DependencyResolver resolver, LatestStrategy latest) { - if (resolver instanceof HasLatestStrategy) { - HasLatestStrategy r = (HasLatestStrategy) resolver; - r.setLatestStrategy(latest); - } - } - - private static LatestStrategy getLatest(DependencyResolver resolver) { - if (resolver instanceof HasLatestStrategy) { - HasLatestStrategy r = (HasLatestStrategy) resolver; - return r.getLatestStrategy(); - } - return null; - } - - private static String getLatestStrategyName(DependencyResolver resolver) { - if (resolver instanceof HasLatestStrategy) { - HasLatestStrategy r = (HasLatestStrategy) resolver; - return r.getLatest(); - } - return null; - } - - public void setDual(boolean b) { - _dual = b; - } - - public boolean isDual() { - return _dual; - } - -} +/* + * 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.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.plugins.latest.ArtifactInfo; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.plugins.resolver.util.HasLatestStrategy; +import org.apache.ivy.plugins.resolver.util.ResolvedModuleRevisionProxy; +import org.apache.ivy.util.Message; + +/** + * + */ +public class ChainResolver extends AbstractResolver { + public static class ResolvedModuleRevisionArtifactInfo implements ArtifactInfo { + private ResolvedModuleRevision _rmr; + + public ResolvedModuleRevisionArtifactInfo(ResolvedModuleRevision rmr) { + _rmr = rmr; + } + + public String getRevision() { + return _rmr.getId().getRevision(); + } + + public long getLastModified() { + return _rmr.getPublicationDate().getTime(); + } + + } + + private boolean _returnFirst = false; + + private List _chain = new ArrayList(); + + private boolean _dual; + + public void add(DependencyResolver resolver) { + _chain.add(resolver); + } + + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException { + data = new ResolveData(data, doValidate(data)); + ResolvedModuleRevision ret = null; + + List errors = new ArrayList(); + + for (Iterator iter = _chain.iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + LatestStrategy oldLatest = setLatestIfRequired(resolver, getLatestStrategy()); + ResolvedModuleRevision mr = null; + try { + mr = resolver.getDependency(dd, data); + } catch (Exception ex) { + Message.verbose("problem occured while resolving " + dd + " with " + resolver + + ": " + ex); + errors.add(ex); + } finally { + if (oldLatest != null) { + setLatest(resolver, oldLatest); + } + } + checkInterrupted(); + if (mr != null) { + boolean shouldReturn = _returnFirst; + shouldReturn |= !getSettings().getVersionMatcher().isDynamic( + dd.getDependencyRevisionId()) + && ret != null && !ret.getDescriptor().isDefault(); + if (!shouldReturn) { + // check if latest is asked and compare to return the most recent + String mrDesc = mr.getId() + + (mr.getDescriptor().isDefault() ? "[default]" : "") + " from " + + mr.getResolver().getName(); + Message.debug("\tchecking " + mrDesc + " against " + ret); + if (ret == null) { + Message.debug("\tmodule revision kept as first found: " + mrDesc); + ret = mr; + } else if (isAfter(mr, ret, data.getDate())) { + Message.debug("\tmodule revision kept as younger: " + mrDesc); + ret = mr; + } else if (!mr.getDescriptor().isDefault() && ret.getDescriptor().isDefault()) { + Message.debug("\tmodule revision kept as better (not default): " + mrDesc); + ret = mr; + } else { + Message.debug("\tmodule revision discarded as older: " + mrDesc); + } + if (!getSettings().getVersionMatcher().isDynamic(dd.getDependencyRevisionId()) + && !ret.getDescriptor().isDefault()) { + Message.debug("\tmodule revision found and is not default: returning " + + mrDesc); + return resolvedRevision(mr); + } + } else { + return resolvedRevision(mr); + } + } + } + if (ret == null && !errors.isEmpty()) { + if (errors.size() == 1) { + Exception ex = (Exception) errors.get(0); + if (ex instanceof RuntimeException) { + throw (RuntimeException) ex; + } else if (ex instanceof ParseException) { + throw (ParseException) ex; + } else { + throw new RuntimeException(ex.toString(), ex); + } + } else { + StringBuffer err = new StringBuffer(); + for (Iterator iter = errors.iterator(); iter.hasNext();) { + Exception ex = (Exception) iter.next(); + err.append(ex).append("\n"); + } + err.setLength(err.length() - 1); + throw new RuntimeException("several problems occured while resolving " + dd + ":\n" + + err); + } + } + return resolvedRevision(ret); + } + + private ResolvedModuleRevision resolvedRevision(ResolvedModuleRevision mr) { + if (isDual() && mr != null) { + return new ResolvedModuleRevisionProxy(mr, this); + } else { + return mr; + } + } + + private LatestStrategy setLatestIfRequired(DependencyResolver resolver, + LatestStrategy latestStrategy) { + String latestName = getLatestStrategyName(resolver); + if (latestName != null && !"default".equals(latestName)) { + LatestStrategy oldLatest = getLatest(resolver); + setLatest(resolver, latestStrategy); + return oldLatest; + } else { + return null; + } + } + + /** + * Returns true if rmr1 is after rmr2, using the latest strategy to determine which is the + * latest + * + * @param rmr1 + * @param rmr2 + * @return + */ + private boolean isAfter(ResolvedModuleRevision rmr1, ResolvedModuleRevision rmr2, Date date) { + ArtifactInfo[] ais = new ArtifactInfo[] {new ResolvedModuleRevisionArtifactInfo(rmr2), + new ResolvedModuleRevisionArtifactInfo(rmr1)}; + return getLatestStrategy().findLatest(ais, date) != ais[0]; + } + + public void reportFailure() { + for (Iterator iter = _chain.iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + resolver.reportFailure(); + } + } + + public void reportFailure(Artifact art) { + for (Iterator iter = _chain.iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + resolver.reportFailure(art); + } + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + List artifactsToDownload = new ArrayList(Arrays.asList(artifacts)); + DownloadReport report = new DownloadReport(); + for (Iterator iter = _chain.iterator(); iter.hasNext() && !artifactsToDownload.isEmpty();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + DownloadReport r = resolver.download((Artifact[]) artifactsToDownload + .toArray(new Artifact[artifactsToDownload.size()]), options); + ArtifactDownloadReport[] adr = r.getArtifactsReports(); + for (int i = 0; i < adr.length; i++) { + if (adr[i].getDownloadStatus() != DownloadStatus.FAILED) { + artifactsToDownload.remove(adr[i].getArtifact()); + report.addArtifactReport(adr[i]); + } + } + } + for (Iterator iter = artifactsToDownload.iterator(); iter.hasNext();) { + Artifact art = (Artifact) iter.next(); + ArtifactDownloadReport adr = new ArtifactDownloadReport(art); + adr.setDownloadStatus(DownloadStatus.FAILED); + report.addArtifactReport(adr); + } + return report; + } + + public List getResolvers() { + return _chain; + } + + public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { + if (_chain.isEmpty()) { + throw new IllegalStateException("invalid chain resolver with no sub resolver"); + } + ((DependencyResolver) _chain.get(0)).publish(artifact, src, overwrite); + } + + public boolean isReturnFirst() { + return _returnFirst; + } + + public void setReturnFirst(boolean returnFirst) { + _returnFirst = returnFirst; + } + + public void dumpSettings() { + Message.verbose("\t" + getName() + " [chain] " + _chain); + Message.debug("\t\treturn first: " + isReturnFirst()); + Message.debug("\t\tdual: " + isDual()); + for (Iterator iter = _chain.iterator(); iter.hasNext();) { + DependencyResolver r = (DependencyResolver) iter.next(); + Message.debug("\t\t-> " + r.getName()); + } + } + + public boolean exists(Artifact artifact) { + for (Iterator iter = _chain.iterator(); iter.hasNext();) { + DependencyResolver resolver = (DependencyResolver) iter.next(); + if (resolver.exists(artifact)) { + return true; + } + } + return false; + } + + private static void setLatest(DependencyResolver resolver, LatestStrategy latest) { + if (resolver instanceof HasLatestStrategy) { + HasLatestStrategy r = (HasLatestStrategy) resolver; + r.setLatestStrategy(latest); + } + } + + private static LatestStrategy getLatest(DependencyResolver resolver) { + if (resolver instanceof HasLatestStrategy) { + HasLatestStrategy r = (HasLatestStrategy) resolver; + return r.getLatestStrategy(); + } + return null; + } + + private static String getLatestStrategyName(DependencyResolver resolver) { + if (resolver instanceof HasLatestStrategy) { + HasLatestStrategy r = (HasLatestStrategy) resolver; + return r.getLatest(); + } + return null; + } + + public void setDual(boolean b) { + _dual = b; + } + + public boolean isDual() { + return _dual; + } + +} diff --git a/src/java/org/apache/ivy/plugins/resolver/DependencyResolver.java b/src/java/org/apache/ivy/plugins/resolver/DependencyResolver.java index b5a8023a..33ef6c7c 100644 --- a/src/java/org/apache/ivy/plugins/resolver/DependencyResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/DependencyResolver.java @@ -1,98 +1,98 @@ -/* - * 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.text.ParseException; -import java.util.Map; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; - -/** - * - */ -public interface DependencyResolver { - String getName(); - - /** - * Should only be used by configurator - * - * @param name - * the new name of the resolver - */ - void setName(String name); - - /** - * Resolve a module by id, getting its module descriptor and resolving the revision if it's a - * latest one (i.e. a revision uniquely identifying the revision of a module in the current - * environment - If this revision is not able to identify uniquelely the revision of the module - * outside of the current environment, then the resolved revision must begin by ##) - * - * @throws ParseException - */ - ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException; - - DownloadReport download(Artifact[] artifacts, DownloadOptions options); - - boolean exists(Artifact artifact); - - void publish(Artifact artifact, File src, boolean overwrite) throws IOException; - - /** - * Reports last resolve failure as Messages - */ - void reportFailure(); - - /** - * Reports last artifact download failure as Messages - * - * @param art - */ - void reportFailure(Artifact art); - - // listing methods, enable to know what is available from this resolver - // the listing methods must only list entries directly - // available from them, no recursion is needed as long as sub resolvers - // are registered in ivy too. - - /** - * List all the values the given token can take if other tokens are set as described in the - * otherTokenValues map. For instance, if token = "revision" and the map contains - * "organisation"->"foo" "module"->"bar" The results will be the list of revisions of the module - * bar from the org foo. - */ - String[] listTokenValues(String token, Map otherTokenValues); - - OrganisationEntry[] listOrganisations(); - - ModuleEntry[] listModules(OrganisationEntry org); - - RevisionEntry[] listRevisions(ModuleEntry module); - - void dumpSettings(); -} +/* + * 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.text.ParseException; +import java.util.Map; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; + +/** + * + */ +public interface DependencyResolver { + String getName(); + + /** + * Should only be used by configurator + * + * @param name + * the new name of the resolver + */ + void setName(String name); + + /** + * Resolve a module by id, getting its module descriptor and resolving the revision if it's a + * latest one (i.e. a revision uniquely identifying the revision of a module in the current + * environment - If this revision is not able to identify uniquelely the revision of the module + * outside of the current environment, then the resolved revision must begin by ##) + * + * @throws ParseException + */ + ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException; + + DownloadReport download(Artifact[] artifacts, DownloadOptions options); + + boolean exists(Artifact artifact); + + void publish(Artifact artifact, File src, boolean overwrite) throws IOException; + + /** + * Reports last resolve failure as Messages + */ + void reportFailure(); + + /** + * Reports last artifact download failure as Messages + * + * @param art + */ + void reportFailure(Artifact art); + + // listing methods, enable to know what is available from this resolver + // the listing methods must only list entries directly + // available from them, no recursion is needed as long as sub resolvers + // are registered in ivy too. + + /** + * List all the values the given token can take if other tokens are set as described in the + * otherTokenValues map. For instance, if token = "revision" and the map contains + * "organisation"->"foo" "module"->"bar" The results will be the list of revisions of the module + * bar from the org foo. + */ + String[] listTokenValues(String token, Map otherTokenValues); + + OrganisationEntry[] listOrganisations(); + + ModuleEntry[] listModules(OrganisationEntry org); + + RevisionEntry[] listRevisions(ModuleEntry module); + + void dumpSettings(); +} diff --git a/src/java/org/apache/ivy/plugins/resolver/DualResolver.java b/src/java/org/apache/ivy/plugins/resolver/DualResolver.java index cfa77ff3..416fad5e 100644 --- a/src/java/org/apache/ivy/plugins/resolver/DualResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/DualResolver.java @@ -1,141 +1,141 @@ -/* - * 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.text.ParseException; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.plugins.resolver.util.ResolvedModuleRevisionProxy; -import org.apache.ivy.util.Message; - -/** - * DualResolver is used to resolve dependencies with one dependency revolver, called ivy resolver, - * and then download artifacts found in the resolved dependencies from a second dependency resolver, - * called artifact resolver. It is especially useful with resolvers using repository where there is - * a lot of artifact, but no ivy file, like the maven ibiblio repository. If no ivy file is found by - * the ivy resolver, the artifact resolver is used to check if there is artifact corresponding to - * the request (with default ivy file). For artifact download, however, only the artifact resolver - * is used. Exactly two resolvers should be added to this resolver for it to work properly. The - * first resolver added if the ivy resolver, the second is the artifact one. - */ -public class DualResolver extends AbstractResolver { - private DependencyResolver _ivyResolver; - - private DependencyResolver _artifactResolver; - - private boolean _allownomd = true; - - public void add(DependencyResolver resolver) { - if (_ivyResolver == null) { - _ivyResolver = resolver; - } else if (_artifactResolver == null) { - _artifactResolver = resolver; - } else { - throw new IllegalStateException( - "exactly two resolvers must be added: ivy(1) and artifact(2) one"); - } - } - - public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException { - if (_ivyResolver == null || _artifactResolver == null) { - throw new IllegalStateException( - "exactly two resolvers must be added: ivy(1) and artifact(2) one"); - } - data = new ResolveData(data, doValidate(data)); - final ResolvedModuleRevision mr = _ivyResolver.getDependency(dd, data); - if (mr == null) { - checkInterrupted(); - if (isAllownomd()) { - Message.verbose("ivy resolver didn't find " + dd.getDependencyRevisionId() - + ": trying with artifact resolver"); - return _artifactResolver.getDependency(dd, data); - } else { - return null; - } - } else { - return new ResolvedModuleRevisionProxy(mr, this); - } - } - - public void reportFailure() { - _ivyResolver.reportFailure(); - _artifactResolver.reportFailure(); - } - - public void reportFailure(Artifact art) { - _ivyResolver.reportFailure(art); - _artifactResolver.reportFailure(art); - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - return _artifactResolver.download(artifacts, options); - } - - public DependencyResolver getArtifactResolver() { - return _artifactResolver; - } - - public void setArtifactResolver(DependencyResolver artifactResolver) { - _artifactResolver = artifactResolver; - } - - public DependencyResolver getIvyResolver() { - return _ivyResolver; - } - - public void setIvyResolver(DependencyResolver ivyResolver) { - _ivyResolver = ivyResolver; - } - - public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { - if ("ivy".equals(artifact.getType())) { - _ivyResolver.publish(artifact, src, overwrite); - } else { - _artifactResolver.publish(artifact, src, overwrite); - } - } - - public void dumpSettings() { - if (_ivyResolver == null || _artifactResolver == null) { - throw new IllegalStateException( - "exactly two resolvers must be added: ivy(1) and artifact(2) one"); - } - Message.verbose("\t" + getName() + " [dual " + _ivyResolver.getName() + " " - + _artifactResolver.getName() + "]"); - } - - public boolean exists(Artifact artifact) { - return _artifactResolver.exists(artifact); - } - - public boolean isAllownomd() { - return _allownomd; - } - - public void setAllownomd(boolean allownomd) { - _allownomd = allownomd; - } -} +/* + * 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.text.ParseException; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.plugins.resolver.util.ResolvedModuleRevisionProxy; +import org.apache.ivy.util.Message; + +/** + * DualResolver is used to resolve dependencies with one dependency revolver, called ivy resolver, + * and then download artifacts found in the resolved dependencies from a second dependency resolver, + * called artifact resolver. It is especially useful with resolvers using repository where there is + * a lot of artifact, but no ivy file, like the maven ibiblio repository. If no ivy file is found by + * the ivy resolver, the artifact resolver is used to check if there is artifact corresponding to + * the request (with default ivy file). For artifact download, however, only the artifact resolver + * is used. Exactly two resolvers should be added to this resolver for it to work properly. The + * first resolver added if the ivy resolver, the second is the artifact one. + */ +public class DualResolver extends AbstractResolver { + private DependencyResolver _ivyResolver; + + private DependencyResolver _artifactResolver; + + private boolean _allownomd = true; + + public void add(DependencyResolver resolver) { + if (_ivyResolver == null) { + _ivyResolver = resolver; + } else if (_artifactResolver == null) { + _artifactResolver = resolver; + } else { + throw new IllegalStateException( + "exactly two resolvers must be added: ivy(1) and artifact(2) one"); + } + } + + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException { + if (_ivyResolver == null || _artifactResolver == null) { + throw new IllegalStateException( + "exactly two resolvers must be added: ivy(1) and artifact(2) one"); + } + data = new ResolveData(data, doValidate(data)); + final ResolvedModuleRevision mr = _ivyResolver.getDependency(dd, data); + if (mr == null) { + checkInterrupted(); + if (isAllownomd()) { + Message.verbose("ivy resolver didn't find " + dd.getDependencyRevisionId() + + ": trying with artifact resolver"); + return _artifactResolver.getDependency(dd, data); + } else { + return null; + } + } else { + return new ResolvedModuleRevisionProxy(mr, this); + } + } + + public void reportFailure() { + _ivyResolver.reportFailure(); + _artifactResolver.reportFailure(); + } + + public void reportFailure(Artifact art) { + _ivyResolver.reportFailure(art); + _artifactResolver.reportFailure(art); + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + return _artifactResolver.download(artifacts, options); + } + + public DependencyResolver getArtifactResolver() { + return _artifactResolver; + } + + public void setArtifactResolver(DependencyResolver artifactResolver) { + _artifactResolver = artifactResolver; + } + + public DependencyResolver getIvyResolver() { + return _ivyResolver; + } + + public void setIvyResolver(DependencyResolver ivyResolver) { + _ivyResolver = ivyResolver; + } + + public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { + if ("ivy".equals(artifact.getType())) { + _ivyResolver.publish(artifact, src, overwrite); + } else { + _artifactResolver.publish(artifact, src, overwrite); + } + } + + public void dumpSettings() { + if (_ivyResolver == null || _artifactResolver == null) { + throw new IllegalStateException( + "exactly two resolvers must be added: ivy(1) and artifact(2) one"); + } + Message.verbose("\t" + getName() + " [dual " + _ivyResolver.getName() + " " + + _artifactResolver.getName() + "]"); + } + + public boolean exists(Artifact artifact) { + return _artifactResolver.exists(artifact); + } + + public boolean isAllownomd() { + return _allownomd; + } + + public void setAllownomd(boolean allownomd) { + _allownomd = allownomd; + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/FileSystemResolver.java b/src/java/org/apache/ivy/plugins/resolver/FileSystemResolver.java index af0f8f4e..c3f395b8 100644 --- a/src/java/org/apache/ivy/plugins/resolver/FileSystemResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/FileSystemResolver.java @@ -1,45 +1,45 @@ -/* - * 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 org.apache.ivy.plugins.repository.file.FileRepository; - -/** - */ -public class FileSystemResolver extends RepositoryResolver { - public FileSystemResolver() { - setRepository(new FileRepository()); - } - - public String getTypeName() { - return "file"; - } - - public boolean isLocal() { - return getFileRepository().isLocal(); - } - - public void setLocal(boolean local) { - getFileRepository().setLocal(local); - } - - private FileRepository getFileRepository() { - return (FileRepository) getRepository(); - } - -} +/* + * 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 org.apache.ivy.plugins.repository.file.FileRepository; + +/** + */ +public class FileSystemResolver extends RepositoryResolver { + public FileSystemResolver() { + setRepository(new FileRepository()); + } + + public String getTypeName() { + return "file"; + } + + public boolean isLocal() { + return getFileRepository().isLocal(); + } + + public void setLocal(boolean local) { + getFileRepository().setLocal(local); + } + + private FileRepository getFileRepository() { + return (FileRepository) getRepository(); + } + +} diff --git a/src/java/org/apache/ivy/plugins/resolver/IBiblioResolver.java b/src/java/org/apache/ivy/plugins/resolver/IBiblioResolver.java index 00961f42..66a6f277 100644 --- a/src/java/org/apache/ivy/plugins/resolver/IBiblioResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/IBiblioResolver.java @@ -1,243 +1,243 @@ -/* - * 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.text.ParseException; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.resolver.util.ResolvedResource; -import org.apache.ivy.util.Message; - -/** - * IBiblioResolver is a resolver which can be used to resolve dependencies found in the ibiblio - * maven repository, or similar repositories. For more flexibility with url and patterns, see - * {@link org.apache.ivy.plugins.resolver.URLResolver}. - */ -public class IBiblioResolver extends URLResolver { - public static final String DEFAULT_PATTERN = "[module]/[type]s/[artifact]-[revision].[ext]"; - - public static final String DEFAULT_ROOT = "http://www.ibiblio.org/maven/"; - - private String _root = null; - - private String _pattern = null; - - // use poms if m2 compatible is true - private boolean _usepoms = true; - - public IBiblioResolver() { - } - - protected ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data) { - if (isM2compatible() && isUsepoms()) { - ModuleRevisionId mrid = dd.getDependencyRevisionId(); - mrid = convertM2IdForResourceSearch(mrid); - ResolvedResource rres = findResourceUsingPatterns(mrid, getIvyPatterns(), - DefaultArtifact.newPomArtifact(mrid, data.getDate()), getRMDParser(dd, data), data - .getDate()); - return rres; - } else { - return null; - } - } - - public void setM2compatible(boolean m2compatible) { - super.setM2compatible(m2compatible); - if (m2compatible) { - if (_root == null) { - _root = "http://repo1.maven.org/maven2/"; - } - if (_pattern == null) { - _pattern = "[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"; - } - updateWholePattern(); - } - } - - public void ensureConfigured(IvySettings settings) { - if (settings != null && (_root == null || _pattern == null)) { - if (_root == null) { - String root = settings.getVariable("ivy.ibiblio.default.artifact.root"); - if (root != null) { - _root = root; - } else { - settings.configureRepositories(true); - _root = settings.getVariable("ivy.ibiblio.default.artifact.root"); - } - } - if (_pattern == null) { - String pattern = settings.getVariable("ivy.ibiblio.default.artifact.pattern"); - if (pattern != null) { - _pattern = pattern; - } else { - settings.configureRepositories(false); - _pattern = settings.getVariable("ivy.ibiblio.default.artifact.pattern"); - } - } - updateWholePattern(); - } - } - - private String getWholePattern() { - return _root + _pattern; - } - - public String getPattern() { - return _pattern; - } - - public void setPattern(String pattern) { - if (pattern == null) { - throw new NullPointerException("pattern must not be null"); - } - _pattern = pattern; - ensureConfigured(getSettings()); - updateWholePattern(); - } - - public String getRoot() { - return _root; - } - - /** - * Sets the root of the maven like repository. The maven like repository is necessarily an http - * repository. - * - * @param root - * the root of the maven like repository - * @throws IllegalArgumentException - * if root does not start with "http://" - */ - public void setRoot(String root) { - if (root == null) { - throw new NullPointerException("root must not be null"); - } - if (!root.endsWith("/")) { - _root = root + "/"; - } else { - _root = root; - } - ensureConfigured(getSettings()); - updateWholePattern(); - } - - private void updateWholePattern() { - if (isM2compatible() && isUsepoms()) { - setIvyPatterns(Collections.singletonList(getWholePattern())); - } - setArtifactPatterns(Collections.singletonList(getWholePattern())); - } - - public void publish(Artifact artifact, File src) { - throw new UnsupportedOperationException("publish not supported by IBiblioResolver"); - } - - // we do not allow to list organisations on ibiblio, nor modules in ibiblio 1 - public String[] listTokenValues(String token, Map otherTokenValues) { - if (IvyPatternHelper.ORGANISATION_KEY.equals(token)) { - return new String[0]; - } - if (IvyPatternHelper.MODULE_KEY.equals(token) && !isM2compatible()) { - return new String[0]; - } - ensureConfigured(getSettings()); - return super.listTokenValues(token, otherTokenValues); - } - - public OrganisationEntry[] listOrganisations() { - return new OrganisationEntry[0]; - } - - public ModuleEntry[] listModules(OrganisationEntry org) { - if (isM2compatible()) { - ensureConfigured(getSettings()); - return super.listModules(org); - } - return new ModuleEntry[0]; - } - - public RevisionEntry[] listRevisions(ModuleEntry mod) { - ensureConfigured(getSettings()); - return super.listRevisions(mod); - } - - public String getTypeName() { - return "ibiblio"; - } - - // override some methods to ensure configuration - public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException { - ensureConfigured(data.getSettings()); - return super.getDependency(dd, data); - } - - protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { - ensureConfigured(getSettings()); - return super.findArtifactRef(artifact, date); - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - ensureConfigured(options.getSettings()); - return super.download(artifacts, options); - } - - public boolean exists(Artifact artifact) { - ensureConfigured(getSettings()); - return super.exists(artifact); - } - - public List getArtifactPatterns() { - ensureConfigured(getSettings()); - return super.getArtifactPatterns(); - } - - public boolean isUsepoms() { - return _usepoms; - } - - public void setUsepoms(boolean usepoms) { - _usepoms = usepoms; - updateWholePattern(); - } - - public void dumpSettings() { - ensureConfigured(getSettings()); - super.dumpSettings(); - Message.debug("\t\troot: " + getRoot()); - Message.debug("\t\tpattern: " + getPattern()); - Message.debug("\t\tusepoms: " + _usepoms); - } -} +/* + * 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.text.ParseException; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.resolver.util.ResolvedResource; +import org.apache.ivy.util.Message; + +/** + * IBiblioResolver is a resolver which can be used to resolve dependencies found in the ibiblio + * maven repository, or similar repositories. For more flexibility with url and patterns, see + * {@link org.apache.ivy.plugins.resolver.URLResolver}. + */ +public class IBiblioResolver extends URLResolver { + public static final String DEFAULT_PATTERN = "[module]/[type]s/[artifact]-[revision].[ext]"; + + public static final String DEFAULT_ROOT = "http://www.ibiblio.org/maven/"; + + private String _root = null; + + private String _pattern = null; + + // use poms if m2 compatible is true + private boolean _usepoms = true; + + public IBiblioResolver() { + } + + protected ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data) { + if (isM2compatible() && isUsepoms()) { + ModuleRevisionId mrid = dd.getDependencyRevisionId(); + mrid = convertM2IdForResourceSearch(mrid); + ResolvedResource rres = findResourceUsingPatterns(mrid, getIvyPatterns(), + DefaultArtifact.newPomArtifact(mrid, data.getDate()), getRMDParser(dd, data), data + .getDate()); + return rres; + } else { + return null; + } + } + + public void setM2compatible(boolean m2compatible) { + super.setM2compatible(m2compatible); + if (m2compatible) { + if (_root == null) { + _root = "http://repo1.maven.org/maven2/"; + } + if (_pattern == null) { + _pattern = "[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"; + } + updateWholePattern(); + } + } + + public void ensureConfigured(IvySettings settings) { + if (settings != null && (_root == null || _pattern == null)) { + if (_root == null) { + String root = settings.getVariable("ivy.ibiblio.default.artifact.root"); + if (root != null) { + _root = root; + } else { + settings.configureRepositories(true); + _root = settings.getVariable("ivy.ibiblio.default.artifact.root"); + } + } + if (_pattern == null) { + String pattern = settings.getVariable("ivy.ibiblio.default.artifact.pattern"); + if (pattern != null) { + _pattern = pattern; + } else { + settings.configureRepositories(false); + _pattern = settings.getVariable("ivy.ibiblio.default.artifact.pattern"); + } + } + updateWholePattern(); + } + } + + private String getWholePattern() { + return _root + _pattern; + } + + public String getPattern() { + return _pattern; + } + + public void setPattern(String pattern) { + if (pattern == null) { + throw new NullPointerException("pattern must not be null"); + } + _pattern = pattern; + ensureConfigured(getSettings()); + updateWholePattern(); + } + + public String getRoot() { + return _root; + } + + /** + * Sets the root of the maven like repository. The maven like repository is necessarily an http + * repository. + * + * @param root + * the root of the maven like repository + * @throws IllegalArgumentException + * if root does not start with "http://" + */ + public void setRoot(String root) { + if (root == null) { + throw new NullPointerException("root must not be null"); + } + if (!root.endsWith("/")) { + _root = root + "/"; + } else { + _root = root; + } + ensureConfigured(getSettings()); + updateWholePattern(); + } + + private void updateWholePattern() { + if (isM2compatible() && isUsepoms()) { + setIvyPatterns(Collections.singletonList(getWholePattern())); + } + setArtifactPatterns(Collections.singletonList(getWholePattern())); + } + + public void publish(Artifact artifact, File src) { + throw new UnsupportedOperationException("publish not supported by IBiblioResolver"); + } + + // we do not allow to list organisations on ibiblio, nor modules in ibiblio 1 + public String[] listTokenValues(String token, Map otherTokenValues) { + if (IvyPatternHelper.ORGANISATION_KEY.equals(token)) { + return new String[0]; + } + if (IvyPatternHelper.MODULE_KEY.equals(token) && !isM2compatible()) { + return new String[0]; + } + ensureConfigured(getSettings()); + return super.listTokenValues(token, otherTokenValues); + } + + public OrganisationEntry[] listOrganisations() { + return new OrganisationEntry[0]; + } + + public ModuleEntry[] listModules(OrganisationEntry org) { + if (isM2compatible()) { + ensureConfigured(getSettings()); + return super.listModules(org); + } + return new ModuleEntry[0]; + } + + public RevisionEntry[] listRevisions(ModuleEntry mod) { + ensureConfigured(getSettings()); + return super.listRevisions(mod); + } + + public String getTypeName() { + return "ibiblio"; + } + + // override some methods to ensure configuration + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException { + ensureConfigured(data.getSettings()); + return super.getDependency(dd, data); + } + + protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { + ensureConfigured(getSettings()); + return super.findArtifactRef(artifact, date); + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + ensureConfigured(options.getSettings()); + return super.download(artifacts, options); + } + + public boolean exists(Artifact artifact) { + ensureConfigured(getSettings()); + return super.exists(artifact); + } + + public List getArtifactPatterns() { + ensureConfigured(getSettings()); + return super.getArtifactPatterns(); + } + + public boolean isUsepoms() { + return _usepoms; + } + + public void setUsepoms(boolean usepoms) { + _usepoms = usepoms; + updateWholePattern(); + } + + public void dumpSettings() { + ensureConfigured(getSettings()); + super.dumpSettings(); + Message.debug("\t\troot: " + getRoot()); + Message.debug("\t\tpattern: " + getPattern()); + Message.debug("\t\tusepoms: " + _usepoms); + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java b/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java index b2758200..586b5222 100644 --- a/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java @@ -1,300 +1,300 @@ -/* - * 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.net.MalformedURLException; -import java.net.URL; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.resolver.util.ResolvedResource; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.XMLHelper; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * IvyRepResolver is a resolver which can be used to resolve dependencies found in the ivy official - * repository for ivy files and ibiblio maven repository for the artifacts, or similar repositories. - * For more flexibility with url and patterns, see - * {@link org.apache.ivy.plugins.resolver.URLResolver}. - */ -public class IvyRepResolver extends URLResolver { - public static final String DEFAULT_IVYPATTERN = "[organisation]/[module]/ivy-[revision].xml"; - - public static final String DEFAULT_IVYROOT = "http://ivyrep.jayasoft.org/"; - - private String _ivyroot = null; - - private String _ivypattern = null; - - private String _artroot = null; - - private String _artpattern = null; - - public IvyRepResolver() { - } - - private void ensureArtifactConfigured(IvySettings settings) { - if (settings != null && (_artroot == null || _artpattern == null)) { - if (_artroot == null) { - String root = settings.getVariable("ivy.ivyrep.default.artifact.root"); - if (root != null) { - _artroot = root; - } else { - settings.configureRepositories(true); - _artroot = settings.getVariable("ivy.ivyrep.default.artifact.root"); - } - } - if (_artpattern == null) { - String pattern = settings.getVariable("ivy.ivyrep.default.artifact.pattern"); - if (pattern != null) { - _artpattern = pattern; - } else { - settings.configureRepositories(false); - _artpattern = settings.getVariable("ivy.ivyrep.default.artifact.pattern"); - } - } - updateWholeArtPattern(); - } - } - - private void ensureIvyConfigured(IvySettings settings) { - if (settings != null && (_ivyroot == null || _ivypattern == null)) { - if (_ivyroot == null) { - String root = settings.getVariable("ivy.ivyrep.default.ivy.root"); - if (root != null) { - _ivyroot = root; - } else { - settings.configureRepositories(true); - _ivyroot = settings.getVariable("ivy.ivyrep.default.ivy.root"); - } - } - if (_ivypattern == null) { - String pattern = settings.getVariable("ivy.ivyrep.default.ivy.pattern"); - if (pattern != null) { - _ivypattern = pattern; - } else { - settings.configureRepositories(false); - _ivypattern = settings.getVariable("ivy.ivyrep.default.ivy.pattern"); - } - } - updateWholeIvyPattern(); - } - } - - private String getWholeIvyPattern() { - if (_ivyroot == null || _ivypattern == null) { - return null; - } - return _ivyroot + _ivypattern; - } - - private String getWholeArtPattern() { - return _artroot + _artpattern; - } - - public String getIvypattern() { - return _ivypattern; - } - - public void setIvypattern(String pattern) { - if (pattern == null) { - throw new NullPointerException("pattern must not be null"); - } - _ivypattern = pattern; - ensureIvyConfigured(getSettings()); - updateWholeIvyPattern(); - } - - public String getIvyroot() { - return _ivyroot; - } - - /** - * Sets the root of the maven like repository. The maven like repository is necessarily an http - * repository. - * - * @param root - * the root of the maven like repository - * @throws IllegalArgumentException - * if root does not start with "http://" - */ - public void setIvyroot(String root) { - if (root == null) { - throw new NullPointerException("root must not be null"); - } - if (!root.endsWith("/")) { - _ivyroot = root + "/"; - } else { - _ivyroot = root; - } - ensureIvyConfigured(getSettings()); - updateWholeIvyPattern(); - } - - public void setM2compatible(boolean m2compatible) { - if (m2compatible) { - throw new IllegalArgumentException( - "ivyrep does not support maven2 compatibility. Please use ibiblio resolver instead, or even url or filesystem resolvers for more specific needs."); - } - } - - private void updateWholeIvyPattern() { - setIvyPatterns(Collections.singletonList(getWholeIvyPattern())); - } - - private void updateWholeArtPattern() { - setArtifactPatterns(Collections.singletonList(getWholeArtPattern())); - } - - public void publish(Artifact artifact, File src) { - throw new UnsupportedOperationException("publish not supported by IBiblioResolver"); - } - - public String getArtroot() { - return _artroot; - } - - public String getArtpattern() { - return _artpattern; - } - - public void setArtpattern(String pattern) { - if (pattern == null) { - throw new NullPointerException("pattern must not be null"); - } - _artpattern = pattern; - ensureArtifactConfigured(getSettings()); - updateWholeArtPattern(); - } - - public void setArtroot(String root) { - if (root == null) { - throw new NullPointerException("root must not be null"); - } - if (!root.endsWith("/")) { - _artroot = root + "/"; - } else { - _artroot = root; - } - ensureArtifactConfigured(getSettings()); - updateWholeArtPattern(); - } - - public OrganisationEntry[] listOrganisations() { - ensureIvyConfigured(getSettings()); - try { - URL content = new URL(_ivyroot + "content.xml"); - final List ret = new ArrayList(); - XMLHelper.parse(content, null, new DefaultHandler() { - public void startElement(String uri, String localName, String qName, - org.xml.sax.Attributes attributes) throws SAXException { - if ("organisation".equals(qName)) { - String org = attributes.getValue("name"); - if (org != null) { - ret.add(new OrganisationEntry(IvyRepResolver.this, org)); - } - } - } - }); - return (OrganisationEntry[]) ret.toArray(new OrganisationEntry[ret.size()]); - } catch (MalformedURLException e) { - } catch (Exception e) { - Message.warn("unable to parse content.xml file on ivyrep: " + e.getMessage()); - } - return super.listOrganisations(); - } - - // overwrite parent to use only ivy patterns (and not artifact ones, cause ibiblio is too slow - // to answer) - public ModuleEntry[] listModules(OrganisationEntry org) { - ensureIvyConfigured(getSettings()); - Map tokenValues = new HashMap(); - tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation()); - Collection names = findIvyNames(tokenValues, IvyPatternHelper.MODULE_KEY); - ModuleEntry[] ret = new ModuleEntry[names.size()]; - int i = 0; - for (Iterator iter = names.iterator(); iter.hasNext(); i++) { - String name = (String) iter.next(); - ret[i] = new ModuleEntry(org, name); - } - return ret; - } - - public RevisionEntry[] listRevisions(ModuleEntry mod) { - ensureIvyConfigured(getSettings()); - ensureArtifactConfigured(getSettings()); - return super.listRevisions(mod); - } - - public String getTypeName() { - return "ivyrep"; - } - - // override some methods to ensure configuration - public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException { - ensureIvyConfigured(data.getSettings()); - return super.getDependency(dd, data); - } - - protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { - ensureArtifactConfigured(getSettings()); - return super.findArtifactRef(artifact, date); - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - ensureArtifactConfigured(options.getSettings()); - return super.download(artifacts, options); - } - - public boolean exists(Artifact artifact) { - ensureArtifactConfigured(getSettings()); - return super.exists(artifact); - } - - public List getIvyPatterns() { - ensureIvyConfigured(getSettings()); - return super.getIvyPatterns(); - } - - public List getArtifactPatterns() { - ensureArtifactConfigured(getSettings()); - return super.getArtifactPatterns(); - } -} +/* + * 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.net.MalformedURLException; +import java.net.URL; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.resolver.util.ResolvedResource; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.XMLHelper; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * IvyRepResolver is a resolver which can be used to resolve dependencies found in the ivy official + * repository for ivy files and ibiblio maven repository for the artifacts, or similar repositories. + * For more flexibility with url and patterns, see + * {@link org.apache.ivy.plugins.resolver.URLResolver}. + */ +public class IvyRepResolver extends URLResolver { + public static final String DEFAULT_IVYPATTERN = "[organisation]/[module]/ivy-[revision].xml"; + + public static final String DEFAULT_IVYROOT = "http://ivyrep.jayasoft.org/"; + + private String _ivyroot = null; + + private String _ivypattern = null; + + private String _artroot = null; + + private String _artpattern = null; + + public IvyRepResolver() { + } + + private void ensureArtifactConfigured(IvySettings settings) { + if (settings != null && (_artroot == null || _artpattern == null)) { + if (_artroot == null) { + String root = settings.getVariable("ivy.ivyrep.default.artifact.root"); + if (root != null) { + _artroot = root; + } else { + settings.configureRepositories(true); + _artroot = settings.getVariable("ivy.ivyrep.default.artifact.root"); + } + } + if (_artpattern == null) { + String pattern = settings.getVariable("ivy.ivyrep.default.artifact.pattern"); + if (pattern != null) { + _artpattern = pattern; + } else { + settings.configureRepositories(false); + _artpattern = settings.getVariable("ivy.ivyrep.default.artifact.pattern"); + } + } + updateWholeArtPattern(); + } + } + + private void ensureIvyConfigured(IvySettings settings) { + if (settings != null && (_ivyroot == null || _ivypattern == null)) { + if (_ivyroot == null) { + String root = settings.getVariable("ivy.ivyrep.default.ivy.root"); + if (root != null) { + _ivyroot = root; + } else { + settings.configureRepositories(true); + _ivyroot = settings.getVariable("ivy.ivyrep.default.ivy.root"); + } + } + if (_ivypattern == null) { + String pattern = settings.getVariable("ivy.ivyrep.default.ivy.pattern"); + if (pattern != null) { + _ivypattern = pattern; + } else { + settings.configureRepositories(false); + _ivypattern = settings.getVariable("ivy.ivyrep.default.ivy.pattern"); + } + } + updateWholeIvyPattern(); + } + } + + private String getWholeIvyPattern() { + if (_ivyroot == null || _ivypattern == null) { + return null; + } + return _ivyroot + _ivypattern; + } + + private String getWholeArtPattern() { + return _artroot + _artpattern; + } + + public String getIvypattern() { + return _ivypattern; + } + + public void setIvypattern(String pattern) { + if (pattern == null) { + throw new NullPointerException("pattern must not be null"); + } + _ivypattern = pattern; + ensureIvyConfigured(getSettings()); + updateWholeIvyPattern(); + } + + public String getIvyroot() { + return _ivyroot; + } + + /** + * Sets the root of the maven like repository. The maven like repository is necessarily an http + * repository. + * + * @param root + * the root of the maven like repository + * @throws IllegalArgumentException + * if root does not start with "http://" + */ + public void setIvyroot(String root) { + if (root == null) { + throw new NullPointerException("root must not be null"); + } + if (!root.endsWith("/")) { + _ivyroot = root + "/"; + } else { + _ivyroot = root; + } + ensureIvyConfigured(getSettings()); + updateWholeIvyPattern(); + } + + public void setM2compatible(boolean m2compatible) { + if (m2compatible) { + throw new IllegalArgumentException( + "ivyrep does not support maven2 compatibility. Please use ibiblio resolver instead, or even url or filesystem resolvers for more specific needs."); + } + } + + private void updateWholeIvyPattern() { + setIvyPatterns(Collections.singletonList(getWholeIvyPattern())); + } + + private void updateWholeArtPattern() { + setArtifactPatterns(Collections.singletonList(getWholeArtPattern())); + } + + public void publish(Artifact artifact, File src) { + throw new UnsupportedOperationException("publish not supported by IBiblioResolver"); + } + + public String getArtroot() { + return _artroot; + } + + public String getArtpattern() { + return _artpattern; + } + + public void setArtpattern(String pattern) { + if (pattern == null) { + throw new NullPointerException("pattern must not be null"); + } + _artpattern = pattern; + ensureArtifactConfigured(getSettings()); + updateWholeArtPattern(); + } + + public void setArtroot(String root) { + if (root == null) { + throw new NullPointerException("root must not be null"); + } + if (!root.endsWith("/")) { + _artroot = root + "/"; + } else { + _artroot = root; + } + ensureArtifactConfigured(getSettings()); + updateWholeArtPattern(); + } + + public OrganisationEntry[] listOrganisations() { + ensureIvyConfigured(getSettings()); + try { + URL content = new URL(_ivyroot + "content.xml"); + final List ret = new ArrayList(); + XMLHelper.parse(content, null, new DefaultHandler() { + public void startElement(String uri, String localName, String qName, + org.xml.sax.Attributes attributes) throws SAXException { + if ("organisation".equals(qName)) { + String org = attributes.getValue("name"); + if (org != null) { + ret.add(new OrganisationEntry(IvyRepResolver.this, org)); + } + } + } + }); + return (OrganisationEntry[]) ret.toArray(new OrganisationEntry[ret.size()]); + } catch (MalformedURLException e) { + } catch (Exception e) { + Message.warn("unable to parse content.xml file on ivyrep: " + e.getMessage()); + } + return super.listOrganisations(); + } + + // overwrite parent to use only ivy patterns (and not artifact ones, cause ibiblio is too slow + // to answer) + public ModuleEntry[] listModules(OrganisationEntry org) { + ensureIvyConfigured(getSettings()); + Map tokenValues = new HashMap(); + tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation()); + Collection names = findIvyNames(tokenValues, IvyPatternHelper.MODULE_KEY); + ModuleEntry[] ret = new ModuleEntry[names.size()]; + int i = 0; + for (Iterator iter = names.iterator(); iter.hasNext(); i++) { + String name = (String) iter.next(); + ret[i] = new ModuleEntry(org, name); + } + return ret; + } + + public RevisionEntry[] listRevisions(ModuleEntry mod) { + ensureIvyConfigured(getSettings()); + ensureArtifactConfigured(getSettings()); + return super.listRevisions(mod); + } + + public String getTypeName() { + return "ivyrep"; + } + + // override some methods to ensure configuration + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException { + ensureIvyConfigured(data.getSettings()); + return super.getDependency(dd, data); + } + + protected ResolvedResource findArtifactRef(Artifact artifact, Date date) { + ensureArtifactConfigured(getSettings()); + return super.findArtifactRef(artifact, date); + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + ensureArtifactConfigured(options.getSettings()); + return super.download(artifacts, options); + } + + public boolean exists(Artifact artifact) { + ensureArtifactConfigured(getSettings()); + return super.exists(artifact); + } + + public List getIvyPatterns() { + ensureIvyConfigured(getSettings()); + return super.getIvyPatterns(); + } + + public List getArtifactPatterns() { + ensureArtifactConfigured(getSettings()); + return super.getArtifactPatterns(); + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/RepositoryResolver.java b/src/java/org/apache/ivy/plugins/resolver/RepositoryResolver.java index 7b143cdc..72818a68 100644 --- a/src/java/org/apache/ivy/plugins/resolver/RepositoryResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/RepositoryResolver.java @@ -1,247 +1,247 @@ -/* - * 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.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.plugins.repository.AbstractRepository; -import org.apache.ivy.plugins.repository.Repository; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.plugins.resolver.util.ResolvedResource; -import org.apache.ivy.plugins.resolver.util.ResolverHelper; -import org.apache.ivy.plugins.resolver.util.ResourceMDParser; -import org.apache.ivy.plugins.version.VersionMatcher; -import org.apache.ivy.util.ChecksumHelper; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; - -/** - * - */ -public class RepositoryResolver extends AbstractResourceResolver { - - private Repository _repository; - - private Boolean _alwaysCheckExactRevision = null; - - public RepositoryResolver() { - } - - public Repository getRepository() { - return _repository; - } - - public void setRepository(Repository repository) { - _repository = repository; - } - - public void setName(String name) { - super.setName(name); - if (_repository instanceof AbstractRepository) { - ((AbstractRepository) _repository).setName(name); - } - } - - protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern, - Artifact artifact, ResourceMDParser rmdparser, Date date) { - return findResourceUsingPattern(getName(), getRepository(), getLatestStrategy(), - getSettings().getVersionMatcher(), rmdparser, mrid, pattern, artifact, date, - isAlwaysCheckExactRevision()); - } - - public static ResolvedResource findResourceUsingPattern(String name, Repository repository, - LatestStrategy strategy, VersionMatcher versionMatcher, ResourceMDParser rmdparser, - ModuleRevisionId mrid, String pattern, Artifact artifact, Date date, - boolean alwaysCheckExactRevision) { - try { - if (!versionMatcher.isDynamic(mrid) || alwaysCheckExactRevision) { - String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact); - Message.debug("\t trying " + resourceName); - logAttempt(resourceName); - Resource res = repository.getResource(resourceName); - boolean reachable = res.exists(); - if (reachable) { - String revision = pattern.indexOf(IvyPatternHelper.REVISION_KEY) == -1 ? "working@" - + name - : mrid.getRevision(); - return new ResolvedResource(res, revision); - } else if (versionMatcher.isDynamic(mrid)) { - return findDynamicResourceUsingPattern(name, repository, strategy, - versionMatcher, rmdparser, mrid, pattern, artifact, date); - } else { - Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res=" - + res); - return null; - } - } else { - return findDynamicResourceUsingPattern(name, repository, strategy, versionMatcher, - rmdparser, mrid, pattern, artifact, date); - } - } catch (IOException ex) { - throw new RuntimeException(name + ": unable to get resource for " + mrid + ": res=" - + IvyPatternHelper.substitute(pattern, mrid, artifact) + ": " + ex, ex); - } - } - - private static ResolvedResource findDynamicResourceUsingPattern(String name, - Repository repository, LatestStrategy strategy, VersionMatcher versionMatcher, - ResourceMDParser rmdparser, ModuleRevisionId mrid, String pattern, Artifact artifact, - Date date) { - logAttempt(IvyPatternHelper.substitute(pattern, ModuleRevisionId.newInstance(mrid, - IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY)), artifact)); - ResolvedResource[] rress = ResolverHelper.findAll(repository, mrid, pattern, artifact); - if (rress == null) { - Message.debug("\t" + name + ": unable to list resources for " + mrid + ": pattern=" - + pattern); - return null; - } else { - ResolvedResource found = findResource(rress, name, strategy, versionMatcher, rmdparser, - mrid, date); - if (found == null) { - Message.debug("\t" + name + ": no resource found for " + mrid + ": pattern=" - + pattern); - } - return found; - } - } - - protected long get(Resource resource, File dest) throws IOException { - Message.verbose("\t" + getName() + ": downloading " + resource.getName()); - Message.debug("\t\tto " + dest); - if (dest.getParentFile() != null) { - dest.getParentFile().mkdirs(); - } - _repository.get(resource.getName(), dest); - return dest.length(); - } - - public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { - String destPattern; - if ("ivy".equals(artifact.getType()) && !getIvyPatterns().isEmpty()) { - destPattern = (String) getIvyPatterns().get(0); - } else if (!getArtifactPatterns().isEmpty()) { - destPattern = (String) getArtifactPatterns().get(0); - } else { - throw new IllegalStateException("impossible to publish " + artifact + " using " + this - + ": no artifact pattern defined"); - } - // Check for m2 compatibility - ModuleRevisionId mrid = artifact.getModuleRevisionId(); - if (isM2compatible()) { - mrid = convertM2IdForResourceSearch(mrid); - } - - String dest = IvyPatternHelper.substitute(destPattern, mrid, artifact); - - put(artifact, src, dest, overwrite); - Message.info("\tpublished " + artifact.getName() + " to " + hidePassword(dest)); - } - - private void put(Artifact artifact, File src, String dest, boolean overwrite) - throws IOException { - _repository.put(artifact, src, dest, overwrite); - String[] checksums = getChecksumAlgorithms(); - for (int i = 0; i < checksums.length; i++) { - putChecksum(artifact, src, dest, overwrite, checksums[i]); - } - } - - private void putChecksum(Artifact artifact, File src, String dest, boolean overwrite, - String algorithm) throws IOException { - File csFile = File.createTempFile("ivytemp", algorithm); - try { - FileUtil.copy(new ByteArrayInputStream(ChecksumHelper.computeAsString(src, algorithm) - .getBytes()), csFile, null); - _repository.put(DefaultArtifact.cloneWithAnotherTypeAndExt(artifact, algorithm, - artifact.getExt() + "." + algorithm), csFile, dest + "." + algorithm, overwrite); - } finally { - csFile.delete(); - } - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - EventManager eventManager = options.getEventManager(); - try { - if (eventManager != null) { - _repository.addTransferListener(eventManager); - } - return super.download(artifacts, options); - } finally { - if (eventManager != null) { - _repository.removeTransferListener(eventManager); - } - } - } - - protected void findTokenValues(Collection names, List patterns, Map tokenValues, String token) { - for (Iterator iter = patterns.iterator(); iter.hasNext();) { - String pattern = (String) iter.next(); - String partiallyResolvedPattern = IvyPatternHelper.substituteTokens(pattern, - tokenValues); - String[] values = ResolverHelper.listTokenValues(_repository, partiallyResolvedPattern, - token); - if (values != null) { - names.addAll(Arrays.asList(values)); - } - } - } - - public String getTypeName() { - return "repository"; - } - - public void dumpSettings() { - super.dumpSettings(); - Message.debug("\t\trepository: " + getRepository()); - } - - public void setSettings(IvySettings settings) { - super.setSettings(settings); - if (settings != null) { - if (_alwaysCheckExactRevision == null) { - _alwaysCheckExactRevision = Boolean.valueOf(settings - .getVariable("ivy.default.always.check.exact.revision")); - } - } - } - - public boolean isAlwaysCheckExactRevision() { - return _alwaysCheckExactRevision == null ? true : _alwaysCheckExactRevision.booleanValue(); - } - - public void setAlwaysCheckExactRevision(boolean alwaysCheckExactRevision) { - _alwaysCheckExactRevision = Boolean.valueOf(alwaysCheckExactRevision); - } -} +/* + * 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.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.plugins.repository.AbstractRepository; +import org.apache.ivy.plugins.repository.Repository; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.plugins.resolver.util.ResolvedResource; +import org.apache.ivy.plugins.resolver.util.ResolverHelper; +import org.apache.ivy.plugins.resolver.util.ResourceMDParser; +import org.apache.ivy.plugins.version.VersionMatcher; +import org.apache.ivy.util.ChecksumHelper; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; + +/** + * + */ +public class RepositoryResolver extends AbstractResourceResolver { + + private Repository _repository; + + private Boolean _alwaysCheckExactRevision = null; + + public RepositoryResolver() { + } + + public Repository getRepository() { + return _repository; + } + + public void setRepository(Repository repository) { + _repository = repository; + } + + public void setName(String name) { + super.setName(name); + if (_repository instanceof AbstractRepository) { + ((AbstractRepository) _repository).setName(name); + } + } + + protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern, + Artifact artifact, ResourceMDParser rmdparser, Date date) { + return findResourceUsingPattern(getName(), getRepository(), getLatestStrategy(), + getSettings().getVersionMatcher(), rmdparser, mrid, pattern, artifact, date, + isAlwaysCheckExactRevision()); + } + + public static ResolvedResource findResourceUsingPattern(String name, Repository repository, + LatestStrategy strategy, VersionMatcher versionMatcher, ResourceMDParser rmdparser, + ModuleRevisionId mrid, String pattern, Artifact artifact, Date date, + boolean alwaysCheckExactRevision) { + try { + if (!versionMatcher.isDynamic(mrid) || alwaysCheckExactRevision) { + String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact); + Message.debug("\t trying " + resourceName); + logAttempt(resourceName); + Resource res = repository.getResource(resourceName); + boolean reachable = res.exists(); + if (reachable) { + String revision = pattern.indexOf(IvyPatternHelper.REVISION_KEY) == -1 ? "working@" + + name + : mrid.getRevision(); + return new ResolvedResource(res, revision); + } else if (versionMatcher.isDynamic(mrid)) { + return findDynamicResourceUsingPattern(name, repository, strategy, + versionMatcher, rmdparser, mrid, pattern, artifact, date); + } else { + Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res=" + + res); + return null; + } + } else { + return findDynamicResourceUsingPattern(name, repository, strategy, versionMatcher, + rmdparser, mrid, pattern, artifact, date); + } + } catch (IOException ex) { + throw new RuntimeException(name + ": unable to get resource for " + mrid + ": res=" + + IvyPatternHelper.substitute(pattern, mrid, artifact) + ": " + ex, ex); + } + } + + private static ResolvedResource findDynamicResourceUsingPattern(String name, + Repository repository, LatestStrategy strategy, VersionMatcher versionMatcher, + ResourceMDParser rmdparser, ModuleRevisionId mrid, String pattern, Artifact artifact, + Date date) { + logAttempt(IvyPatternHelper.substitute(pattern, ModuleRevisionId.newInstance(mrid, + IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY)), artifact)); + ResolvedResource[] rress = ResolverHelper.findAll(repository, mrid, pattern, artifact); + if (rress == null) { + Message.debug("\t" + name + ": unable to list resources for " + mrid + ": pattern=" + + pattern); + return null; + } else { + ResolvedResource found = findResource(rress, name, strategy, versionMatcher, rmdparser, + mrid, date); + if (found == null) { + Message.debug("\t" + name + ": no resource found for " + mrid + ": pattern=" + + pattern); + } + return found; + } + } + + protected long get(Resource resource, File dest) throws IOException { + Message.verbose("\t" + getName() + ": downloading " + resource.getName()); + Message.debug("\t\tto " + dest); + if (dest.getParentFile() != null) { + dest.getParentFile().mkdirs(); + } + _repository.get(resource.getName(), dest); + return dest.length(); + } + + public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { + String destPattern; + if ("ivy".equals(artifact.getType()) && !getIvyPatterns().isEmpty()) { + destPattern = (String) getIvyPatterns().get(0); + } else if (!getArtifactPatterns().isEmpty()) { + destPattern = (String) getArtifactPatterns().get(0); + } else { + throw new IllegalStateException("impossible to publish " + artifact + " using " + this + + ": no artifact pattern defined"); + } + // Check for m2 compatibility + ModuleRevisionId mrid = artifact.getModuleRevisionId(); + if (isM2compatible()) { + mrid = convertM2IdForResourceSearch(mrid); + } + + String dest = IvyPatternHelper.substitute(destPattern, mrid, artifact); + + put(artifact, src, dest, overwrite); + Message.info("\tpublished " + artifact.getName() + " to " + hidePassword(dest)); + } + + private void put(Artifact artifact, File src, String dest, boolean overwrite) + throws IOException { + _repository.put(artifact, src, dest, overwrite); + String[] checksums = getChecksumAlgorithms(); + for (int i = 0; i < checksums.length; i++) { + putChecksum(artifact, src, dest, overwrite, checksums[i]); + } + } + + private void putChecksum(Artifact artifact, File src, String dest, boolean overwrite, + String algorithm) throws IOException { + File csFile = File.createTempFile("ivytemp", algorithm); + try { + FileUtil.copy(new ByteArrayInputStream(ChecksumHelper.computeAsString(src, algorithm) + .getBytes()), csFile, null); + _repository.put(DefaultArtifact.cloneWithAnotherTypeAndExt(artifact, algorithm, + artifact.getExt() + "." + algorithm), csFile, dest + "." + algorithm, overwrite); + } finally { + csFile.delete(); + } + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + EventManager eventManager = options.getEventManager(); + try { + if (eventManager != null) { + _repository.addTransferListener(eventManager); + } + return super.download(artifacts, options); + } finally { + if (eventManager != null) { + _repository.removeTransferListener(eventManager); + } + } + } + + protected void findTokenValues(Collection names, List patterns, Map tokenValues, String token) { + for (Iterator iter = patterns.iterator(); iter.hasNext();) { + String pattern = (String) iter.next(); + String partiallyResolvedPattern = IvyPatternHelper.substituteTokens(pattern, + tokenValues); + String[] values = ResolverHelper.listTokenValues(_repository, partiallyResolvedPattern, + token); + if (values != null) { + names.addAll(Arrays.asList(values)); + } + } + } + + public String getTypeName() { + return "repository"; + } + + public void dumpSettings() { + super.dumpSettings(); + Message.debug("\t\trepository: " + getRepository()); + } + + public void setSettings(IvySettings settings) { + super.setSettings(settings); + if (settings != null) { + if (_alwaysCheckExactRevision == null) { + _alwaysCheckExactRevision = Boolean.valueOf(settings + .getVariable("ivy.default.always.check.exact.revision")); + } + } + } + + public boolean isAlwaysCheckExactRevision() { + return _alwaysCheckExactRevision == null ? true : _alwaysCheckExactRevision.booleanValue(); + } + + public void setAlwaysCheckExactRevision(boolean alwaysCheckExactRevision) { + _alwaysCheckExactRevision = Boolean.valueOf(alwaysCheckExactRevision); + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/SFTPResolver.java b/src/java/org/apache/ivy/plugins/resolver/SFTPResolver.java index 531e6c28..190d1502 100644 --- a/src/java/org/apache/ivy/plugins/resolver/SFTPResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/SFTPResolver.java @@ -1,41 +1,41 @@ -/* - * 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 org.apache.ivy.plugins.repository.sftp.SFTPRepository; - -/** - * This resolver is able to work with any sftp server. It supports listing and publishing. The - * server host should absolutely be set using setHost. basedir defaults to . port default to 22 - * username and password will be prompted using a dialog box if not set. So if you are in an - * headless environment, provide username and password. - */ -public class SFTPResolver extends AbstractSshBasedResolver { - - public SFTPResolver() { - setRepository(new SFTPRepository()); - } - - public String getTypeName() { - return "sftp"; - } - - public SFTPRepository getSFTPRepository() { - return (SFTPRepository) getRepository(); - } -} +/* + * 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 org.apache.ivy.plugins.repository.sftp.SFTPRepository; + +/** + * This resolver is able to work with any sftp server. It supports listing and publishing. The + * server host should absolutely be set using setHost. basedir defaults to . port default to 22 + * username and password will be prompted using a dialog box if not set. So if you are in an + * headless environment, provide username and password. + */ +public class SFTPResolver extends AbstractSshBasedResolver { + + public SFTPResolver() { + setRepository(new SFTPRepository()); + } + + public String getTypeName() { + return "sftp"; + } + + public SFTPRepository getSFTPRepository() { + return (SFTPRepository) getRepository(); + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/URLResolver.java b/src/java/org/apache/ivy/plugins/resolver/URLResolver.java index 43214982..7afacdc3 100644 --- a/src/java/org/apache/ivy/plugins/resolver/URLResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/URLResolver.java @@ -1,34 +1,34 @@ -/* - * 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 org.apache.ivy.plugins.repository.url.URLRepository; - -/** - * This resolver is able to work with any URLs, it handles latest revisions with file and http urls - * only, and it does not handle publishing - */ -public class URLResolver extends RepositoryResolver { - public URLResolver() { - setRepository(new URLRepository()); - } - - public String getTypeName() { - return "url"; - } -} +/* + * 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 org.apache.ivy.plugins.repository.url.URLRepository; + +/** + * This resolver is able to work with any URLs, it handles latest revisions with file and http urls + * only, and it does not handle publishing + */ +public class URLResolver extends RepositoryResolver { + public URLResolver() { + setRepository(new URLRepository()); + } + + public String getTypeName() { + return "url"; + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/VfsResolver.java b/src/java/org/apache/ivy/plugins/resolver/VfsResolver.java index ec112d45..81641d64 100644 --- a/src/java/org/apache/ivy/plugins/resolver/VfsResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/VfsResolver.java @@ -1,61 +1,61 @@ -/* - * 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.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.plugins.repository.vfs.VfsRepository; - -/** - * - */ -public class VfsResolver extends RepositoryResolver { - private static Pattern URLPattern = Pattern.compile("[a-z]*://(.+):(.+)@.*"); - - private static int PASSWORD_GROUP = 2; - - public VfsResolver() { - setRepository(new VfsRepository()); - } - - public String getTypeName() { - return "vfs"; - } - - public String hidePassword(String name) { - return prepareForDisplay(name); - } - - public static String prepareForDisplay(String name) { - StringBuffer s = new StringBuffer(name); - Matcher m = URLPattern.matcher(s); - if (m.matches()) { - final String password = m.group(PASSWORD_GROUP); - final int passwordposi = s.indexOf(password); - StringBuffer stars = new StringBuffer(password); - for (int posi = 0; posi < password.length(); posi++) { - stars.setCharAt(posi, '*'); - } - String replacement = stars.toString(); - s = s.replace(passwordposi, passwordposi + password.length(), replacement); - } - return s.toString(); - - } -} +/* + * 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.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.plugins.repository.vfs.VfsRepository; + +/** + * + */ +public class VfsResolver extends RepositoryResolver { + private static Pattern URLPattern = Pattern.compile("[a-z]*://(.+):(.+)@.*"); + + private static int PASSWORD_GROUP = 2; + + public VfsResolver() { + setRepository(new VfsRepository()); + } + + public String getTypeName() { + return "vfs"; + } + + public String hidePassword(String name) { + return prepareForDisplay(name); + } + + public static String prepareForDisplay(String name) { + StringBuffer s = new StringBuffer(name); + Matcher m = URLPattern.matcher(s); + if (m.matches()) { + final String password = m.group(PASSWORD_GROUP); + final int passwordposi = s.indexOf(password); + StringBuffer stars = new StringBuffer(password); + for (int posi = 0; posi < password.length(); posi++) { + stars.setCharAt(posi, '*'); + } + String replacement = stars.toString(); + s = s.replace(passwordposi, passwordposi + password.length(), replacement); + } + return s.toString(); + + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/VsftpResolver.java b/src/java/org/apache/ivy/plugins/resolver/VsftpResolver.java index e2cb20fc..e2c4e245 100644 --- a/src/java/org/apache/ivy/plugins/resolver/VsftpResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/VsftpResolver.java @@ -1,74 +1,74 @@ -/* - * 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 org.apache.ivy.plugins.repository.vsftp.VsftpRepository; - -/** - * This resolver uses SecureCRT vsft to access an sftp server. It supports listing and publishing. - * The server host should absolutely be set using setHost, so does the username. - */ -public class VsftpResolver extends RepositoryResolver { - public VsftpResolver() { - setRepository(new VsftpRepository()); - } - - public String getTypeName() { - return "vsftp"; - } - - public VsftpRepository getVsftpRepository() { - return (VsftpRepository) getRepository(); - } - - public void disconnect() { - getVsftpRepository().disconnect(); - } - - public String getAuthentication() { - return getVsftpRepository().getAuthentication(); - } - - public String getHost() { - return getVsftpRepository().getHost(); - } - - public String getUsername() { - return getVsftpRepository().getUsername(); - } - - public void setAuthentication(String authentication) { - getVsftpRepository().setAuthentication(authentication); - } - - public void setHost(String host) { - getVsftpRepository().setHost(host); - } - - public void setUsername(String username) { - getVsftpRepository().setUsername(username); - } - - public void setReuseConnection(long time) { - getVsftpRepository().setReuseConnection(time); - } - - public void setReadTimeout(long readTimeout) { - getVsftpRepository().setReadTimeout(readTimeout); - } -} +/* + * 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 org.apache.ivy.plugins.repository.vsftp.VsftpRepository; + +/** + * This resolver uses SecureCRT vsft to access an sftp server. It supports listing and publishing. + * The server host should absolutely be set using setHost, so does the username. + */ +public class VsftpResolver extends RepositoryResolver { + public VsftpResolver() { + setRepository(new VsftpRepository()); + } + + public String getTypeName() { + return "vsftp"; + } + + public VsftpRepository getVsftpRepository() { + return (VsftpRepository) getRepository(); + } + + public void disconnect() { + getVsftpRepository().disconnect(); + } + + public String getAuthentication() { + return getVsftpRepository().getAuthentication(); + } + + public String getHost() { + return getVsftpRepository().getHost(); + } + + public String getUsername() { + return getVsftpRepository().getUsername(); + } + + public void setAuthentication(String authentication) { + getVsftpRepository().setAuthentication(authentication); + } + + public void setHost(String host) { + getVsftpRepository().setHost(host); + } + + public void setUsername(String username) { + getVsftpRepository().setUsername(username); + } + + public void setReuseConnection(long time) { + getVsftpRepository().setReuseConnection(time); + } + + public void setReadTimeout(long readTimeout) { + getVsftpRepository().setReadTimeout(readTimeout); + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/ApacheHttpURLLister.java b/src/java/org/apache/ivy/plugins/resolver/util/ApacheHttpURLLister.java index fd907e2f..df268e20 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/ApacheHttpURLLister.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/ApacheHttpURLLister.java @@ -1,40 +1,40 @@ -/* - * 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.util; - -import java.io.IOException; -import java.net.URL; -import java.util.List; - -import org.apache.ivy.util.url.ApacheURLLister; - -public class ApacheHttpURLLister implements URLLister { - private ApacheURLLister _lister = new ApacheURLLister(); - - public boolean accept(String pattern) { - return pattern.startsWith("http"); - } - - public List listAll(URL url) throws IOException { - return _lister.listAll(url); - } - - public String toString() { - return "apache http lister"; - } -} +/* + * 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.util; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import org.apache.ivy.util.url.ApacheURLLister; + +public class ApacheHttpURLLister implements URLLister { + private ApacheURLLister _lister = new ApacheURLLister(); + + public boolean accept(String pattern) { + return pattern.startsWith("http"); + } + + public List listAll(URL url) throws IOException { + return _lister.listAll(url); + } + + public String toString() { + return "apache http lister"; + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java b/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java index f1e0c5a4..c19a4cad 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/FileURLLister.java @@ -1,61 +1,61 @@ -/* - * 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.util; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class FileURLLister implements URLLister { - private File _basedir; - - public FileURLLister() { - this(null); - } - - public FileURLLister(File baseDir) { - _basedir = baseDir; - } - - public boolean accept(String pattern) { - return pattern.startsWith("file"); - } - - public List listAll(URL url) throws IOException { - String path = url.getPath(); - File file = _basedir == null ? new File(path) : new File(_basedir, path); - if (file.exists() && file.isDirectory()) { - String[] files = file.list(); - List ret = new ArrayList(files.length); - URL context = url.getPath().endsWith("/") ? url : new URL(url.toExternalForm() + "/"); - for (int i = 0; i < files.length; i++) { - ret.add(new URL(context, files[i])); - } - return ret; - } else { - return Collections.EMPTY_LIST; - } - } - - public String toString() { - return "file lister"; - } -} +/* + * 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.util; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class FileURLLister implements URLLister { + private File _basedir; + + public FileURLLister() { + this(null); + } + + public FileURLLister(File baseDir) { + _basedir = baseDir; + } + + public boolean accept(String pattern) { + return pattern.startsWith("file"); + } + + public List listAll(URL url) throws IOException { + String path = url.getPath(); + File file = _basedir == null ? new File(path) : new File(_basedir, path); + if (file.exists() && file.isDirectory()) { + String[] files = file.list(); + List ret = new ArrayList(files.length); + URL context = url.getPath().endsWith("/") ? url : new URL(url.toExternalForm() + "/"); + for (int i = 0; i < files.length; i++) { + ret.add(new URL(context, files[i])); + } + return ret; + } else { + return Collections.EMPTY_LIST; + } + } + + public String toString() { + return "file lister"; + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/HasLatestStrategy.java b/src/java/org/apache/ivy/plugins/resolver/util/HasLatestStrategy.java index 1f06855a..ea4b27dd 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/HasLatestStrategy.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/HasLatestStrategy.java @@ -1,28 +1,28 @@ -/* - * 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.util; - -import org.apache.ivy.plugins.latest.LatestStrategy; - -public interface HasLatestStrategy { - public LatestStrategy getLatestStrategy(); - - public void setLatestStrategy(LatestStrategy latestStrategy); - - public String getLatest(); -} +/* + * 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.util; + +import org.apache.ivy.plugins.latest.LatestStrategy; + +public interface HasLatestStrategy { + public LatestStrategy getLatestStrategy(); + + public void setLatestStrategy(LatestStrategy latestStrategy); + + public String getLatest(); +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/MDResolvedResource.java b/src/java/org/apache/ivy/plugins/resolver/util/MDResolvedResource.java index 83678f4d..8a02cb7a 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/MDResolvedResource.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/MDResolvedResource.java @@ -1,35 +1,35 @@ -/* - * 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.util; - -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.plugins.repository.Resource; - -public class MDResolvedResource extends ResolvedResource { - private ResolvedModuleRevision _rmr; - - public MDResolvedResource(Resource res, String rev, ResolvedModuleRevision rmr) { - super(res, rev); - _rmr = rmr; - } - - public ResolvedModuleRevision getResolvedModuleRevision() { - return _rmr; - } - -} +/* + * 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.util; + +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.plugins.repository.Resource; + +public class MDResolvedResource extends ResolvedResource { + private ResolvedModuleRevision _rmr; + + public MDResolvedResource(Resource res, String rev, ResolvedModuleRevision rmr) { + super(res, rev); + _rmr = rmr; + } + + public ResolvedModuleRevision getResolvedModuleRevision() { + return _rmr; + } + +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/ResolvedModuleRevisionProxy.java b/src/java/org/apache/ivy/plugins/resolver/util/ResolvedModuleRevisionProxy.java index fa59d980..2929040d 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/ResolvedModuleRevisionProxy.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/ResolvedModuleRevisionProxy.java @@ -1,80 +1,80 @@ -/* - * 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.util; - -import java.net.URL; -import java.util.Date; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; -import org.apache.ivy.plugins.resolver.DependencyResolver; - -/** - * the same ResolvedModuleRevision except that we say that it is another resolver the artifact - * resolver, so that it's it that is used for artifact download ==> forward all except - * getArtifactResolver method - */ -public final class ResolvedModuleRevisionProxy implements ResolvedModuleRevision { - private final ResolvedModuleRevision _mr; - - DependencyResolver _resolver; - - public ResolvedModuleRevisionProxy(ResolvedModuleRevision mr, DependencyResolver artresolver) { - if (mr == null) { - throw new NullPointerException("null module revision not allowed"); - } - if (artresolver == null) { - throw new NullPointerException("null resolver not allowed"); - } - _mr = mr; - _resolver = artresolver; - } - - public DependencyResolver getResolver() { - return _mr.getResolver(); - } - - public DependencyResolver getArtifactResolver() { - return _resolver; - } - - public ModuleRevisionId getId() { - return _mr.getId(); - } - - public Date getPublicationDate() { - return _mr.getPublicationDate(); - } - - public ModuleDescriptor getDescriptor() { - return _mr.getDescriptor(); - } - - public boolean isDownloaded() { - return _mr.isDownloaded(); - } - - public boolean isSearched() { - return _mr.isSearched(); - } - - public URL getLocalMDUrl() { - return _mr.getLocalMDUrl(); - } -} \ No newline at end of file +/* + * 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.util; + +import java.net.URL; +import java.util.Date; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; +import org.apache.ivy.plugins.resolver.DependencyResolver; + +/** + * the same ResolvedModuleRevision except that we say that it is another resolver the artifact + * resolver, so that it's it that is used for artifact download ==> forward all except + * getArtifactResolver method + */ +public final class ResolvedModuleRevisionProxy implements ResolvedModuleRevision { + private final ResolvedModuleRevision _mr; + + DependencyResolver _resolver; + + public ResolvedModuleRevisionProxy(ResolvedModuleRevision mr, DependencyResolver artresolver) { + if (mr == null) { + throw new NullPointerException("null module revision not allowed"); + } + if (artresolver == null) { + throw new NullPointerException("null resolver not allowed"); + } + _mr = mr; + _resolver = artresolver; + } + + public DependencyResolver getResolver() { + return _mr.getResolver(); + } + + public DependencyResolver getArtifactResolver() { + return _resolver; + } + + public ModuleRevisionId getId() { + return _mr.getId(); + } + + public Date getPublicationDate() { + return _mr.getPublicationDate(); + } + + public ModuleDescriptor getDescriptor() { + return _mr.getDescriptor(); + } + + public boolean isDownloaded() { + return _mr.isDownloaded(); + } + + public boolean isSearched() { + return _mr.isSearched(); + } + + public URL getLocalMDUrl() { + return _mr.getLocalMDUrl(); + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/ResolvedResource.java b/src/java/org/apache/ivy/plugins/resolver/util/ResolvedResource.java index fdaf0af5..f902e827 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/ResolvedResource.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/ResolvedResource.java @@ -1,48 +1,48 @@ -/* - * 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.util; - -import org.apache.ivy.plugins.latest.ArtifactInfo; -import org.apache.ivy.plugins.repository.Resource; - -public class ResolvedResource implements ArtifactInfo { - private Resource _res; - - private String _rev; - - public ResolvedResource(Resource res, String rev) { - _res = res; - _rev = rev; - } - - public String getRevision() { - return _rev; - } - - public Resource getResource() { - return _res; - } - - public String toString() { - return _res + " (" + _rev + ")"; - } - - public long getLastModified() { - return getResource().getLastModified(); - } -} \ No newline at end of file +/* + * 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.util; + +import org.apache.ivy.plugins.latest.ArtifactInfo; +import org.apache.ivy.plugins.repository.Resource; + +public class ResolvedResource implements ArtifactInfo { + private Resource _res; + + private String _rev; + + public ResolvedResource(Resource res, String rev) { + _res = res; + _rev = rev; + } + + public String getRevision() { + return _rev; + } + + public Resource getResource() { + return _res; + } + + public String toString() { + return _res + " (" + _rev + ")"; + } + + public long getLastModified() { + return getResource().getLastModified(); + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java b/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java index 5c43d92f..a9079a34 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java @@ -1,327 +1,327 @@ -/* - * 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.util; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.repository.Repository; -import org.apache.ivy.plugins.repository.Resource; -import org.apache.ivy.util.Message; - -public class ResolverHelper { - // lists all the values a token can take in a pattern, as listed by a given url lister - public static String[] listTokenValues(Repository rep, String pattern, String token) { - String fileSep = rep.getFileSeparator(); - pattern = rep.standardize(pattern); - String tokenString = IvyPatternHelper.getTokenString(token); - int index = pattern.indexOf(tokenString); - if (index == -1) { - Message.verbose("unable to list " + token + " in " + pattern - + ": token not found in pattern"); - return null; - } - if (((pattern.length() <= index + tokenString.length()) || fileSep.equals(pattern - .substring(index + tokenString.length(), index + tokenString.length() + 1))) - && (index == 0 || fileSep.equals(pattern.substring(index - 1, index)))) { - // the searched token is a whole name - String root = pattern.substring(0, index); - return listAll(rep, root); - } else { - int slashIndex = pattern.substring(0, index).lastIndexOf(fileSep); - String root = slashIndex == -1 ? "" : pattern.substring(0, slashIndex); - - try { - Message.debug("\tusing " + rep + " to list all in " + root); - List all = rep.list(root); - if (all != null) { - Message.debug("\t\tfound " + all.size() + " urls"); - List ret = new ArrayList(all.size()); - int endNameIndex = pattern.indexOf(fileSep, slashIndex + 1); - String namePattern; - if (endNameIndex != -1) { - namePattern = pattern.substring(slashIndex + 1, endNameIndex); - } else { - namePattern = pattern.substring(slashIndex + 1); - } - String acceptNamePattern = ".*" - + IvyPatternHelper.substituteToken(namePattern, token, "([^" + fileSep - + "]+)") + ".*"; - Pattern p = Pattern.compile(acceptNamePattern.toString()); - for (Iterator iter = all.iterator(); iter.hasNext();) { - String path = (String) iter.next(); - Matcher m = p.matcher(path); - if (m.matches()) { - String value = m.group(1); - ret.add(value); - } - } - Message.debug("\t\t" + ret.size() + " matched " + pattern); - return (String[]) ret.toArray(new String[ret.size()]); - } else { - return null; - } - } catch (Exception e) { - Message.warn("problem while listing resources in " + root + " with " + rep + ":"); - Message.warn(" " + e.getClass().getName() + " " + e.getMessage()); - return null; - } - } - } - - public static String[] listAll(Repository rep, String parent) { - try { - String fileSep = rep.getFileSeparator(); - Message.debug("\tusing " + rep + " to list all in " + parent); - List all = rep.list(parent); - if (all != null) { - Message.debug("\t\tfound " + all.size() + " resources"); - List names = new ArrayList(all.size()); - for (Iterator iter = all.iterator(); iter.hasNext();) { - String path = (String) iter.next(); - if (path.endsWith(fileSep)) { - path = path.substring(0, path.length() - 1); - } - int slashIndex = path.lastIndexOf(fileSep); - names.add(path.substring(slashIndex + 1)); - } - return (String[]) names.toArray(new String[names.size()]); - } else { - Message.debug("\t\tno resources found"); - return null; - } - } catch (Exception e) { - Message.warn("problem while listing resources in " + parent + " with " + rep + ":"); - Message.warn(" " + e.getClass().getName() + " " + e.getMessage()); - return null; - } - } - - public static ResolvedResource[] findAll(Repository rep, ModuleRevisionId mrid, String pattern, - Artifact artifact) { - // substitute all but revision - String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, ModuleRevisionId - .newInstance(mrid, IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY)), - artifact); - Message.debug("\tlisting all in " + partiallyResolvedPattern); - - String[] revs = listTokenValues(rep, partiallyResolvedPattern, - IvyPatternHelper.REVISION_KEY); - if (revs != null) { - Message.debug("\tfound revs: " + Arrays.asList(revs)); - List ret = new ArrayList(revs.length); - for (int i = 0; i < revs.length; i++) { - String rres = IvyPatternHelper.substituteToken(partiallyResolvedPattern, - IvyPatternHelper.REVISION_KEY, revs[i]); - try { - ret.add(new ResolvedResource(rep.getResource(rres), revs[i])); - } catch (IOException e) { - Message.warn("impossible to get resource from name listed by repository: " - + rres + ": " + e.getMessage()); - } - } - if (revs.length != ret.size()) { - Message.debug("\tfound resolved res: " + ret); - } - return (ResolvedResource[]) ret.toArray(new ResolvedResource[ret.size()]); - } else if (partiallyResolvedPattern.indexOf("[" + IvyPatternHelper.REVISION_KEY + "]") == -1) { - // the partially resolved pattern is completely resolved, check the resource - try { - Resource res = rep.getResource(partiallyResolvedPattern); - if (res.exists()) { - Message - .debug("\tonly one resource found without real listing: using and defining it as working@" - + rep.getName() + " revision: " + res.getName()); - return new ResolvedResource[] {new ResolvedResource(res, "working@" - + rep.getName())}; - } - } catch (IOException e) { - Message.debug("\timpossible to get resource from name listed by repository: " - + partiallyResolvedPattern + ": " + e.getMessage()); - } - Message.debug("\tno revision found"); - } - return null; - } - - // public static ResolvedResource[] findAll(Repository rep, ModuleRevisionId mrid, String - // pattern, Artifact artifact, VersionMatcher versionMatcher, ResourceMDParser mdParser) { - // // substitute all but revision - // String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, new - // ModuleRevisionId(mrid.getModuleId(), - // IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY), mrid.getExtraAttributes()), - // artifact); - // Message.debug("\tlisting all in "+partiallyResolvedPattern); - // - // String[] revs = listTokenValues(rep, partiallyResolvedPattern, - // IvyPatternHelper.REVISION_KEY); - // if (revs != null) { - // Message.debug("\tfound revs: "+Arrays.asList(revs)); - // List ret = new ArrayList(revs.length); - // String rres = null; - // for (int i = 0; i < revs.length; i++) { - // ModuleRevisionId foundMrid = new ModuleRevisionId(mrid.getModuleId(), revs[i], - // mrid.getExtraAttributes()); - // if (versionMatcher.accept(mrid, foundMrid)) { - // rres = IvyPatternHelper.substituteToken(partiallyResolvedPattern, - // IvyPatternHelper.REVISION_KEY, revs[i]); - // try { - // ResolvedResource resolvedResource; - // if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) { - // resolvedResource = mdParser.parse(rep.getResource(rres), revs[i]); - // if (!versionMatcher.accept(mrid, - // ((MDResolvedResource)resolvedResource).getResolvedModuleRevision().getDescriptor())) { - // continue; - // } - // } else { - // resolvedResource = new ResolvedResource(rep.getResource(rres), revs[i]); - // } - // ret.add(resolvedResource); - // } catch (IOException e) { - // Message.warn("impossible to get resource from name listed by repository: "+rres+": - // "+e.getMessage()); - // } - // } - // } - // if (revs.length != ret.size()) { - // Message.debug("\tfound resolved res: "+ret); - // } - // return (ResolvedResource[])ret.toArray(new ResolvedResource[ret.size()]); - // } else { - // // maybe the partially resolved pattern is completely resolved ? - // try { - // Resource res = rep.getResource(partiallyResolvedPattern); - // if (res.exists()) { - // Message.debug("\tonly one resource found without real listing: using and defining it as - // working@"+rep.getName()+" revision: "+res.getName()); - // return new ResolvedResource[] {new ResolvedResource(res, "working@"+rep.getName())}; - // } - // } catch (IOException e) { - // Message.debug("\timpossible to get resource from name listed by repository: - // "+partiallyResolvedPattern+": "+e.getMessage()); - // } - // Message.debug("\tno revision found"); - // } - // return null; - // } - - // lists all the values a token can take in a pattern, as listed by a given url lister - public static String[] listTokenValues(URLLister lister, String pattern, String token) { - pattern = standardize(pattern); - if (lister.accept(pattern)) { - String tokenString = IvyPatternHelper.getTokenString(token); - int index = pattern.indexOf(tokenString); - if (index == -1) { - Message.verbose("unable to list " + token + " in " + pattern - + ": token not found in pattern"); - return null; - } - if (((pattern.length() <= index + tokenString.length()) || "/".equals(pattern - .substring(index + tokenString.length(), index + tokenString.length() + 1))) - && (index == 0 || "/".equals(pattern.substring(index - 1, index)))) { - // the searched token is a whole name - String root = pattern.substring(0, index); - try { - return listAll(lister, new URL(root)); - } catch (MalformedURLException e) { - Message - .warn("malformed url from pattern root: " + root + ": " - + e.getMessage()); - return null; - } - } else { - int slashIndex = pattern.substring(0, index).lastIndexOf('/'); - String root = slashIndex == -1 ? "" : pattern.substring(0, slashIndex); - - try { - Message.debug("\tusing " + lister + " to list all in " + root); - List all = lister.listAll(new URL(root)); - Message.debug("\t\tfound " + all.size() + " urls"); - List ret = new ArrayList(all.size()); - int endNameIndex = pattern.indexOf('/', slashIndex + 1); - String namePattern; - if (endNameIndex != -1) { - namePattern = pattern.substring(slashIndex + 1, endNameIndex); - } else { - namePattern = pattern.substring(slashIndex + 1); - } - String acceptNamePattern = ".*" - + IvyPatternHelper.substituteToken(namePattern, token, "([^/]+)") - + ".*"; - Pattern p = Pattern.compile(acceptNamePattern.toString()); - for (Iterator iter = all.iterator(); iter.hasNext();) { - URL url = (URL) iter.next(); - String path = standardize(url.getPath()); - Matcher m = p.matcher(path); - if (m.matches()) { - String value = m.group(1); - ret.add(value); - } - } - Message.debug("\t\t" + ret.size() + " matched " + pattern); - return (String[]) ret.toArray(new String[ret.size()]); - } catch (Exception e) { - Message.warn("problem while listing files in " + root + ": " + e.getClass() - + " " + e.getMessage()); - return null; - } - } - } - return null; - } - - private static String standardize(String path) { - return path.replace('\\', '/'); - } - - public static String[] listAll(URLLister lister, URL root) { - try { - if (lister.accept(root.toExternalForm())) { - Message.debug("\tusing " + lister + " to list all in " + root); - List all = lister.listAll(root); - Message.debug("\t\tfound " + all.size() + " urls"); - List names = new ArrayList(all.size()); - for (Iterator iter = all.iterator(); iter.hasNext();) { - URL dir = (URL) iter.next(); - String path = dir.getPath(); - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - int slashIndex = path.lastIndexOf('/'); - names.add(path.substring(slashIndex + 1)); - } - return (String[]) names.toArray(new String[names.size()]); - } - return null; - } catch (Exception e) { - Message.warn("problem while listing directories in " + root + ": " + e.getClass() + " " - + e.getMessage()); - return null; - } - } -} +/* + * 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.util; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.repository.Repository; +import org.apache.ivy.plugins.repository.Resource; +import org.apache.ivy.util.Message; + +public class ResolverHelper { + // lists all the values a token can take in a pattern, as listed by a given url lister + public static String[] listTokenValues(Repository rep, String pattern, String token) { + String fileSep = rep.getFileSeparator(); + pattern = rep.standardize(pattern); + String tokenString = IvyPatternHelper.getTokenString(token); + int index = pattern.indexOf(tokenString); + if (index == -1) { + Message.verbose("unable to list " + token + " in " + pattern + + ": token not found in pattern"); + return null; + } + if (((pattern.length() <= index + tokenString.length()) || fileSep.equals(pattern + .substring(index + tokenString.length(), index + tokenString.length() + 1))) + && (index == 0 || fileSep.equals(pattern.substring(index - 1, index)))) { + // the searched token is a whole name + String root = pattern.substring(0, index); + return listAll(rep, root); + } else { + int slashIndex = pattern.substring(0, index).lastIndexOf(fileSep); + String root = slashIndex == -1 ? "" : pattern.substring(0, slashIndex); + + try { + Message.debug("\tusing " + rep + " to list all in " + root); + List all = rep.list(root); + if (all != null) { + Message.debug("\t\tfound " + all.size() + " urls"); + List ret = new ArrayList(all.size()); + int endNameIndex = pattern.indexOf(fileSep, slashIndex + 1); + String namePattern; + if (endNameIndex != -1) { + namePattern = pattern.substring(slashIndex + 1, endNameIndex); + } else { + namePattern = pattern.substring(slashIndex + 1); + } + String acceptNamePattern = ".*" + + IvyPatternHelper.substituteToken(namePattern, token, "([^" + fileSep + + "]+)") + ".*"; + Pattern p = Pattern.compile(acceptNamePattern.toString()); + for (Iterator iter = all.iterator(); iter.hasNext();) { + String path = (String) iter.next(); + Matcher m = p.matcher(path); + if (m.matches()) { + String value = m.group(1); + ret.add(value); + } + } + Message.debug("\t\t" + ret.size() + " matched " + pattern); + return (String[]) ret.toArray(new String[ret.size()]); + } else { + return null; + } + } catch (Exception e) { + Message.warn("problem while listing resources in " + root + " with " + rep + ":"); + Message.warn(" " + e.getClass().getName() + " " + e.getMessage()); + return null; + } + } + } + + public static String[] listAll(Repository rep, String parent) { + try { + String fileSep = rep.getFileSeparator(); + Message.debug("\tusing " + rep + " to list all in " + parent); + List all = rep.list(parent); + if (all != null) { + Message.debug("\t\tfound " + all.size() + " resources"); + List names = new ArrayList(all.size()); + for (Iterator iter = all.iterator(); iter.hasNext();) { + String path = (String) iter.next(); + if (path.endsWith(fileSep)) { + path = path.substring(0, path.length() - 1); + } + int slashIndex = path.lastIndexOf(fileSep); + names.add(path.substring(slashIndex + 1)); + } + return (String[]) names.toArray(new String[names.size()]); + } else { + Message.debug("\t\tno resources found"); + return null; + } + } catch (Exception e) { + Message.warn("problem while listing resources in " + parent + " with " + rep + ":"); + Message.warn(" " + e.getClass().getName() + " " + e.getMessage()); + return null; + } + } + + public static ResolvedResource[] findAll(Repository rep, ModuleRevisionId mrid, String pattern, + Artifact artifact) { + // substitute all but revision + String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, ModuleRevisionId + .newInstance(mrid, IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY)), + artifact); + Message.debug("\tlisting all in " + partiallyResolvedPattern); + + String[] revs = listTokenValues(rep, partiallyResolvedPattern, + IvyPatternHelper.REVISION_KEY); + if (revs != null) { + Message.debug("\tfound revs: " + Arrays.asList(revs)); + List ret = new ArrayList(revs.length); + for (int i = 0; i < revs.length; i++) { + String rres = IvyPatternHelper.substituteToken(partiallyResolvedPattern, + IvyPatternHelper.REVISION_KEY, revs[i]); + try { + ret.add(new ResolvedResource(rep.getResource(rres), revs[i])); + } catch (IOException e) { + Message.warn("impossible to get resource from name listed by repository: " + + rres + ": " + e.getMessage()); + } + } + if (revs.length != ret.size()) { + Message.debug("\tfound resolved res: " + ret); + } + return (ResolvedResource[]) ret.toArray(new ResolvedResource[ret.size()]); + } else if (partiallyResolvedPattern.indexOf("[" + IvyPatternHelper.REVISION_KEY + "]") == -1) { + // the partially resolved pattern is completely resolved, check the resource + try { + Resource res = rep.getResource(partiallyResolvedPattern); + if (res.exists()) { + Message + .debug("\tonly one resource found without real listing: using and defining it as working@" + + rep.getName() + " revision: " + res.getName()); + return new ResolvedResource[] {new ResolvedResource(res, "working@" + + rep.getName())}; + } + } catch (IOException e) { + Message.debug("\timpossible to get resource from name listed by repository: " + + partiallyResolvedPattern + ": " + e.getMessage()); + } + Message.debug("\tno revision found"); + } + return null; + } + + // public static ResolvedResource[] findAll(Repository rep, ModuleRevisionId mrid, String + // pattern, Artifact artifact, VersionMatcher versionMatcher, ResourceMDParser mdParser) { + // // substitute all but revision + // String partiallyResolvedPattern = IvyPatternHelper.substitute(pattern, new + // ModuleRevisionId(mrid.getModuleId(), + // IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY), mrid.getExtraAttributes()), + // artifact); + // Message.debug("\tlisting all in "+partiallyResolvedPattern); + // + // String[] revs = listTokenValues(rep, partiallyResolvedPattern, + // IvyPatternHelper.REVISION_KEY); + // if (revs != null) { + // Message.debug("\tfound revs: "+Arrays.asList(revs)); + // List ret = new ArrayList(revs.length); + // String rres = null; + // for (int i = 0; i < revs.length; i++) { + // ModuleRevisionId foundMrid = new ModuleRevisionId(mrid.getModuleId(), revs[i], + // mrid.getExtraAttributes()); + // if (versionMatcher.accept(mrid, foundMrid)) { + // rres = IvyPatternHelper.substituteToken(partiallyResolvedPattern, + // IvyPatternHelper.REVISION_KEY, revs[i]); + // try { + // ResolvedResource resolvedResource; + // if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) { + // resolvedResource = mdParser.parse(rep.getResource(rres), revs[i]); + // if (!versionMatcher.accept(mrid, + // ((MDResolvedResource)resolvedResource).getResolvedModuleRevision().getDescriptor())) { + // continue; + // } + // } else { + // resolvedResource = new ResolvedResource(rep.getResource(rres), revs[i]); + // } + // ret.add(resolvedResource); + // } catch (IOException e) { + // Message.warn("impossible to get resource from name listed by repository: "+rres+": + // "+e.getMessage()); + // } + // } + // } + // if (revs.length != ret.size()) { + // Message.debug("\tfound resolved res: "+ret); + // } + // return (ResolvedResource[])ret.toArray(new ResolvedResource[ret.size()]); + // } else { + // // maybe the partially resolved pattern is completely resolved ? + // try { + // Resource res = rep.getResource(partiallyResolvedPattern); + // if (res.exists()) { + // Message.debug("\tonly one resource found without real listing: using and defining it as + // working@"+rep.getName()+" revision: "+res.getName()); + // return new ResolvedResource[] {new ResolvedResource(res, "working@"+rep.getName())}; + // } + // } catch (IOException e) { + // Message.debug("\timpossible to get resource from name listed by repository: + // "+partiallyResolvedPattern+": "+e.getMessage()); + // } + // Message.debug("\tno revision found"); + // } + // return null; + // } + + // lists all the values a token can take in a pattern, as listed by a given url lister + public static String[] listTokenValues(URLLister lister, String pattern, String token) { + pattern = standardize(pattern); + if (lister.accept(pattern)) { + String tokenString = IvyPatternHelper.getTokenString(token); + int index = pattern.indexOf(tokenString); + if (index == -1) { + Message.verbose("unable to list " + token + " in " + pattern + + ": token not found in pattern"); + return null; + } + if (((pattern.length() <= index + tokenString.length()) || "/".equals(pattern + .substring(index + tokenString.length(), index + tokenString.length() + 1))) + && (index == 0 || "/".equals(pattern.substring(index - 1, index)))) { + // the searched token is a whole name + String root = pattern.substring(0, index); + try { + return listAll(lister, new URL(root)); + } catch (MalformedURLException e) { + Message + .warn("malformed url from pattern root: " + root + ": " + + e.getMessage()); + return null; + } + } else { + int slashIndex = pattern.substring(0, index).lastIndexOf('/'); + String root = slashIndex == -1 ? "" : pattern.substring(0, slashIndex); + + try { + Message.debug("\tusing " + lister + " to list all in " + root); + List all = lister.listAll(new URL(root)); + Message.debug("\t\tfound " + all.size() + " urls"); + List ret = new ArrayList(all.size()); + int endNameIndex = pattern.indexOf('/', slashIndex + 1); + String namePattern; + if (endNameIndex != -1) { + namePattern = pattern.substring(slashIndex + 1, endNameIndex); + } else { + namePattern = pattern.substring(slashIndex + 1); + } + String acceptNamePattern = ".*" + + IvyPatternHelper.substituteToken(namePattern, token, "([^/]+)") + + ".*"; + Pattern p = Pattern.compile(acceptNamePattern.toString()); + for (Iterator iter = all.iterator(); iter.hasNext();) { + URL url = (URL) iter.next(); + String path = standardize(url.getPath()); + Matcher m = p.matcher(path); + if (m.matches()) { + String value = m.group(1); + ret.add(value); + } + } + Message.debug("\t\t" + ret.size() + " matched " + pattern); + return (String[]) ret.toArray(new String[ret.size()]); + } catch (Exception e) { + Message.warn("problem while listing files in " + root + ": " + e.getClass() + + " " + e.getMessage()); + return null; + } + } + } + return null; + } + + private static String standardize(String path) { + return path.replace('\\', '/'); + } + + public static String[] listAll(URLLister lister, URL root) { + try { + if (lister.accept(root.toExternalForm())) { + Message.debug("\tusing " + lister + " to list all in " + root); + List all = lister.listAll(root); + Message.debug("\t\tfound " + all.size() + " urls"); + List names = new ArrayList(all.size()); + for (Iterator iter = all.iterator(); iter.hasNext();) { + URL dir = (URL) iter.next(); + String path = dir.getPath(); + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + int slashIndex = path.lastIndexOf('/'); + names.add(path.substring(slashIndex + 1)); + } + return (String[]) names.toArray(new String[names.size()]); + } + return null; + } catch (Exception e) { + Message.warn("problem while listing directories in " + root + ": " + e.getClass() + " " + + e.getMessage()); + return null; + } + } +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/ResourceMDParser.java b/src/java/org/apache/ivy/plugins/resolver/util/ResourceMDParser.java index 6bb90315..932ff8c0 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/ResourceMDParser.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/ResourceMDParser.java @@ -1,24 +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. - * - */ -package org.apache.ivy.plugins.resolver.util; - -import org.apache.ivy.plugins.repository.Resource; - -public interface ResourceMDParser { - MDResolvedResource parse(Resource resource, String rev); -} +/* + * 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.util; + +import org.apache.ivy.plugins.repository.Resource; + +public interface ResourceMDParser { + MDResolvedResource parse(Resource resource, String rev); +} diff --git a/src/java/org/apache/ivy/plugins/resolver/util/URLLister.java b/src/java/org/apache/ivy/plugins/resolver/util/URLLister.java index 6cbb15ee..6e7258ad 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/URLLister.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/URLLister.java @@ -1,35 +1,35 @@ -/* - * 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.util; - -import java.io.IOException; -import java.net.URL; -import java.util.List; - -public interface URLLister { - /** - * Indicates if this lister is able to list urls with the given pattern. In general, only - * protocol is used. - * - * @param pattern - * @return - */ - boolean accept(String pattern); - - List listAll(URL url) throws IOException; -} +/* + * 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.util; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +public interface URLLister { + /** + * Indicates if this lister is able to list urls with the given pattern. In general, only + * protocol is used. + * + * @param pattern + * @return + */ + boolean accept(String pattern); + + List listAll(URL url) throws IOException; +} diff --git a/src/java/org/apache/ivy/plugins/trigger/AbstractTrigger.java b/src/java/org/apache/ivy/plugins/trigger/AbstractTrigger.java index 7e848f04..a0cd2307 100644 --- a/src/java/org/apache/ivy/plugins/trigger/AbstractTrigger.java +++ b/src/java/org/apache/ivy/plugins/trigger/AbstractTrigger.java @@ -1,83 +1,83 @@ -/* - * 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.trigger; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.event.IvyEvent; -import org.apache.ivy.core.event.IvyEventFilter; -import org.apache.ivy.core.event.IvyListener; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.util.filter.Filter; - -/** - * Base class for easy trigger implementation. This base class takes of the event filtering part, - * the only method to implement in subclasses is {@link IvyListener#progress(IvyEvent)} which should - * do whatever the trigger needs to do when the event occurs. This method will only be called when - * an event matching the trigger filter occurs. - * - * @since 1.4 - */ -public abstract class AbstractTrigger implements Trigger { - private Filter _filter; - - private String _event; - - private String _filterExpression; - - private String _matcher = PatternMatcher.EXACT; - - public Filter getEventFilter() { - if (_filter == null) { - _filter = createFilter(); - } - return _filter; - } - - private Filter createFilter() { - return new IvyEventFilter(getEvent(), getFilter(), getPatternMatcher()); - } - - private PatternMatcher getPatternMatcher() { - return IvyContext.getContext().getSettings().getMatcher(_matcher); - } - - public String getEvent() { - return _event; - } - - public void setEvent(String event) { - _event = event; - } - - public String getFilter() { - return _filterExpression; - } - - public void setFilter(String filterExpression) { - _filterExpression = filterExpression; - } - - public String getMatcher() { - return _matcher; - } - - public void setMatcher(String matcher) { - _matcher = matcher; - } - -} +/* + * 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.trigger; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.event.IvyEvent; +import org.apache.ivy.core.event.IvyEventFilter; +import org.apache.ivy.core.event.IvyListener; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.util.filter.Filter; + +/** + * Base class for easy trigger implementation. This base class takes of the event filtering part, + * the only method to implement in subclasses is {@link IvyListener#progress(IvyEvent)} which should + * do whatever the trigger needs to do when the event occurs. This method will only be called when + * an event matching the trigger filter occurs. + * + * @since 1.4 + */ +public abstract class AbstractTrigger implements Trigger { + private Filter _filter; + + private String _event; + + private String _filterExpression; + + private String _matcher = PatternMatcher.EXACT; + + public Filter getEventFilter() { + if (_filter == null) { + _filter = createFilter(); + } + return _filter; + } + + private Filter createFilter() { + return new IvyEventFilter(getEvent(), getFilter(), getPatternMatcher()); + } + + private PatternMatcher getPatternMatcher() { + return IvyContext.getContext().getSettings().getMatcher(_matcher); + } + + public String getEvent() { + return _event; + } + + public void setEvent(String event) { + _event = event; + } + + public String getFilter() { + return _filterExpression; + } + + public void setFilter(String filterExpression) { + _filterExpression = filterExpression; + } + + public String getMatcher() { + return _matcher; + } + + public void setMatcher(String matcher) { + _matcher = matcher; + } + +} diff --git a/src/java/org/apache/ivy/plugins/trigger/Trigger.java b/src/java/org/apache/ivy/plugins/trigger/Trigger.java index 59bc37a3..b8987e97 100644 --- a/src/java/org/apache/ivy/plugins/trigger/Trigger.java +++ b/src/java/org/apache/ivy/plugins/trigger/Trigger.java @@ -1,25 +1,25 @@ -/* - * 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.trigger; - -import org.apache.ivy.core.event.IvyListener; -import org.apache.ivy.util.filter.Filter; - -public interface Trigger extends IvyListener { - Filter getEventFilter(); -} +/* + * 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.trigger; + +import org.apache.ivy.core.event.IvyListener; +import org.apache.ivy.util.filter.Filter; + +public interface Trigger extends IvyListener { + Filter getEventFilter(); +} diff --git a/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java index 300d3fcb..f18bb071 100644 --- a/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/AbstractVersionMatcher.java @@ -1,78 +1,78 @@ -/* - * 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.version; - -import java.util.Comparator; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.IvySettingsAware; -import org.apache.ivy.util.Checks; - -public abstract class AbstractVersionMatcher implements VersionMatcher, IvySettingsAware { - private String _name; - - private IvySettings settings; - - public AbstractVersionMatcher() { - } - - public AbstractVersionMatcher(String name) { - _name = name; - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - return false; - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) { - return accept(askedMrid, foundMD.getResolvedModuleRevisionId()); - } - - /** - * This method should be overriden in most cases, because it uses the default contract to return - * 1 when it's not possible to know which revision is greater. - */ - public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, - Comparator staticComparator) { - return 0; - } - - public String toString() { - return getName(); - } - - public IvySettings getSettings() { - return settings; - } - - public void setSettings(IvySettings settings) { - Checks.checkNotNull(settings, "settings"); - this.settings = settings; - } - -} +/* + * 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.version; + +import java.util.Comparator; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.IvySettingsAware; +import org.apache.ivy.util.Checks; + +public abstract class AbstractVersionMatcher implements VersionMatcher, IvySettingsAware { + private String _name; + + private IvySettings settings; + + public AbstractVersionMatcher() { + } + + public AbstractVersionMatcher(String name) { + _name = name; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + return false; + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) { + return accept(askedMrid, foundMD.getResolvedModuleRevisionId()); + } + + /** + * This method should be overriden in most cases, because it uses the default contract to return + * 1 when it's not possible to know which revision is greater. + */ + public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, + Comparator staticComparator) { + return 0; + } + + public String toString() { + return getName(); + } + + public IvySettings getSettings() { + return settings; + } + + public void setSettings(IvySettings settings) { + Checks.checkNotNull(settings, "settings"); + this.settings = settings; + } + +} diff --git a/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java index 94564a3b..fae5ca73 100644 --- a/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/ChainVersionMatcher.java @@ -1,155 +1,155 @@ -/* - * 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.version; - -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.IvySettingsAware; -import org.apache.ivy.util.Checks; - -/** - * An implementation of {@link VersionMatcher} chaining several version matchers, and implemeting - * the {@link VersionMatcher} interface by returning results from the first matcher in the chain - * accepting the version. - */ -public class ChainVersionMatcher extends AbstractVersionMatcher { - /** - * The list of version matchers in the chain. This list will be queried in order, so the last - * matcher will be used only if no other matcher accept the revision before. - */ - private List/* */matchers = new LinkedList(); - - /** - * Unique Constructor. - */ - public ChainVersionMatcher() { - super("chain"); - } - - /** - * Adds a {@link VersionMatcher} to the chain. - * - * @param matcher - * the version matcher to add. Must not be null - */ - public void add(VersionMatcher matcher) { - Checks.checkNotNull(matcher, "matcher"); - matchers.add(0, matcher); - if (getSettings() != null && matcher instanceof IvySettingsAware) { - ((IvySettingsAware) matcher).setSettings(getSettings()); - } - } - - /** - * Sets the settings this matcher will use, and set to the matcher in the chain which implements - * {@link IvySettingsAware}. - * - * @param settings - * the settings to use in the whole chain. Must not be null. - */ - public void setSettings(IvySettings settings) { - super.setSettings(settings); - for (Iterator iter = matchers.iterator(); iter.hasNext();) { - VersionMatcher matcher = (VersionMatcher) iter.next(); - if (matcher instanceof IvySettingsAware) { - ((IvySettingsAware) matcher).setSettings(settings); - } - } - } - - /** - * Returns the list of matchers in the chain. - *

      - * The list is returned as an unmodifiable view on the actual list of matchers, and will thus - * reflect futher changes made in the chain. - * - * @return the list of matchers in the chain. Is never null. - */ - public List getMatchers() { - return Collections.unmodifiableList(matchers); - } - - public boolean isDynamic(ModuleRevisionId askedMrid) { - Checks.checkNotNull(askedMrid, "askedMrid"); - for (Iterator iter = matchers.iterator(); iter.hasNext();) { - VersionMatcher matcher = (VersionMatcher) iter.next(); - if (matcher.isDynamic(askedMrid)) { - return true; - } - } - return false; - } - - public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, - Comparator staticComparator) { - Checks.checkNotNull(askedMrid, "askedMrid"); - Checks.checkNotNull(foundMrid, "foundMrid"); - Checks.checkNotNull(staticComparator, "staticComparator"); - for (Iterator iter = matchers.iterator(); iter.hasNext();) { - VersionMatcher matcher = (VersionMatcher) iter.next(); - if (matcher.isDynamic(askedMrid)) { - return matcher.compare(askedMrid, foundMrid, staticComparator); - } - } - throw new IllegalArgumentException( - "impossible to compare revisions: askedMrid is not dynamic: " + askedMrid); - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - Checks.checkNotNull(askedMrid, "askedMrid"); - Checks.checkNotNull(foundMrid, "foundMrid"); - for (Iterator iter = matchers.iterator(); iter.hasNext();) { - VersionMatcher matcher = (VersionMatcher) iter.next(); - if (!iter.hasNext() || matcher.isDynamic(askedMrid)) { - return matcher.accept(askedMrid, foundMrid); - } - } - return false; - } - - public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - Checks.checkNotNull(askedMrid, "askedMrid"); - Checks.checkNotNull(foundMrid, "foundMrid"); - for (Iterator iter = matchers.iterator(); iter.hasNext();) { - VersionMatcher matcher = (VersionMatcher) iter.next(); - if (!iter.hasNext() || matcher.isDynamic(askedMrid)) { - return matcher.needModuleDescriptor(askedMrid, foundMrid); - } - } - return false; - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) { - Checks.checkNotNull(askedMrid, "askedMrid"); - Checks.checkNotNull(foundMD, "foundMD"); - for (Iterator iter = matchers.iterator(); iter.hasNext();) { - VersionMatcher matcher = (VersionMatcher) iter.next(); - if (!iter.hasNext() || matcher.isDynamic(askedMrid)) { - return matcher.accept(askedMrid, foundMD); - } - } - return false; - } -} +/* + * 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.version; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.IvySettingsAware; +import org.apache.ivy.util.Checks; + +/** + * An implementation of {@link VersionMatcher} chaining several version matchers, and implemeting + * the {@link VersionMatcher} interface by returning results from the first matcher in the chain + * accepting the version. + */ +public class ChainVersionMatcher extends AbstractVersionMatcher { + /** + * The list of version matchers in the chain. This list will be queried in order, so the last + * matcher will be used only if no other matcher accept the revision before. + */ + private List/* */matchers = new LinkedList(); + + /** + * Unique Constructor. + */ + public ChainVersionMatcher() { + super("chain"); + } + + /** + * Adds a {@link VersionMatcher} to the chain. + * + * @param matcher + * the version matcher to add. Must not be null + */ + public void add(VersionMatcher matcher) { + Checks.checkNotNull(matcher, "matcher"); + matchers.add(0, matcher); + if (getSettings() != null && matcher instanceof IvySettingsAware) { + ((IvySettingsAware) matcher).setSettings(getSettings()); + } + } + + /** + * Sets the settings this matcher will use, and set to the matcher in the chain which implements + * {@link IvySettingsAware}. + * + * @param settings + * the settings to use in the whole chain. Must not be null. + */ + public void setSettings(IvySettings settings) { + super.setSettings(settings); + for (Iterator iter = matchers.iterator(); iter.hasNext();) { + VersionMatcher matcher = (VersionMatcher) iter.next(); + if (matcher instanceof IvySettingsAware) { + ((IvySettingsAware) matcher).setSettings(settings); + } + } + } + + /** + * Returns the list of matchers in the chain. + *

      + * The list is returned as an unmodifiable view on the actual list of matchers, and will thus + * reflect futher changes made in the chain. + * + * @return the list of matchers in the chain. Is never null. + */ + public List getMatchers() { + return Collections.unmodifiableList(matchers); + } + + public boolean isDynamic(ModuleRevisionId askedMrid) { + Checks.checkNotNull(askedMrid, "askedMrid"); + for (Iterator iter = matchers.iterator(); iter.hasNext();) { + VersionMatcher matcher = (VersionMatcher) iter.next(); + if (matcher.isDynamic(askedMrid)) { + return true; + } + } + return false; + } + + public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, + Comparator staticComparator) { + Checks.checkNotNull(askedMrid, "askedMrid"); + Checks.checkNotNull(foundMrid, "foundMrid"); + Checks.checkNotNull(staticComparator, "staticComparator"); + for (Iterator iter = matchers.iterator(); iter.hasNext();) { + VersionMatcher matcher = (VersionMatcher) iter.next(); + if (matcher.isDynamic(askedMrid)) { + return matcher.compare(askedMrid, foundMrid, staticComparator); + } + } + throw new IllegalArgumentException( + "impossible to compare revisions: askedMrid is not dynamic: " + askedMrid); + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + Checks.checkNotNull(askedMrid, "askedMrid"); + Checks.checkNotNull(foundMrid, "foundMrid"); + for (Iterator iter = matchers.iterator(); iter.hasNext();) { + VersionMatcher matcher = (VersionMatcher) iter.next(); + if (!iter.hasNext() || matcher.isDynamic(askedMrid)) { + return matcher.accept(askedMrid, foundMrid); + } + } + return false; + } + + public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + Checks.checkNotNull(askedMrid, "askedMrid"); + Checks.checkNotNull(foundMrid, "foundMrid"); + for (Iterator iter = matchers.iterator(); iter.hasNext();) { + VersionMatcher matcher = (VersionMatcher) iter.next(); + if (!iter.hasNext() || matcher.isDynamic(askedMrid)) { + return matcher.needModuleDescriptor(askedMrid, foundMrid); + } + } + return false; + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) { + Checks.checkNotNull(askedMrid, "askedMrid"); + Checks.checkNotNull(foundMD, "foundMD"); + for (Iterator iter = matchers.iterator(); iter.hasNext();) { + VersionMatcher matcher = (VersionMatcher) iter.next(); + if (!iter.hasNext() || matcher.isDynamic(askedMrid)) { + return matcher.accept(askedMrid, foundMD); + } + } + return false; + } +} diff --git a/src/java/org/apache/ivy/plugins/version/ExactVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/ExactVersionMatcher.java index 77053c25..6b861e36 100644 --- a/src/java/org/apache/ivy/plugins/version/ExactVersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/ExactVersionMatcher.java @@ -1,35 +1,35 @@ -/* - * 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.version; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class ExactVersionMatcher extends AbstractVersionMatcher { - - public ExactVersionMatcher() { - super("exact"); - } - - public boolean isDynamic(ModuleRevisionId askedMrid) { - return false; - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - return askedMrid.getRevision().equals(foundMrid.getRevision()); - } -} +/* + * 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.version; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class ExactVersionMatcher extends AbstractVersionMatcher { + + public ExactVersionMatcher() { + super("exact"); + } + + public boolean isDynamic(ModuleRevisionId askedMrid) { + return false; + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + return askedMrid.getRevision().equals(foundMrid.getRevision()); + } +} diff --git a/src/java/org/apache/ivy/plugins/version/LatestVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/LatestVersionMatcher.java index f8f3a1bc..d502bea5 100644 --- a/src/java/org/apache/ivy/plugins/version/LatestVersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/LatestVersionMatcher.java @@ -1,57 +1,57 @@ -/* - * 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.version; - -import java.util.Comparator; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.module.status.StatusManager; - -public class LatestVersionMatcher extends AbstractVersionMatcher { - public LatestVersionMatcher() { - super("latest"); - } - - public boolean isDynamic(ModuleRevisionId askedMrid) { - return askedMrid.getRevision().startsWith("latest."); - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - return true; - } - - public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - return !"latest.integration".equals(askedMrid.getRevision()); - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) { - String askedStatus = askedMrid.getRevision().substring("latest.".length()); - return StatusManager.getCurrent().getPriority(askedStatus) >= StatusManager.getCurrent() - .getPriority(foundMD.getStatus()); - } - - /** - * If we don't need a module descriptor we can consider the dynamic revision to be greater. If - * we need a module descriptor then we can't know which one is greater and return 0. - */ - public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, - Comparator staticComparator) { - return needModuleDescriptor(askedMrid, foundMrid) ? 0 : 1; - } -} +/* + * 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.version; + +import java.util.Comparator; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.module.status.StatusManager; + +public class LatestVersionMatcher extends AbstractVersionMatcher { + public LatestVersionMatcher() { + super("latest"); + } + + public boolean isDynamic(ModuleRevisionId askedMrid) { + return askedMrid.getRevision().startsWith("latest."); + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + return true; + } + + public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + return !"latest.integration".equals(askedMrid.getRevision()); + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) { + String askedStatus = askedMrid.getRevision().substring("latest.".length()); + return StatusManager.getCurrent().getPriority(askedStatus) >= StatusManager.getCurrent() + .getPriority(foundMD.getStatus()); + } + + /** + * If we don't need a module descriptor we can consider the dynamic revision to be greater. If + * we need a module descriptor then we can't know which one is greater and return 0. + */ + public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, + Comparator staticComparator) { + return needModuleDescriptor(askedMrid, foundMrid) ? 0 : 1; + } +} diff --git a/src/java/org/apache/ivy/plugins/version/Match.java b/src/java/org/apache/ivy/plugins/version/Match.java index 366ee518..abd62e69 100644 --- a/src/java/org/apache/ivy/plugins/version/Match.java +++ b/src/java/org/apache/ivy/plugins/version/Match.java @@ -1,136 +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.plugins.version; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -import org.apache.ivy.core.IvyContext; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.matcher.Matcher; -import org.apache.ivy.plugins.matcher.PatternMatcher; - -/** - * - */ -public class Match { - private String _revision; - - private String _pattern; - - private String _args; - - private String _matcher; - - public String getArgs() { - return _args; - } - - public void setArgs(String args) { - this._args = args; - } - - public String getMatcher() { - return _matcher; - } - - public void setMatcher(String matcher) { - this._matcher = matcher; - } - - public String getPattern() { - return _pattern; - } - - public void setPattern(String pattern) { - this._pattern = pattern; - } - - public String getRevision() { - return _revision; - } - - public void setRevision(String revision) { - this._revision = revision; - } - - public Matcher getPatternMatcher(ModuleRevisionId askedMrid) { - String revision = askedMrid.getRevision(); - - String[] args = split(getArgs()); - String[] argValues = getRevisionArgs(revision); - - if (args.length != argValues.length) { - return new NoMatchMatcher(); - } - - Map variables = new HashMap(); - for (int i = 0; i < args.length; i++) { - variables.put(args[i], argValues[i]); - } - - String pattern = getPattern(); - pattern = IvyPatternHelper.substituteVariables(pattern, variables); - - PatternMatcher pMatcher = IvyContext.getContext().getSettings().getMatcher(_matcher); - return pMatcher.getMatcher(pattern); - } - - private String[] getRevisionArgs(String revision) { - int bracketStartIndex = revision.indexOf('('); - if (bracketStartIndex == -1) { - return new String[0]; - } - - int bracketEndIndex = revision.indexOf(')'); - if (bracketEndIndex <= (bracketStartIndex + 1)) { - return new String[0]; - } - - String args = revision.substring(bracketStartIndex + 1, bracketEndIndex); - return split(args); - } - - private static String[] split(String string) { - if (string == null) { - return new String[0]; - } - - StringTokenizer tokenizer = new StringTokenizer(string, ", "); - List tokens = new ArrayList(); - while (tokenizer.hasMoreTokens()) { - tokens.add(tokenizer.nextToken()); - } - - return (String[]) tokens.toArray(new String[tokens.size()]); - } - - private static class NoMatchMatcher implements Matcher { - public boolean isExact() { - return false; - } - - public boolean matches(String str) { - return false; - } - } -} +/* + * 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.version; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +import org.apache.ivy.core.IvyContext; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.matcher.Matcher; +import org.apache.ivy.plugins.matcher.PatternMatcher; + +/** + * + */ +public class Match { + private String _revision; + + private String _pattern; + + private String _args; + + private String _matcher; + + public String getArgs() { + return _args; + } + + public void setArgs(String args) { + this._args = args; + } + + public String getMatcher() { + return _matcher; + } + + public void setMatcher(String matcher) { + this._matcher = matcher; + } + + public String getPattern() { + return _pattern; + } + + public void setPattern(String pattern) { + this._pattern = pattern; + } + + public String getRevision() { + return _revision; + } + + public void setRevision(String revision) { + this._revision = revision; + } + + public Matcher getPatternMatcher(ModuleRevisionId askedMrid) { + String revision = askedMrid.getRevision(); + + String[] args = split(getArgs()); + String[] argValues = getRevisionArgs(revision); + + if (args.length != argValues.length) { + return new NoMatchMatcher(); + } + + Map variables = new HashMap(); + for (int i = 0; i < args.length; i++) { + variables.put(args[i], argValues[i]); + } + + String pattern = getPattern(); + pattern = IvyPatternHelper.substituteVariables(pattern, variables); + + PatternMatcher pMatcher = IvyContext.getContext().getSettings().getMatcher(_matcher); + return pMatcher.getMatcher(pattern); + } + + private String[] getRevisionArgs(String revision) { + int bracketStartIndex = revision.indexOf('('); + if (bracketStartIndex == -1) { + return new String[0]; + } + + int bracketEndIndex = revision.indexOf(')'); + if (bracketEndIndex <= (bracketStartIndex + 1)) { + return new String[0]; + } + + String args = revision.substring(bracketStartIndex + 1, bracketEndIndex); + return split(args); + } + + private static String[] split(String string) { + if (string == null) { + return new String[0]; + } + + StringTokenizer tokenizer = new StringTokenizer(string, ", "); + List tokens = new ArrayList(); + while (tokenizer.hasMoreTokens()) { + tokens.add(tokenizer.nextToken()); + } + + return (String[]) tokens.toArray(new String[tokens.size()]); + } + + private static class NoMatchMatcher implements Matcher { + public boolean isExact() { + return false; + } + + public boolean matches(String str) { + return false; + } + } +} diff --git a/src/java/org/apache/ivy/plugins/version/PatternVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/PatternVersionMatcher.java index c6922bc1..5233855b 100644 --- a/src/java/org/apache/ivy/plugins/version/PatternVersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/PatternVersionMatcher.java @@ -1,99 +1,99 @@ -/* - * 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.version; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.matcher.Matcher; - -/** - * - */ -public class PatternVersionMatcher extends AbstractVersionMatcher { - - private List _matches = new ArrayList(); - - private Map _revisionMatches = new HashMap(); // revision -> list of Match instances - - private boolean _init = false; - - public void addMatch(Match match) { - _matches.add(match); - } - - private void init() { - if (!_init) { - for (Iterator it = _matches.iterator(); it.hasNext();) { - Match match = (Match) it.next(); - List matches = (List) _revisionMatches.get(match.getRevision()); - if (matches == null) { - matches = new ArrayList(); - _revisionMatches.put(match.getRevision(), matches); - } - matches.add(match); - } - _init = true; - } - } - - /** - * {@inheritDoc} - */ - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - init(); - boolean accept = false; - - String revision = askedMrid.getRevision(); - int bracketIndex = revision.indexOf('('); - if (bracketIndex > 0) { - revision = revision.substring(0, bracketIndex); - } - - List matches = (List) _revisionMatches.get(revision); - - if (matches != null) { - Iterator it = matches.iterator(); - while (!accept && it.hasNext()) { - Match match = (Match) it.next(); - Matcher matcher = match.getPatternMatcher(askedMrid); - accept = matcher.matches(foundMrid.getRevision()); - } - } - - return accept; - } - - /** - * {@inheritDoc} - */ - public boolean isDynamic(ModuleRevisionId askedMrid) { - init(); - String revision = askedMrid.getRevision(); - int bracketIndex = revision.indexOf('('); - if (bracketIndex > 0) { - revision = revision.substring(0, bracketIndex); - } - return _revisionMatches.containsKey(revision); - } - -} +/* + * 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.version; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.matcher.Matcher; + +/** + * + */ +public class PatternVersionMatcher extends AbstractVersionMatcher { + + private List _matches = new ArrayList(); + + private Map _revisionMatches = new HashMap(); // revision -> list of Match instances + + private boolean _init = false; + + public void addMatch(Match match) { + _matches.add(match); + } + + private void init() { + if (!_init) { + for (Iterator it = _matches.iterator(); it.hasNext();) { + Match match = (Match) it.next(); + List matches = (List) _revisionMatches.get(match.getRevision()); + if (matches == null) { + matches = new ArrayList(); + _revisionMatches.put(match.getRevision(), matches); + } + matches.add(match); + } + _init = true; + } + } + + /** + * {@inheritDoc} + */ + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + init(); + boolean accept = false; + + String revision = askedMrid.getRevision(); + int bracketIndex = revision.indexOf('('); + if (bracketIndex > 0) { + revision = revision.substring(0, bracketIndex); + } + + List matches = (List) _revisionMatches.get(revision); + + if (matches != null) { + Iterator it = matches.iterator(); + while (!accept && it.hasNext()) { + Match match = (Match) it.next(); + Matcher matcher = match.getPatternMatcher(askedMrid); + accept = matcher.matches(foundMrid.getRevision()); + } + } + + return accept; + } + + /** + * {@inheritDoc} + */ + public boolean isDynamic(ModuleRevisionId askedMrid) { + init(); + String revision = askedMrid.getRevision(); + int bracketIndex = revision.indexOf('('); + if (bracketIndex > 0) { + revision = revision.substring(0, bracketIndex); + } + return _revisionMatches.containsKey(revision); + } + +} diff --git a/src/java/org/apache/ivy/plugins/version/SubVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/SubVersionMatcher.java index 49babb3d..b8e04cb9 100644 --- a/src/java/org/apache/ivy/plugins/version/SubVersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/SubVersionMatcher.java @@ -1,46 +1,46 @@ -/* - * 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.version; - -import java.util.Comparator; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class SubVersionMatcher extends AbstractVersionMatcher { - public SubVersionMatcher() { - super("sub-version"); - } - - public boolean isDynamic(ModuleRevisionId askedMrid) { - return askedMrid.getRevision().endsWith("+"); - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - String prefix = askedMrid.getRevision().substring(0, askedMrid.getRevision().length() - 1); - return foundMrid.getRevision().startsWith(prefix); - } - - public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, - Comparator staticComparator) { - if (foundMrid.getRevision().startsWith( - askedMrid.getRevision().substring(0, askedMrid.getRevision().length() - 1))) { - return 1; - } - return staticComparator.compare(askedMrid, foundMrid); - } -} +/* + * 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.version; + +import java.util.Comparator; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class SubVersionMatcher extends AbstractVersionMatcher { + public SubVersionMatcher() { + super("sub-version"); + } + + public boolean isDynamic(ModuleRevisionId askedMrid) { + return askedMrid.getRevision().endsWith("+"); + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + String prefix = askedMrid.getRevision().substring(0, askedMrid.getRevision().length() - 1); + return foundMrid.getRevision().startsWith(prefix); + } + + public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, + Comparator staticComparator) { + if (foundMrid.getRevision().startsWith( + askedMrid.getRevision().substring(0, askedMrid.getRevision().length() - 1))) { + return 1; + } + return staticComparator.compare(askedMrid, foundMrid); + } +} diff --git a/src/java/org/apache/ivy/plugins/version/VersionMatcher.java b/src/java/org/apache/ivy/plugins/version/VersionMatcher.java index 91fd5edf..307f32f1 100644 --- a/src/java/org/apache/ivy/plugins/version/VersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/VersionMatcher.java @@ -1,104 +1,104 @@ -/* - * 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.version; - -import java.util.Comparator; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -/** - * This interface defines a version matcher, i.e. a class able to tell if the revision asked by a - * module for a dependency is dynamic (i.e. need to find all revisions to find the good one among - * them) and if a found revision matches the asked one. Two ways of matching are possible: - based - * on the module revision only (known as ModuleRevisionId) - based on the parsed module descriptor - * The second being much more time consuming than the first, the version matcher should tell if it - * needs such parsing or not using the needModuleDescriptor(ModuleRevisionId askedMrid, - * ModuleRevisionId foundMrid) method. Anyway, the first way is always used, and if a revision is - * not accepted using the first method, the module descriptor won't be parsed. Therefore if a - * version matcher uses only module descriptors to accept a revision or not it should always return - * true to needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) and - * accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid). - */ -public interface VersionMatcher { - /** - * Indicates if the given asked ModuleRevisionId should be considered as dynamic for the current - * VersionMatcher or not. - * - * @param askedMrid - * the dependency module revision id as asked by a module - * @return true if this revision is considered as a dynamic one, false otherwise - */ - public boolean isDynamic(ModuleRevisionId askedMrid); - - /** - * Indicates if this version matcher considers that the module revision found matches the asked - * one. - * - * @param askedMrid - * @param foundMrid - * @return - */ - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid); - - /** - * Indicates if this VersionMatcher needs module descriptors to determine if a module revision - * matches the asked one. Note that returning true in this method may imply big performance - * issues. - * - * @return - */ - public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid); - - /** - * Indicates if this version matcher considers that the module found matches the asked one. This - * method can be called even needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId - * foundMrid) returns false, so it is required to implement it in any case, a usual default - * implementation being: return accept(askedMrid, foundMD.getResolvedModuleRevisionId()); - * - * @param askedMrid - * @param foundMD - * @return - */ - public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD); - - /** - * Compares a dynamic revision (askedMrid) with a static one (foundMrid) to indicate which one - * should be considered the greater. If there is not enough information to know which one is the - * greater, the dynamic one should be considered greater and this method should return 0. This - * method should never be called with a askdeMrid for which isDynamic returns false. - * - * @param askedMrid - * the dynamic revision to compare - * @param foundMrid - * the static revision to compare - * @param staticComparator - * a comparator which can be used to compare static revisions - * @return 0 if it's not possible to know which one is greater, greater than 0 if askedMrid - * should be considered greater, lower than 0 if it can't be consider greater - */ - public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, - Comparator staticComparator); - - /** - * Returns the version matcher name identifying this version matcher - * - * @return the version matcher name identifying this version matcher - */ - public String getName(); -} +/* + * 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.version; + +import java.util.Comparator; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +/** + * This interface defines a version matcher, i.e. a class able to tell if the revision asked by a + * module for a dependency is dynamic (i.e. need to find all revisions to find the good one among + * them) and if a found revision matches the asked one. Two ways of matching are possible: - based + * on the module revision only (known as ModuleRevisionId) - based on the parsed module descriptor + * The second being much more time consuming than the first, the version matcher should tell if it + * needs such parsing or not using the needModuleDescriptor(ModuleRevisionId askedMrid, + * ModuleRevisionId foundMrid) method. Anyway, the first way is always used, and if a revision is + * not accepted using the first method, the module descriptor won't be parsed. Therefore if a + * version matcher uses only module descriptors to accept a revision or not it should always return + * true to needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) and + * accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid). + */ +public interface VersionMatcher { + /** + * Indicates if the given asked ModuleRevisionId should be considered as dynamic for the current + * VersionMatcher or not. + * + * @param askedMrid + * the dependency module revision id as asked by a module + * @return true if this revision is considered as a dynamic one, false otherwise + */ + public boolean isDynamic(ModuleRevisionId askedMrid); + + /** + * Indicates if this version matcher considers that the module revision found matches the asked + * one. + * + * @param askedMrid + * @param foundMrid + * @return + */ + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid); + + /** + * Indicates if this VersionMatcher needs module descriptors to determine if a module revision + * matches the asked one. Note that returning true in this method may imply big performance + * issues. + * + * @return + */ + public boolean needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid); + + /** + * Indicates if this version matcher considers that the module found matches the asked one. This + * method can be called even needModuleDescriptor(ModuleRevisionId askedMrid, ModuleRevisionId + * foundMrid) returns false, so it is required to implement it in any case, a usual default + * implementation being: return accept(askedMrid, foundMD.getResolvedModuleRevisionId()); + * + * @param askedMrid + * @param foundMD + * @return + */ + public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD); + + /** + * Compares a dynamic revision (askedMrid) with a static one (foundMrid) to indicate which one + * should be considered the greater. If there is not enough information to know which one is the + * greater, the dynamic one should be considered greater and this method should return 0. This + * method should never be called with a askdeMrid for which isDynamic returns false. + * + * @param askedMrid + * the dynamic revision to compare + * @param foundMrid + * the static revision to compare + * @param staticComparator + * a comparator which can be used to compare static revisions + * @return 0 if it's not possible to know which one is greater, greater than 0 if askedMrid + * should be considered greater, lower than 0 if it can't be consider greater + */ + public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, + Comparator staticComparator); + + /** + * Returns the version matcher name identifying this version matcher + * + * @return the version matcher name identifying this version matcher + */ + public String getName(); +} diff --git a/src/java/org/apache/ivy/plugins/version/VersionRangeMatcher.java b/src/java/org/apache/ivy/plugins/version/VersionRangeMatcher.java index 54b54868..87389536 100644 --- a/src/java/org/apache/ivy/plugins/version/VersionRangeMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/VersionRangeMatcher.java @@ -1,240 +1,240 @@ -/* - * 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.version; - -import java.util.Comparator; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.latest.ArtifactInfo; -import org.apache.ivy.plugins.latest.LatestStrategy; - -/** - * Matches version ranges: [1.0,2.0] matches all versions greater or equal to 1.0 and lower or equal - * to 2.0 [1.0,2.0[ matches all versions greater or equal to 1.0 and lower than 2.0 ]1.0,2.0] - * matches all versions greater than 1.0 and lower or equal to 2.0 ]1.0,2.0[ matches all versions - * greater than 1.0 and lower than 2.0 [1.0,) matches all versions greater or equal to 1.0 ]1.0,) - * matches all versions greater than 1.0 (,2.0] matches all versions lower or equal to 2.0 (,2.0[ - * matches all versions lower than 2.0 This class uses a latest strategy to compare revisions. If - * none is set, it uses the default one of the ivy instance set through setIvy(). If neither a - * latest strategy nor a ivy instance is set, an IllegalStateException will be thrown when calling - * accept(). Note that it can't work with latest time strategy, cause no time is known for the - * limits of the range. Therefore only purely revision based LatestStrategy can be used. - */ -public class VersionRangeMatcher extends AbstractVersionMatcher { - // todo: check these constants - private final static String OPEN_INC = "["; - - private final static String OPEN_EXC = "]"; - - private final static String CLOSE_INC = "]"; - - private final static String CLOSE_EXC = "["; - - private final static String LOWER_INFINITE = "("; - - private final static String UPPER_INFINITE = ")"; - - private final static String SEPARATOR = ","; - - // following patterns are built upon constants above and should not be modified - private final static String OPEN_INC_PATTERN = "\\" + OPEN_INC; - - private final static String OPEN_EXC_PATTERN = "\\" + OPEN_EXC; - - private final static String CLOSE_INC_PATTERN = "\\" + CLOSE_INC; - - private final static String CLOSE_EXC_PATTERN = "\\" + CLOSE_EXC; - - private final static String LI_PATTERN = "\\" + LOWER_INFINITE; - - private final static String UI_PATTERN = "\\" + UPPER_INFINITE; - - private final static String SEP_PATTERN = "\\" + SEPARATOR; - - private final static String OPEN_PATTERN = "[" + OPEN_INC_PATTERN + OPEN_EXC_PATTERN + "]"; - - private final static String CLOSE_PATTERN = "[" + CLOSE_INC_PATTERN + CLOSE_EXC_PATTERN + "]"; - - private final static String ANY_NON_SPECIAL_PATTERN = "[^" + SEP_PATTERN + OPEN_INC_PATTERN - + OPEN_EXC_PATTERN + CLOSE_INC_PATTERN + CLOSE_EXC_PATTERN + LI_PATTERN + UI_PATTERN - + "]"; - - private final static String FINITE_PATTERN = OPEN_PATTERN + "(" + ANY_NON_SPECIAL_PATTERN - + "+)" + SEP_PATTERN + "(" + ANY_NON_SPECIAL_PATTERN + "+)" + CLOSE_PATTERN; - - private final static String LOWER_INFINITE_PATTERN = LI_PATTERN + "\\,(" - + ANY_NON_SPECIAL_PATTERN + "+)" + CLOSE_PATTERN; - - private final static String UPPER_INFINITE_PATTERN = OPEN_PATTERN + "(" - + ANY_NON_SPECIAL_PATTERN + "+)\\," + UI_PATTERN; - - private final static Pattern FINITE_RANGE = Pattern.compile(FINITE_PATTERN); - - private final static Pattern LOWER_INFINITE_RANGE = Pattern.compile(LOWER_INFINITE_PATTERN); - - private final static Pattern UPPER_INFINITE_RANGE = Pattern.compile(UPPER_INFINITE_PATTERN); - - private final static Pattern ALL_RANGE = Pattern.compile(FINITE_PATTERN + "|" - + LOWER_INFINITE_PATTERN + "|" + UPPER_INFINITE_PATTERN); - - private final class MRIDArtifactInfo implements ArtifactInfo { - private ModuleRevisionId _mrid; - - public MRIDArtifactInfo(ModuleRevisionId id) { - _mrid = id; - } - - public long getLastModified() { - return 0; - } - - public String getRevision() { - return _mrid.getRevision(); - } - } - - private final Comparator COMPARATOR = new Comparator() { - public int compare(Object o1, Object o2) { - if (o1.equals(o2)) { - return 0; - } - ArtifactInfo art1 = new MRIDArtifactInfo((ModuleRevisionId) o1); - ArtifactInfo art2 = new MRIDArtifactInfo((ModuleRevisionId) o2); - ArtifactInfo art = getLatestStrategy() - .findLatest(new ArtifactInfo[] {art1, art2}, null); - return art == art1 ? -1 : 1; - } - }; - - private LatestStrategy _latestStrategy; - - private String _latestStrategyName = "default"; - - public VersionRangeMatcher() { - super("version-range"); - } - - public VersionRangeMatcher(String name) { - super(name); - } - - public VersionRangeMatcher(String name, LatestStrategy strategy) { - super(name); - _latestStrategy = strategy; - } - - public boolean isDynamic(ModuleRevisionId askedMrid) { - String revision = askedMrid.getRevision(); - return ALL_RANGE.matcher(revision).matches(); - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - String revision = askedMrid.getRevision(); - Matcher m; - m = FINITE_RANGE.matcher(revision); - if (m.matches()) { - String lower = m.group(1); - String upper = m.group(2); - return isUpper(askedMrid, lower, foundMrid, revision.startsWith(OPEN_INC)) - && isLower(askedMrid, upper, foundMrid, revision.endsWith(CLOSE_INC)); - } - m = LOWER_INFINITE_RANGE.matcher(revision); - if (m.matches()) { - String upper = m.group(1); - return isLower(askedMrid, upper, foundMrid, revision.endsWith(CLOSE_INC)); - } - m = UPPER_INFINITE_RANGE.matcher(revision); - if (m.matches()) { - String lower = m.group(1); - return isUpper(askedMrid, lower, foundMrid, revision.startsWith(OPEN_INC)); - } - return false; - } - - private boolean isLower(ModuleRevisionId askedMrid, String revision, - ModuleRevisionId foundMrid, boolean inclusive) { - return COMPARATOR.compare(ModuleRevisionId.newInstance(askedMrid, revision), foundMrid) <= (inclusive ? 0 - : -1); - } - - private boolean isUpper(ModuleRevisionId askedMrid, String revision, - ModuleRevisionId foundMrid, boolean inclusive) { - return COMPARATOR.compare(ModuleRevisionId.newInstance(askedMrid, revision), foundMrid) >= (inclusive ? 0 - : 1); - } - - public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, - Comparator staticComparator) { - String revision = askedMrid.getRevision(); - Matcher m; - m = UPPER_INFINITE_RANGE.matcher(revision); - if (m.matches()) { - // no upper limit, the dynamic revision can always be considered greater - return 1; - } - String upper; - m = FINITE_RANGE.matcher(revision); - if (m.matches()) { - upper = m.group(2); - } else { - m = LOWER_INFINITE_RANGE.matcher(revision); - if (m.matches()) { - upper = m.group(1); - } else { - throw new IllegalArgumentException( - "impossible to compare: askedMrid is not a dynamic revision: " + askedMrid); - } - } - int c = staticComparator.compare(ModuleRevisionId.newInstance(askedMrid, upper), foundMrid); - // if the comparison consider them equal, we must return -1, because we can't consider the - // dynamic revision to be greater. Otherwise we can safeely return the result of the static - // comparison - return c == 0 ? -1 : c; - } - - public LatestStrategy getLatestStrategy() { - if (_latestStrategy == null) { - if (getSettings() == null) { - throw new IllegalStateException( - "no ivy instance nor latest strategy configured in version range matcher " - + this); - } - if (_latestStrategyName == null) { - throw new IllegalStateException( - "null latest strategy defined in version range matcher " + this); - } - _latestStrategy = getSettings().getLatestStrategy(_latestStrategyName); - if (_latestStrategy == null) { - throw new IllegalStateException("unknown latest strategy '" + _latestStrategyName - + "' configured in version range matcher " + this); - } - } - return _latestStrategy; - } - - public void setLatestStrategy(LatestStrategy latestStrategy) { - _latestStrategy = latestStrategy; - } - - public void setLatest(String latestStrategyName) { - _latestStrategyName = latestStrategyName; - } - -} +/* + * 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.version; + +import java.util.Comparator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.latest.ArtifactInfo; +import org.apache.ivy.plugins.latest.LatestStrategy; + +/** + * Matches version ranges: [1.0,2.0] matches all versions greater or equal to 1.0 and lower or equal + * to 2.0 [1.0,2.0[ matches all versions greater or equal to 1.0 and lower than 2.0 ]1.0,2.0] + * matches all versions greater than 1.0 and lower or equal to 2.0 ]1.0,2.0[ matches all versions + * greater than 1.0 and lower than 2.0 [1.0,) matches all versions greater or equal to 1.0 ]1.0,) + * matches all versions greater than 1.0 (,2.0] matches all versions lower or equal to 2.0 (,2.0[ + * matches all versions lower than 2.0 This class uses a latest strategy to compare revisions. If + * none is set, it uses the default one of the ivy instance set through setIvy(). If neither a + * latest strategy nor a ivy instance is set, an IllegalStateException will be thrown when calling + * accept(). Note that it can't work with latest time strategy, cause no time is known for the + * limits of the range. Therefore only purely revision based LatestStrategy can be used. + */ +public class VersionRangeMatcher extends AbstractVersionMatcher { + // todo: check these constants + private final static String OPEN_INC = "["; + + private final static String OPEN_EXC = "]"; + + private final static String CLOSE_INC = "]"; + + private final static String CLOSE_EXC = "["; + + private final static String LOWER_INFINITE = "("; + + private final static String UPPER_INFINITE = ")"; + + private final static String SEPARATOR = ","; + + // following patterns are built upon constants above and should not be modified + private final static String OPEN_INC_PATTERN = "\\" + OPEN_INC; + + private final static String OPEN_EXC_PATTERN = "\\" + OPEN_EXC; + + private final static String CLOSE_INC_PATTERN = "\\" + CLOSE_INC; + + private final static String CLOSE_EXC_PATTERN = "\\" + CLOSE_EXC; + + private final static String LI_PATTERN = "\\" + LOWER_INFINITE; + + private final static String UI_PATTERN = "\\" + UPPER_INFINITE; + + private final static String SEP_PATTERN = "\\" + SEPARATOR; + + private final static String OPEN_PATTERN = "[" + OPEN_INC_PATTERN + OPEN_EXC_PATTERN + "]"; + + private final static String CLOSE_PATTERN = "[" + CLOSE_INC_PATTERN + CLOSE_EXC_PATTERN + "]"; + + private final static String ANY_NON_SPECIAL_PATTERN = "[^" + SEP_PATTERN + OPEN_INC_PATTERN + + OPEN_EXC_PATTERN + CLOSE_INC_PATTERN + CLOSE_EXC_PATTERN + LI_PATTERN + UI_PATTERN + + "]"; + + private final static String FINITE_PATTERN = OPEN_PATTERN + "(" + ANY_NON_SPECIAL_PATTERN + + "+)" + SEP_PATTERN + "(" + ANY_NON_SPECIAL_PATTERN + "+)" + CLOSE_PATTERN; + + private final static String LOWER_INFINITE_PATTERN = LI_PATTERN + "\\,(" + + ANY_NON_SPECIAL_PATTERN + "+)" + CLOSE_PATTERN; + + private final static String UPPER_INFINITE_PATTERN = OPEN_PATTERN + "(" + + ANY_NON_SPECIAL_PATTERN + "+)\\," + UI_PATTERN; + + private final static Pattern FINITE_RANGE = Pattern.compile(FINITE_PATTERN); + + private final static Pattern LOWER_INFINITE_RANGE = Pattern.compile(LOWER_INFINITE_PATTERN); + + private final static Pattern UPPER_INFINITE_RANGE = Pattern.compile(UPPER_INFINITE_PATTERN); + + private final static Pattern ALL_RANGE = Pattern.compile(FINITE_PATTERN + "|" + + LOWER_INFINITE_PATTERN + "|" + UPPER_INFINITE_PATTERN); + + private final class MRIDArtifactInfo implements ArtifactInfo { + private ModuleRevisionId _mrid; + + public MRIDArtifactInfo(ModuleRevisionId id) { + _mrid = id; + } + + public long getLastModified() { + return 0; + } + + public String getRevision() { + return _mrid.getRevision(); + } + } + + private final Comparator COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + if (o1.equals(o2)) { + return 0; + } + ArtifactInfo art1 = new MRIDArtifactInfo((ModuleRevisionId) o1); + ArtifactInfo art2 = new MRIDArtifactInfo((ModuleRevisionId) o2); + ArtifactInfo art = getLatestStrategy() + .findLatest(new ArtifactInfo[] {art1, art2}, null); + return art == art1 ? -1 : 1; + } + }; + + private LatestStrategy _latestStrategy; + + private String _latestStrategyName = "default"; + + public VersionRangeMatcher() { + super("version-range"); + } + + public VersionRangeMatcher(String name) { + super(name); + } + + public VersionRangeMatcher(String name, LatestStrategy strategy) { + super(name); + _latestStrategy = strategy; + } + + public boolean isDynamic(ModuleRevisionId askedMrid) { + String revision = askedMrid.getRevision(); + return ALL_RANGE.matcher(revision).matches(); + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + String revision = askedMrid.getRevision(); + Matcher m; + m = FINITE_RANGE.matcher(revision); + if (m.matches()) { + String lower = m.group(1); + String upper = m.group(2); + return isUpper(askedMrid, lower, foundMrid, revision.startsWith(OPEN_INC)) + && isLower(askedMrid, upper, foundMrid, revision.endsWith(CLOSE_INC)); + } + m = LOWER_INFINITE_RANGE.matcher(revision); + if (m.matches()) { + String upper = m.group(1); + return isLower(askedMrid, upper, foundMrid, revision.endsWith(CLOSE_INC)); + } + m = UPPER_INFINITE_RANGE.matcher(revision); + if (m.matches()) { + String lower = m.group(1); + return isUpper(askedMrid, lower, foundMrid, revision.startsWith(OPEN_INC)); + } + return false; + } + + private boolean isLower(ModuleRevisionId askedMrid, String revision, + ModuleRevisionId foundMrid, boolean inclusive) { + return COMPARATOR.compare(ModuleRevisionId.newInstance(askedMrid, revision), foundMrid) <= (inclusive ? 0 + : -1); + } + + private boolean isUpper(ModuleRevisionId askedMrid, String revision, + ModuleRevisionId foundMrid, boolean inclusive) { + return COMPARATOR.compare(ModuleRevisionId.newInstance(askedMrid, revision), foundMrid) >= (inclusive ? 0 + : 1); + } + + public int compare(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid, + Comparator staticComparator) { + String revision = askedMrid.getRevision(); + Matcher m; + m = UPPER_INFINITE_RANGE.matcher(revision); + if (m.matches()) { + // no upper limit, the dynamic revision can always be considered greater + return 1; + } + String upper; + m = FINITE_RANGE.matcher(revision); + if (m.matches()) { + upper = m.group(2); + } else { + m = LOWER_INFINITE_RANGE.matcher(revision); + if (m.matches()) { + upper = m.group(1); + } else { + throw new IllegalArgumentException( + "impossible to compare: askedMrid is not a dynamic revision: " + askedMrid); + } + } + int c = staticComparator.compare(ModuleRevisionId.newInstance(askedMrid, upper), foundMrid); + // if the comparison consider them equal, we must return -1, because we can't consider the + // dynamic revision to be greater. Otherwise we can safeely return the result of the static + // comparison + return c == 0 ? -1 : c; + } + + public LatestStrategy getLatestStrategy() { + if (_latestStrategy == null) { + if (getSettings() == null) { + throw new IllegalStateException( + "no ivy instance nor latest strategy configured in version range matcher " + + this); + } + if (_latestStrategyName == null) { + throw new IllegalStateException( + "null latest strategy defined in version range matcher " + this); + } + _latestStrategy = getSettings().getLatestStrategy(_latestStrategyName); + if (_latestStrategy == null) { + throw new IllegalStateException("unknown latest strategy '" + _latestStrategyName + + "' configured in version range matcher " + this); + } + } + return _latestStrategy; + } + + public void setLatestStrategy(LatestStrategy latestStrategy) { + _latestStrategy = latestStrategy; + } + + public void setLatest(String latestStrategyName) { + _latestStrategyName = latestStrategyName; + } + +} diff --git a/src/java/org/apache/ivy/tools/analyser/DependencyAnalyser.java b/src/java/org/apache/ivy/tools/analyser/DependencyAnalyser.java index cbd8fca9..1b450404 100644 --- a/src/java/org/apache/ivy/tools/analyser/DependencyAnalyser.java +++ b/src/java/org/apache/ivy/tools/analyser/DependencyAnalyser.java @@ -1,24 +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. - * - */ -package org.apache.ivy.tools.analyser; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; - -public interface DependencyAnalyser { - public ModuleDescriptor[] analyze(JarModule[] modules); -} +/* + * 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.tools.analyser; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; + +public interface DependencyAnalyser { + public ModuleDescriptor[] analyze(JarModule[] modules); +} diff --git a/src/java/org/apache/ivy/tools/analyser/JarJarDependencyAnalyser.java b/src/java/org/apache/ivy/tools/analyser/JarJarDependencyAnalyser.java index f2252b2c..a7b179a8 100644 --- a/src/java/org/apache/ivy/tools/analyser/JarJarDependencyAnalyser.java +++ b/src/java/org/apache/ivy/tools/analyser/JarJarDependencyAnalyser.java @@ -1,96 +1,96 @@ -/* - * 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.tools.analyser; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.util.Message; - -public class JarJarDependencyAnalyser implements DependencyAnalyser { - private File _jarjarjarLocation; - - public JarJarDependencyAnalyser(File jarjarjarLocation) { - _jarjarjarLocation = jarjarjarLocation; - } - - public ModuleDescriptor[] analyze(JarModule[] modules) { - - StringBuffer jarjarCmd = new StringBuffer("java -jar \"").append( - _jarjarjarLocation.getAbsolutePath()).append("\" --find --level=jar "); - Map jarModulesMap = new HashMap(); - Map mds = new HashMap(); - - for (int i = 0; i < modules.length; i++) { - jarModulesMap.put(modules[i].getJar().getAbsolutePath(), modules[i]); - DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(modules[i] - .getMrid(), new Date(modules[i].getJar().lastModified())); - mds.put(modules[i].getMrid(), md); - jarjarCmd.append("\"").append(modules[i].getJar().getAbsolutePath()).append("\""); - if (i + 1 < modules.length) { - jarjarCmd.append(File.pathSeparator); - } - } - - Message.verbose("jarjar command: " + jarjarCmd); - - try { - Process p = Runtime.getRuntime().exec(jarjarCmd.toString()); - BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line; - while ((line = r.readLine()) != null) { - String[] deps = line.split(" -> "); - JarModule module = (JarModule) jarModulesMap.get(deps[0]); - JarModule dependency = (JarModule) jarModulesMap.get(deps[1]); - - if (module.getMrid().getModuleId().equals(dependency.getMrid().getModuleId())) { - continue; - } - Message.verbose(module.getMrid() + " depends on " + dependency.getMrid()); - - DefaultModuleDescriptor md = (DefaultModuleDescriptor) mds.get(module.getMrid()); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, dependency - .getMrid(), false, false, true); - dd.addDependencyConfiguration(ModuleDescriptor.DEFAULT_CONFIGURATION, - ModuleDescriptor.DEFAULT_CONFIGURATION); - md.addDependency(dd); - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return (ModuleDescriptor[]) mds.values().toArray(new ModuleDescriptor[mds.values().size()]); - } - - public static void main(String[] args) { - JarJarDependencyAnalyser a = new JarJarDependencyAnalyser(new File( - "D:/temp/test2/jarjar-0.7.jar")); - a.analyze(new JarModuleFinder( - "D:/temp/test2/ivyrep/[organisation]/[module]/[revision]/[artifact].[ext]") - .findJarModules()); - } -} +/* + * 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.tools.analyser; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.util.Message; + +public class JarJarDependencyAnalyser implements DependencyAnalyser { + private File _jarjarjarLocation; + + public JarJarDependencyAnalyser(File jarjarjarLocation) { + _jarjarjarLocation = jarjarjarLocation; + } + + public ModuleDescriptor[] analyze(JarModule[] modules) { + + StringBuffer jarjarCmd = new StringBuffer("java -jar \"").append( + _jarjarjarLocation.getAbsolutePath()).append("\" --find --level=jar "); + Map jarModulesMap = new HashMap(); + Map mds = new HashMap(); + + for (int i = 0; i < modules.length; i++) { + jarModulesMap.put(modules[i].getJar().getAbsolutePath(), modules[i]); + DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(modules[i] + .getMrid(), new Date(modules[i].getJar().lastModified())); + mds.put(modules[i].getMrid(), md); + jarjarCmd.append("\"").append(modules[i].getJar().getAbsolutePath()).append("\""); + if (i + 1 < modules.length) { + jarjarCmd.append(File.pathSeparator); + } + } + + Message.verbose("jarjar command: " + jarjarCmd); + + try { + Process p = Runtime.getRuntime().exec(jarjarCmd.toString()); + BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line; + while ((line = r.readLine()) != null) { + String[] deps = line.split(" -> "); + JarModule module = (JarModule) jarModulesMap.get(deps[0]); + JarModule dependency = (JarModule) jarModulesMap.get(deps[1]); + + if (module.getMrid().getModuleId().equals(dependency.getMrid().getModuleId())) { + continue; + } + Message.verbose(module.getMrid() + " depends on " + dependency.getMrid()); + + DefaultModuleDescriptor md = (DefaultModuleDescriptor) mds.get(module.getMrid()); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, dependency + .getMrid(), false, false, true); + dd.addDependencyConfiguration(ModuleDescriptor.DEFAULT_CONFIGURATION, + ModuleDescriptor.DEFAULT_CONFIGURATION); + md.addDependency(dd); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return (ModuleDescriptor[]) mds.values().toArray(new ModuleDescriptor[mds.values().size()]); + } + + public static void main(String[] args) { + JarJarDependencyAnalyser a = new JarJarDependencyAnalyser(new File( + "D:/temp/test2/jarjar-0.7.jar")); + a.analyze(new JarModuleFinder( + "D:/temp/test2/ivyrep/[organisation]/[module]/[revision]/[artifact].[ext]") + .findJarModules()); + } +} diff --git a/src/java/org/apache/ivy/tools/analyser/JarModule.java b/src/java/org/apache/ivy/tools/analyser/JarModule.java index 85f08199..b828b92f 100644 --- a/src/java/org/apache/ivy/tools/analyser/JarModule.java +++ b/src/java/org/apache/ivy/tools/analyser/JarModule.java @@ -1,46 +1,46 @@ -/* - * 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.tools.analyser; - -import java.io.File; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class JarModule { - private ModuleRevisionId _mrid; - - private File _jar; - - public JarModule(ModuleRevisionId mrid, File jar) { - _mrid = mrid; - _jar = jar; - } - - public File getJar() { - return _jar; - } - - public ModuleRevisionId getMrid() { - return _mrid; - } - - public String toString() { - return _jar + " " + _mrid; - } - -} +/* + * 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.tools.analyser; + +import java.io.File; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class JarModule { + private ModuleRevisionId _mrid; + + private File _jar; + + public JarModule(ModuleRevisionId mrid, File jar) { + _mrid = mrid; + _jar = jar; + } + + public File getJar() { + return _jar; + } + + public ModuleRevisionId getMrid() { + return _mrid; + } + + public String toString() { + return _jar + " " + _mrid; + } + +} diff --git a/src/java/org/apache/ivy/tools/analyser/JarModuleFinder.java b/src/java/org/apache/ivy/tools/analyser/JarModuleFinder.java index ef334347..261f03e5 100644 --- a/src/java/org/apache/ivy/tools/analyser/JarModuleFinder.java +++ b/src/java/org/apache/ivy/tools/analyser/JarModuleFinder.java @@ -1,78 +1,78 @@ -/* - * 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.tools.analyser; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.resolver.util.FileURLLister; -import org.apache.ivy.plugins.resolver.util.ResolverHelper; -import org.apache.ivy.plugins.resolver.util.URLLister; - -public class JarModuleFinder { - private String _pattern; - - private String _filePattern; - - public JarModuleFinder(String pattern) { - _pattern = "file:///" + pattern; - _filePattern = pattern; - } - - public JarModule[] findJarModules() { - List ret = new ArrayList(); - URLLister lister = new FileURLLister(); - try { - String[] orgs = ResolverHelper.listTokenValues(lister, _pattern, "organisation"); - for (int i = 0; i < orgs.length; i++) { - String orgPattern = IvyPatternHelper.substituteToken(_pattern, - IvyPatternHelper.ORGANISATION_KEY, orgs[i]); - String[] modules = ResolverHelper.listTokenValues(lister, orgPattern, "module"); - for (int j = 0; j < modules.length; j++) { - String modPattern = IvyPatternHelper.substituteToken(orgPattern, - IvyPatternHelper.MODULE_KEY, modules[j]); - String[] revs = ResolverHelper.listTokenValues(lister, modPattern, "revision"); - for (int k = 0; k < revs.length; k++) { - File jar = new File(IvyPatternHelper.substitute(_filePattern, orgs[i], - modules[j], revs[k], modules[j], "jar", "jar")); - if (jar.exists()) { - ret.add(new JarModule(ModuleRevisionId.newInstance(orgs[i], modules[j], - revs[k]), jar)); - } - } - } - } - - } catch (Exception e) { - // TODO: handle exception - } - return (JarModule[]) ret.toArray(new JarModule[ret.size()]); - } - - public static void main(String[] args) { - JarModule[] mods = new JarModuleFinder( - "D:/temp/test2/ivyrep/[organisation]/[module]/[revision]/[artifact].[ext]") - .findJarModules(); - for (int i = 0; i < mods.length; i++) { - System.out.println(mods[i]); - } - } -} +/* + * 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.tools.analyser; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.resolver.util.FileURLLister; +import org.apache.ivy.plugins.resolver.util.ResolverHelper; +import org.apache.ivy.plugins.resolver.util.URLLister; + +public class JarModuleFinder { + private String _pattern; + + private String _filePattern; + + public JarModuleFinder(String pattern) { + _pattern = "file:///" + pattern; + _filePattern = pattern; + } + + public JarModule[] findJarModules() { + List ret = new ArrayList(); + URLLister lister = new FileURLLister(); + try { + String[] orgs = ResolverHelper.listTokenValues(lister, _pattern, "organisation"); + for (int i = 0; i < orgs.length; i++) { + String orgPattern = IvyPatternHelper.substituteToken(_pattern, + IvyPatternHelper.ORGANISATION_KEY, orgs[i]); + String[] modules = ResolverHelper.listTokenValues(lister, orgPattern, "module"); + for (int j = 0; j < modules.length; j++) { + String modPattern = IvyPatternHelper.substituteToken(orgPattern, + IvyPatternHelper.MODULE_KEY, modules[j]); + String[] revs = ResolverHelper.listTokenValues(lister, modPattern, "revision"); + for (int k = 0; k < revs.length; k++) { + File jar = new File(IvyPatternHelper.substitute(_filePattern, orgs[i], + modules[j], revs[k], modules[j], "jar", "jar")); + if (jar.exists()) { + ret.add(new JarModule(ModuleRevisionId.newInstance(orgs[i], modules[j], + revs[k]), jar)); + } + } + } + } + + } catch (Exception e) { + // TODO: handle exception + } + return (JarModule[]) ret.toArray(new JarModule[ret.size()]); + } + + public static void main(String[] args) { + JarModule[] mods = new JarModuleFinder( + "D:/temp/test2/ivyrep/[organisation]/[module]/[revision]/[artifact].[ext]") + .findJarModules(); + for (int i = 0; i < mods.length; i++) { + System.out.println(mods[i]); + } + } +} diff --git a/src/java/org/apache/ivy/tools/analyser/RepositoryAnalyser.java b/src/java/org/apache/ivy/tools/analyser/RepositoryAnalyser.java index 010f225d..801b8179 100644 --- a/src/java/org/apache/ivy/tools/analyser/RepositoryAnalyser.java +++ b/src/java/org/apache/ivy/tools/analyser/RepositoryAnalyser.java @@ -1,59 +1,59 @@ -/* - * 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.tools.analyser; - -import java.io.File; -import java.io.IOException; - -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; -import org.apache.ivy.util.Message; - -public class RepositoryAnalyser { - public void analyse(String pattern, DependencyAnalyser depAnalyser) { - JarModuleFinder finder = new JarModuleFinder(pattern); - ModuleDescriptor[] mds = depAnalyser.analyze(finder.findJarModules()); - Message.info("found " + mds.length + " modules"); - for (int i = 0; i < mds.length; i++) { - File ivyFile = new File(IvyPatternHelper.substitute(pattern, DefaultArtifact - .newIvyArtifact(mds[i].getModuleRevisionId(), mds[i].getPublicationDate()))); - try { - Message.info("generating " + ivyFile); - XmlModuleDescriptorWriter.write(mds[i], ivyFile); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - public static void main(String[] args) { - if (args.length != 2) { - System.out - .println("usage: ivyanalyser path/to/jarjar.jar absolute-ivy-repository-pattern"); - return; - } - String jarjarLocation = args[0]; - String pattern = args[1]; - - JarJarDependencyAnalyser a = new JarJarDependencyAnalyser(new File(jarjarLocation)); - new RepositoryAnalyser().analyse(pattern, a); - } -} +/* + * 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.tools.analyser; + +import java.io.File; +import java.io.IOException; + +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; +import org.apache.ivy.util.Message; + +public class RepositoryAnalyser { + public void analyse(String pattern, DependencyAnalyser depAnalyser) { + JarModuleFinder finder = new JarModuleFinder(pattern); + ModuleDescriptor[] mds = depAnalyser.analyze(finder.findJarModules()); + Message.info("found " + mds.length + " modules"); + for (int i = 0; i < mds.length; i++) { + File ivyFile = new File(IvyPatternHelper.substitute(pattern, DefaultArtifact + .newIvyArtifact(mds[i].getModuleRevisionId(), mds[i].getPublicationDate()))); + try { + Message.info("generating " + ivyFile); + XmlModuleDescriptorWriter.write(mds[i], ivyFile); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public static void main(String[] args) { + if (args.length != 2) { + System.out + .println("usage: ivyanalyser path/to/jarjar.jar absolute-ivy-repository-pattern"); + return; + } + String jarjarLocation = args[0]; + String pattern = args[1]; + + JarJarDependencyAnalyser a = new JarJarDependencyAnalyser(new File(jarjarLocation)); + new RepositoryAnalyser().analyse(pattern, a); + } +} diff --git a/src/java/org/apache/ivy/util/ChecksumHelper.java b/src/java/org/apache/ivy/util/ChecksumHelper.java index f4203238..ccca27a2 100644 --- a/src/java/org/apache/ivy/util/ChecksumHelper.java +++ b/src/java/org/apache/ivy/util/ChecksumHelper.java @@ -1,137 +1,137 @@ -/* - * 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.util; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.HashMap; -import java.util.Map; - -public class ChecksumHelper { - - private static Map _algorithms = new HashMap(); - static { - _algorithms.put("md5", "MD5"); - _algorithms.put("sha1", "SHA-1"); - } - - /** - * Checks the checksum of the given file against the given checksumFile, and throws an - * IOException if the checksum is not compliant - * - * @param dest - * the file to test - * @param checksumFile - * the file containing the expected checksum - * @param algorithm - * the checksum algorithm to use - * @throws IOException - * if an IO problem occur whle reading files or if the checksum is not compliant - */ - public static void check(File dest, File checksumFile, String algorithm) throws IOException { - String csFileContent = FileUtil.readEntirely( - new BufferedReader(new FileReader(checksumFile))).trim().toLowerCase(); - String expected; - int spaceIndex = csFileContent.indexOf(' '); - if (spaceIndex != -1) { - expected = csFileContent.substring(0, spaceIndex); - } else { - expected = csFileContent; - } - - String computed = computeAsString(dest, algorithm).trim().toLowerCase(); - if (!expected.equals(computed)) { - throw new IOException("invalid " + algorithm + ": expected=" + expected + " computed=" - + computed); - } - } - - public static String computeAsString(File f, String algorithm) throws IOException { - return byteArrayToHexString(compute(f, algorithm)); - } - - private static byte[] compute(File f, String algorithm) throws IOException { - InputStream is = new FileInputStream(f); - - try { - MessageDigest md = getMessageDigest(algorithm); - md.reset(); - - byte[] buf = new byte[2048]; - int len = 0; - while ((len = is.read(buf)) != -1) { - md.update(buf, 0, len); - } - return md.digest(); - } finally { - is.close(); - } - } - - private static MessageDigest getMessageDigest(String algorithm) { - String mdAlgorithm = (String) _algorithms.get(algorithm); - if (mdAlgorithm == null) { - throw new IllegalArgumentException("unknown algorithm " + algorithm); - } - try { - return MessageDigest.getInstance(mdAlgorithm); - } catch (NoSuchAlgorithmException e) { - throw new IllegalArgumentException("unknown algorithm " + algorithm); - } - } - - // byte to hex string converter - private final static char[] CHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', - 'b', 'c', 'd', 'e', 'f'}; - - /** - * Convert a byte[] array to readable string format. This makes the "hex" readable! - * - * @return result String buffer in String format - * @param in - * byte[] buffer to convert to string format - */ - public static String byteArrayToHexString(byte in[]) { - byte ch = 0x00; - - if (in == null || in.length <= 0) { - return null; - } - - StringBuffer out = new StringBuffer(in.length * 2); - - for (int i = 0; i < in.length; i++) { - ch = (byte) (in[i] & 0xF0); // Strip off high nibble - ch = (byte) (ch >>> 4); // shift the bits down - ch = (byte) (ch & 0x0F); // must do this is high order bit is on! - - out.append(CHARS[(int) ch]); // convert the nibble to a String Character - ch = (byte) (in[i] & 0x0F); // Strip off low nibble - out.append(CHARS[(int) ch]); // convert the nibble to a String Character - } - - return out.toString(); - } - -} +/* + * 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.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.Map; + +public class ChecksumHelper { + + private static Map _algorithms = new HashMap(); + static { + _algorithms.put("md5", "MD5"); + _algorithms.put("sha1", "SHA-1"); + } + + /** + * Checks the checksum of the given file against the given checksumFile, and throws an + * IOException if the checksum is not compliant + * + * @param dest + * the file to test + * @param checksumFile + * the file containing the expected checksum + * @param algorithm + * the checksum algorithm to use + * @throws IOException + * if an IO problem occur whle reading files or if the checksum is not compliant + */ + public static void check(File dest, File checksumFile, String algorithm) throws IOException { + String csFileContent = FileUtil.readEntirely( + new BufferedReader(new FileReader(checksumFile))).trim().toLowerCase(); + String expected; + int spaceIndex = csFileContent.indexOf(' '); + if (spaceIndex != -1) { + expected = csFileContent.substring(0, spaceIndex); + } else { + expected = csFileContent; + } + + String computed = computeAsString(dest, algorithm).trim().toLowerCase(); + if (!expected.equals(computed)) { + throw new IOException("invalid " + algorithm + ": expected=" + expected + " computed=" + + computed); + } + } + + public static String computeAsString(File f, String algorithm) throws IOException { + return byteArrayToHexString(compute(f, algorithm)); + } + + private static byte[] compute(File f, String algorithm) throws IOException { + InputStream is = new FileInputStream(f); + + try { + MessageDigest md = getMessageDigest(algorithm); + md.reset(); + + byte[] buf = new byte[2048]; + int len = 0; + while ((len = is.read(buf)) != -1) { + md.update(buf, 0, len); + } + return md.digest(); + } finally { + is.close(); + } + } + + private static MessageDigest getMessageDigest(String algorithm) { + String mdAlgorithm = (String) _algorithms.get(algorithm); + if (mdAlgorithm == null) { + throw new IllegalArgumentException("unknown algorithm " + algorithm); + } + try { + return MessageDigest.getInstance(mdAlgorithm); + } catch (NoSuchAlgorithmException e) { + throw new IllegalArgumentException("unknown algorithm " + algorithm); + } + } + + // byte to hex string converter + private final static char[] CHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', + 'b', 'c', 'd', 'e', 'f'}; + + /** + * Convert a byte[] array to readable string format. This makes the "hex" readable! + * + * @return result String buffer in String format + * @param in + * byte[] buffer to convert to string format + */ + public static String byteArrayToHexString(byte in[]) { + byte ch = 0x00; + + if (in == null || in.length <= 0) { + return null; + } + + StringBuffer out = new StringBuffer(in.length * 2); + + for (int i = 0; i < in.length; i++) { + ch = (byte) (in[i] & 0xF0); // Strip off high nibble + ch = (byte) (ch >>> 4); // shift the bits down + ch = (byte) (ch & 0x0F); // must do this is high order bit is on! + + out.append(CHARS[(int) ch]); // convert the nibble to a String Character + ch = (byte) (in[i] & 0x0F); // Strip off low nibble + out.append(CHARS[(int) ch]); // convert the nibble to a String Character + } + + return out.toString(); + } + +} diff --git a/src/java/org/apache/ivy/util/ConfigurationUtils.java b/src/java/org/apache/ivy/util/ConfigurationUtils.java index 24462e79..e4f8d725 100644 --- a/src/java/org/apache/ivy/util/ConfigurationUtils.java +++ b/src/java/org/apache/ivy/util/ConfigurationUtils.java @@ -1,86 +1,86 @@ -/* - * 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.util; - -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.Set; - -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.descriptor.Configuration.Visibility; - -/** - * Class containing several utility methods for working with configurations. - */ -public class ConfigurationUtils { - - /** - * Private constructor to avoid instantiation of this class. - */ - private ConfigurationUtils() { - } - - /** - * Replace all the wildcards in the given configuration array. Supported wildcards are: - *

        - *
      • *:all configurations
      • - *
      • *(public):all public configurations
      • - *
      • *(private):all private configurations
      • - *
      - * If the given array of configurations is null, all configurations are returned. - * - * @param confs - * the configurations, can contain wildcards - * @param md - * the configurations where the wildcards are replaced - * @return - */ - public static String[] replaceWildcards(String[] confs, ModuleDescriptor md) { - Set result = new LinkedHashSet(); - - if (confs == null) { - return md.getConfigurationsNames(); - } - - for (int i = 0; i < confs.length; i++) { - if ("*".equals(confs[i])) { - result.addAll(Arrays.asList(md.getConfigurationsNames())); - } else if ("*(public)".equals(confs[i])) { - Configuration[] all = md.getConfigurations(); - for (int j = 0; j < all.length; j++) { - if (all[j].getVisibility().equals(Visibility.PUBLIC)) { - result.add(all[j].getName()); - } - } - } else if ("*(private)".equals(confs[i])) { - Configuration[] all = md.getConfigurations(); - for (int j = 0; j < all.length; j++) { - if (all[j].getVisibility().equals(Visibility.PRIVATE)) { - result.add(all[j].getName()); - } - } - } else { - result.add(confs[i]); - } - } - - return (String[]) result.toArray(new String[result.size()]); - } - -} +/* + * 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.util; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.descriptor.Configuration.Visibility; + +/** + * Class containing several utility methods for working with configurations. + */ +public class ConfigurationUtils { + + /** + * Private constructor to avoid instantiation of this class. + */ + private ConfigurationUtils() { + } + + /** + * Replace all the wildcards in the given configuration array. Supported wildcards are: + *
        + *
      • *:all configurations
      • + *
      • *(public):all public configurations
      • + *
      • *(private):all private configurations
      • + *
      + * If the given array of configurations is null, all configurations are returned. + * + * @param confs + * the configurations, can contain wildcards + * @param md + * the configurations where the wildcards are replaced + * @return + */ + public static String[] replaceWildcards(String[] confs, ModuleDescriptor md) { + Set result = new LinkedHashSet(); + + if (confs == null) { + return md.getConfigurationsNames(); + } + + for (int i = 0; i < confs.length; i++) { + if ("*".equals(confs[i])) { + result.addAll(Arrays.asList(md.getConfigurationsNames())); + } else if ("*(public)".equals(confs[i])) { + Configuration[] all = md.getConfigurations(); + for (int j = 0; j < all.length; j++) { + if (all[j].getVisibility().equals(Visibility.PUBLIC)) { + result.add(all[j].getName()); + } + } + } else if ("*(private)".equals(confs[i])) { + Configuration[] all = md.getConfigurations(); + for (int j = 0; j < all.length; j++) { + if (all[j].getVisibility().equals(Visibility.PRIVATE)) { + result.add(all[j].getName()); + } + } + } else { + result.add(confs[i]); + } + } + + return (String[]) result.toArray(new String[result.size()]); + } + +} diff --git a/src/java/org/apache/ivy/util/Configurator.java b/src/java/org/apache/ivy/util/Configurator.java index 7fcdad3e..c7a76ac8 100644 --- a/src/java/org/apache/ivy/util/Configurator.java +++ b/src/java/org/apache/ivy/util/Configurator.java @@ -1,695 +1,695 @@ -/* - * 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.util; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; - -import org.apache.ivy.core.IvyPatternHelper; - -/** - * Ant 1.6.1 like Configurator This configurator is used to configure elements (initialised with - * setRoot) using the behaviour defined by ant for its tasks. Example (based on Ant Example) : Configurator - * conf = new Configurator(); conf.typeDef("buildpath", "Sample$BuildPath"); - * conf.typeDef("xinterface", "Sample$XInterface"); Sample.MyFileSelector mfs = new - * Sample.MyFileSelector(); conf.setRoot(mfs); conf.startCreateChild("buildpath"); - * conf.setAttribute("path", "."); conf.setAttribute("url", "abc"); - * conf.startCreateChild("xinterface"); conf.setAttribute("count", "4"); conf.endCreateChild(); // - * xinterface conf.endCreateChild(); // buildpath - */ -public class Configurator { - public static class Macro { - private MacroDef _macrodef; - - private Map _attValues = new HashMap(); - - private Map _macroRecords = new HashMap(); - - public Macro(MacroDef def) { - _macrodef = def; - } - - public void defineAttribute(String attributeName, String value) { - if (_macrodef.getAttribute(attributeName) == null) { - throw new IllegalArgumentException("undeclared attribute " + attributeName - + " on macro " + _macrodef.getName()); - } - _attValues.put(attributeName, value); - } - - public MacroRecord recordCreateChild(String name) { - MacroRecord macroRecord = new MacroRecord(name); - List records = (List) _macroRecords.get(name); - if (records == null) { - records = new ArrayList(); - _macroRecords.put(name, records); - } - records.add(macroRecord); - return macroRecord; - } - - public Object play(Configurator conf) { - return _macrodef.play(conf, _attValues, _macroRecords); - } - - } - - public static class Attribute { - private String _name; - - private String _default; - - public String getDefault() { - return _default; - } - - public void setDefault(String default1) { - _default = default1; - } - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - } - - public static class Element { - private String _name; - - private boolean _optional = false; - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public boolean isOptional() { - return _optional; - } - - public void setOptional(boolean optional) { - _optional = optional; - } - } - - public static class MacroRecord { - private String _name; - - private Map _attributes = new LinkedHashMap(); - - private List _children = new ArrayList(); - - public MacroRecord(String name) { - _name = name; - } - - public String getName() { - return _name; - } - - public void recordAttribute(String name, String value) { - _attributes.put(name, value); - } - - public MacroRecord recordChild(String name) { - MacroRecord child = new MacroRecord(name); - _children.add(child); - return child; - } - - public Map getAttributes() { - return _attributes; - } - - public List getChildren() { - return _children; - } - } - - public static class MacroDef { - private String _name; - - private Map _attributes = new HashMap(); - - private Map _elements = new HashMap(); - - private MacroRecord _macroRecord; - - public MacroDef(String macroName) { - _name = macroName; - } - - public Attribute getAttribute(String attributeName) { - return (Attribute) _attributes.get(attributeName); - } - - public Object play(Configurator conf, Map attValues, Map macroRecords) { - for (Iterator iter = _attributes.values().iterator(); iter.hasNext();) { - Attribute att = (Attribute) iter.next(); - String val = (String) attValues.get(att.getName()); - if (val == null) { - if (att.getDefault() == null) { - throw new IllegalArgumentException("attribute " + att.getName() - + " is required in " + getName()); - } else { - attValues.put(att.getName(), att.getDefault()); - } - } - } - return play(conf, _macroRecord, attValues, macroRecords); - } - - private Object play(Configurator conf, MacroRecord macroRecord, Map attValues, - Map childrenRecords) { - conf.startCreateChild(macroRecord.getName()); - Map attributes = macroRecord.getAttributes(); - for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { - String attName = (String) iter.next(); - String attValue = replaceParam((String) attributes.get(attName), attValues); - conf.setAttribute(attName, attValue); - } - for (Iterator iter = macroRecord.getChildren().iterator(); iter.hasNext();) { - MacroRecord child = (MacroRecord) iter.next(); - Element elt = (Element) _elements.get(child.getName()); - if (elt != null) { - List elements = (List) childrenRecords.get(child.getName()); - if (elements != null) { - for (Iterator iterator = elements.iterator(); iterator.hasNext();) { - MacroRecord element = (MacroRecord) iterator.next(); - for (Iterator it2 = element.getChildren().iterator(); it2.hasNext();) { - MacroRecord r = (MacroRecord) it2.next(); - play(conf, r, attValues, Collections.EMPTY_MAP); - } - } - } else if (!elt.isOptional()) { - throw new IllegalArgumentException( - "non optional element is not specified: " + elt.getName() - + " in macro " + getName()); - } - continue; - } - play(conf, child, attValues, childrenRecords); - } - return conf.endCreateChild(); - } - - private String replaceParam(String string, Map attValues) { - return IvyPatternHelper.substituteParams(string, attValues); - } - - public String getName() { - return _name; - } - - public void addConfiguredAttribute(Attribute att) { - _attributes.put(att.getName(), att); - } - - public void addConfiguredElement(Element elt) { - _elements.put(elt.getName(), elt); - } - - public Macro createMacro() { - return new Macro(this); - } - - public void addAttribute(String attName, String attDefaultValue) { - Attribute att = new Attribute(); - att.setName(attName); - att.setDefault(attDefaultValue); - addConfiguredAttribute(att); - } - - public void addElement(String elementName, boolean optional) { - Element elt = new Element(); - elt.setName(elementName); - elt.setOptional(optional); - addConfiguredElement(elt); - } - - public MacroRecord recordCreateChild(String name) { - _macroRecord = new MacroRecord(name); - return _macroRecord; - } - } - - private static class ObjectDescriptor { - private Object _obj; - - private String _objName; - - private Map _createMethods = new HashMap(); - - private Map _addMethods = new HashMap(); - - private Map _addConfiguredMethods = new HashMap(); - - private Map _setMethods = new HashMap(); - - private Map _typeAddMethods = new HashMap(); - - private Map _typeAddConfiguredMethods = new HashMap(); - - public ObjectDescriptor(Object object, String objName) { - _obj = object; - _objName = objName; - Method[] methods = object.getClass().getMethods(); - for (int i = 0; i < methods.length; i++) { - Method m = methods[i]; - if (m.getName().startsWith("create") && m.getParameterTypes().length == 0 - && !Void.TYPE.equals(m.getReturnType())) { - String name = StringUtils - .uncapitalize(m.getName().substring("create".length())); - if (name.length() == 0) { - continue; - } - addCreateMethod(name, m); - } else if (m.getName().startsWith("addConfigured") - && m.getParameterTypes().length == 1 && Void.TYPE.equals(m.getReturnType())) { - String name = StringUtils.uncapitalize(m.getName().substring( - "addConfigured".length())); - if (name.length() == 0) { - addAddConfiguredMethod(m); - } - addAddConfiguredMethod(name, m); - } else if (m.getName().startsWith("add") - && !m.getName().startsWith("addConfigured") - && m.getParameterTypes().length == 1 && Void.TYPE.equals(m.getReturnType())) { - String name = StringUtils.uncapitalize(m.getName().substring("add".length())); - if (name.length() == 0) { - addAddMethod(m); - } - addAddMethod(name, m); - } else if (m.getName().startsWith("set") && m.getParameterTypes().length == 1 - && Void.TYPE.equals(m.getReturnType())) { - String name = StringUtils.uncapitalize(m.getName().substring("set".length())); - if (name.length() == 0) { - continue; - } - addSetMethod(name, m); - } - } - } - - public void addCreateMethod(String name, Method m) { - _createMethods.put(name, m); - } - - public void addAddMethod(String name, Method m) { - _addMethods.put(name, m); - } - - public void addAddConfiguredMethod(String name, Method m) { - _addConfiguredMethods.put(name, m); - } - - private void addAddMethod(Method m) { - _typeAddMethods.put(m.getParameterTypes()[0], m); - } - - private void addAddConfiguredMethod(Method m) { - _typeAddConfiguredMethods.put(m.getParameterTypes()[0], m); - } - - public void addSetMethod(String name, Method m) { - _setMethods.put(name, m); - } - - public Object getObject() { - return _obj; - } - - public Method getCreateMethod(String name) { - return (Method) _createMethods.get(name); - } - - public Method getAddMethod(String name) { - return (Method) _addMethods.get(name); - } - - public Method getAddConfiguredMethod(String name) { - return (Method) _addConfiguredMethods.get(name); - } - - public Method getAddMethod(Class type) { - return getTypeMatchingMethod(type, _typeAddMethods); - } - - public Method getAddConfiguredMethod(Class type) { - return getTypeMatchingMethod(type, _typeAddConfiguredMethods); - } - - private Method getTypeMatchingMethod(Class type, Map typeMethods) { - Method m = (Method) typeMethods.get(type); - if (m != null) { - return m; - } - for (Iterator iter = typeMethods.keySet().iterator(); iter.hasNext();) { - Class clss = (Class) iter.next(); - if (clss.isAssignableFrom(type)) { - return (Method) typeMethods.get(clss); - } - } - return null; - } - - public Method getSetMethod(String name) { - return (Method) _setMethods.get(name); - } - - public String getObjectName() { - return _objName; - } - } - - private Map _typedefs = new HashMap(); - - private Map _macrodefs = new HashMap(); - - // stack in which the top is current configured object descriptor - private Stack _objectStack = new Stack(); - - private static final List TRUE_VALUES = Arrays.asList(new String[] {"true", "yes", "on"}); - - public void typeDef(String name, String className) throws ClassNotFoundException { - typeDef(name, Class.forName(className)); - } - - public void typeDef(String name, Class clazz) { - _typedefs.put(name, clazz); - } - - public void setRoot(Object root) { - if (root == null) { - throw new NullPointerException(); - } - _objectStack.clear(); - setCurrent(root, null); - } - - public void clear() { - _objectStack.clear(); - } - - private void setCurrent(Object object, String name) { - _objectStack.push(new ObjectDescriptor(object, name)); - } - - public Object startCreateChild(String name) { - if (_objectStack.isEmpty()) { - throw new IllegalStateException("set root before creating child"); - } - ObjectDescriptor parentOD = (ObjectDescriptor) _objectStack.peek(); - Object parent = parentOD.getObject(); - if (parent instanceof MacroDef) { - if (!"attribute".equals(name) && !"element".equals(name)) { - MacroRecord record = ((MacroDef) parent).recordCreateChild(name); - setCurrent(record, name); - return record; - } - } - if (parent instanceof Macro) { - MacroRecord record = ((Macro) parent).recordCreateChild(name); - setCurrent(record, name); - return record; - } - if (parent instanceof MacroRecord) { - MacroRecord record = ((MacroRecord) parent).recordChild(name); - setCurrent(record, name); - return record; - } - Object child = null; - MacroDef macrodef = (MacroDef) _macrodefs.get(name); - if (macrodef != null) { - Macro macro = macrodef.createMacro(); - setCurrent(macro, name); - return macro; - } - Class childClass = (Class) _typedefs.get(name); - Method addChild = null; - try { - if (childClass != null) { - return addChild(parentOD, childClass, name, null); - } else { - addChild = parentOD.getCreateMethod(name); - if (addChild != null) { - child = addChild.invoke(parent, new Object[0]); - setCurrent(child, name); - return child; - } - addChild = parentOD.getAddMethod(name); - if (addChild != null) { - childClass = addChild.getParameterTypes()[0]; - child = childClass.newInstance(); - addChild.invoke(parent, new Object[] {child}); - setCurrent(child, name); - return child; - } - addChild = parentOD.getAddConfiguredMethod(name); - if (addChild != null) { - childClass = addChild.getParameterTypes()[0]; - child = childClass.newInstance(); - setCurrent(child, name); - return child; - } - } - } catch (InstantiationException ex) { - throw new IllegalArgumentException("no default constructor on " + childClass - + " for adding " + name + " on " + parent.getClass()); - } catch (Exception ex) { - IllegalArgumentException iae = new IllegalArgumentException("bad method found for " - + name + " on " + parent.getClass()); - iae.initCause(ex); - throw iae; - } - throw new IllegalArgumentException("no appropriate method found for adding " + name - + " on " + parent.getClass()); - } - - public void addChild(String name, Object child) { - if (_objectStack.isEmpty()) { - throw new IllegalStateException("set root before creating child"); - } - ObjectDescriptor parentOD = (ObjectDescriptor) _objectStack.peek(); - try { - addChild(parentOD, child.getClass(), name, child); - } catch (InstantiationException ex) { - throw new IllegalArgumentException("no default constructor on " + child.getClass() - + " for adding " + name + " on " + parentOD.getObject().getClass()); - } catch (Exception ex) { - IllegalArgumentException iae = new IllegalArgumentException("bad method found for " - + name + " on " + parentOD.getObject().getClass()); - iae.initCause(ex); - throw iae; - } - } - - private Object addChild(ObjectDescriptor parentOD, Class childClass, String name, Object child) - throws InstantiationException, IllegalAccessException, InvocationTargetException { - Object parent = parentOD.getObject(); - Method addChild; - addChild = parentOD.getAddMethod(childClass); - if (addChild != null) { - if (child == null) { - child = childClass.newInstance(); - } - addChild.invoke(parent, new Object[] {child}); - setCurrent(child, name); - return child; - } - addChild = parentOD.getAddConfiguredMethod(childClass); - if (addChild != null) { - if (child == null) { - child = childClass.newInstance(); - } - setCurrent(child, name); - return child; - } - throw new IllegalArgumentException("no appropriate method found for adding " + name - + " on " + parent.getClass()); - } - - public boolean isTopLevelMacroRecord() { - if (_objectStack.isEmpty()) { - return false; - } - ObjectDescriptor od = (ObjectDescriptor) _objectStack.peek(); - return (od.getObject() instanceof MacroDef); - } - - public void setAttribute(String attributeName, String value) { - if (_objectStack.isEmpty()) { - throw new IllegalStateException("set root before setting attribute"); - } - ObjectDescriptor od = (ObjectDescriptor) _objectStack.peek(); - if (od.getObject() instanceof Macro) { - ((Macro) od.getObject()).defineAttribute(attributeName, value); - return; - } - if (od.getObject() instanceof MacroRecord) { - ((MacroRecord) od.getObject()).recordAttribute(attributeName, value); - return; - } - Method m = od.getSetMethod(attributeName); - if (m == null) { - throw new IllegalArgumentException("no set method found for " + attributeName + " on " - + od.getObject().getClass()); - } - Object convertedValue = null; - Class paramClass = m.getParameterTypes()[0]; - try { - if (paramClass.equals(String.class)) { - convertedValue = value; - } else if (paramClass.equals(Boolean.class) || paramClass.equals(boolean.class)) { - convertedValue = Boolean.valueOf(TRUE_VALUES.contains(value)); - } else if (paramClass.equals(Character.class) || paramClass.equals(char.class)) { - convertedValue = new Character(value.length() > 0 ? value.charAt(0) : ' '); - } else if (paramClass.equals(Short.class) || paramClass.equals(short.class)) { - convertedValue = Short.valueOf(value); - } else if (paramClass.equals(Integer.class) || paramClass.equals(int.class)) { - convertedValue = Integer.valueOf(value); - } else if (paramClass.equals(Long.class) || paramClass.equals(long.class)) { - convertedValue = Long.valueOf(value); - } else if (paramClass.equals(Class.class)) { - convertedValue = Class.forName(value); - } else { - convertedValue = paramClass.getConstructor(new Class[] {String.class}).newInstance( - new Object[] {value}); - } - } catch (Exception ex) { - IllegalArgumentException iae = new IllegalArgumentException("impossible to convert " - + value + " to " + paramClass + " for setting " + attributeName + " on " - + od.getObject().getClass()); - iae.initCause(ex); - throw iae; - } - try { - m.invoke(od.getObject(), new Object[] {convertedValue}); - } catch (Exception ex) { - IllegalArgumentException iae = new IllegalArgumentException("impossible to set " - + attributeName + " to " + convertedValue + " on " + od.getObject().getClass()); - iae.initCause(ex); - throw iae; - } - } - - public void addText(String text) { - if (_objectStack.isEmpty()) { - throw new IllegalStateException("set root before adding text"); - } - ObjectDescriptor od = (ObjectDescriptor) _objectStack.peek(); - try { - od.getObject().getClass().getMethod("addText", new Class[] {String.class}).invoke( - od.getObject(), new Object[] {text}); - } catch (Exception ex) { - IllegalArgumentException iae = new IllegalArgumentException( - "impossible to add text on " + od.getObject().getClass()); - iae.initCause(ex); - throw iae; - } - } - - /** - * @return the finished child - */ - public Object endCreateChild() { - if (_objectStack.isEmpty()) { - throw new IllegalStateException("set root before ending child"); - } - ObjectDescriptor od = (ObjectDescriptor) _objectStack.pop(); - if (_objectStack.isEmpty()) { - _objectStack.push(od); // back to previous state - throw new IllegalStateException("cannot end root"); - } - if (od.getObject() instanceof Macro) { - return ((Macro) od.getObject()).play(this); - } - ObjectDescriptor parentOD = (ObjectDescriptor) _objectStack.peek(); - String name = od.getObjectName(); - Class childClass = (Class) _typedefs.get(name); - Method m = null; - if (childClass != null) { - m = parentOD.getAddConfiguredMethod(childClass); - } else { - m = parentOD.getAddConfiguredMethod(name); - } - try { - if (m != null) { - m.invoke(parentOD.getObject(), new Object[] {od.getObject()}); - } - return od.getObject(); - } catch (Exception ex) { - IllegalArgumentException iae = new IllegalArgumentException( - "impossible to add configured child for " + name + " on " - + parentOD.getObject().getClass()); - iae.initCause(ex); - throw iae; - } - } - - public Object getCurrent() { - return _objectStack.isEmpty() ? null : ((ObjectDescriptor) _objectStack.peek()).getObject(); - } - - public int getDepth() { - return _objectStack.size(); - } - - public MacroDef startMacroDef(String macroName) { - MacroDef macroDef = new MacroDef(macroName); - setCurrent(macroDef, macroName); - return macroDef; - } - - public void addMacroAttribute(String attName, String attDefaultValue) { - ((MacroDef) getCurrent()).addAttribute(attName, attDefaultValue); - } - - public void addMacroElement(String elementName, boolean optional) { - ((MacroDef) getCurrent()).addElement(elementName, optional); - } - - public void endMacroDef() { - addConfiguredMacrodef(((MacroDef) getCurrent())); - _objectStack.pop(); - } - - public void addConfiguredMacrodef(MacroDef macrodef) { - _macrodefs.put(macrodef.getName(), macrodef); - } - - public Class getTypeDef(String name) { - return (Class) _typedefs.get(name); - } -} +/* + * 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.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import org.apache.ivy.core.IvyPatternHelper; + +/** + * Ant 1.6.1 like Configurator This configurator is used to configure elements (initialised with + * setRoot) using the behaviour defined by ant for its tasks. Example (based on Ant Example) : Configurator + * conf = new Configurator(); conf.typeDef("buildpath", "Sample$BuildPath"); + * conf.typeDef("xinterface", "Sample$XInterface"); Sample.MyFileSelector mfs = new + * Sample.MyFileSelector(); conf.setRoot(mfs); conf.startCreateChild("buildpath"); + * conf.setAttribute("path", "."); conf.setAttribute("url", "abc"); + * conf.startCreateChild("xinterface"); conf.setAttribute("count", "4"); conf.endCreateChild(); // + * xinterface conf.endCreateChild(); // buildpath + */ +public class Configurator { + public static class Macro { + private MacroDef _macrodef; + + private Map _attValues = new HashMap(); + + private Map _macroRecords = new HashMap(); + + public Macro(MacroDef def) { + _macrodef = def; + } + + public void defineAttribute(String attributeName, String value) { + if (_macrodef.getAttribute(attributeName) == null) { + throw new IllegalArgumentException("undeclared attribute " + attributeName + + " on macro " + _macrodef.getName()); + } + _attValues.put(attributeName, value); + } + + public MacroRecord recordCreateChild(String name) { + MacroRecord macroRecord = new MacroRecord(name); + List records = (List) _macroRecords.get(name); + if (records == null) { + records = new ArrayList(); + _macroRecords.put(name, records); + } + records.add(macroRecord); + return macroRecord; + } + + public Object play(Configurator conf) { + return _macrodef.play(conf, _attValues, _macroRecords); + } + + } + + public static class Attribute { + private String _name; + + private String _default; + + public String getDefault() { + return _default; + } + + public void setDefault(String default1) { + _default = default1; + } + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + } + + public static class Element { + private String _name; + + private boolean _optional = false; + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public boolean isOptional() { + return _optional; + } + + public void setOptional(boolean optional) { + _optional = optional; + } + } + + public static class MacroRecord { + private String _name; + + private Map _attributes = new LinkedHashMap(); + + private List _children = new ArrayList(); + + public MacroRecord(String name) { + _name = name; + } + + public String getName() { + return _name; + } + + public void recordAttribute(String name, String value) { + _attributes.put(name, value); + } + + public MacroRecord recordChild(String name) { + MacroRecord child = new MacroRecord(name); + _children.add(child); + return child; + } + + public Map getAttributes() { + return _attributes; + } + + public List getChildren() { + return _children; + } + } + + public static class MacroDef { + private String _name; + + private Map _attributes = new HashMap(); + + private Map _elements = new HashMap(); + + private MacroRecord _macroRecord; + + public MacroDef(String macroName) { + _name = macroName; + } + + public Attribute getAttribute(String attributeName) { + return (Attribute) _attributes.get(attributeName); + } + + public Object play(Configurator conf, Map attValues, Map macroRecords) { + for (Iterator iter = _attributes.values().iterator(); iter.hasNext();) { + Attribute att = (Attribute) iter.next(); + String val = (String) attValues.get(att.getName()); + if (val == null) { + if (att.getDefault() == null) { + throw new IllegalArgumentException("attribute " + att.getName() + + " is required in " + getName()); + } else { + attValues.put(att.getName(), att.getDefault()); + } + } + } + return play(conf, _macroRecord, attValues, macroRecords); + } + + private Object play(Configurator conf, MacroRecord macroRecord, Map attValues, + Map childrenRecords) { + conf.startCreateChild(macroRecord.getName()); + Map attributes = macroRecord.getAttributes(); + for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) { + String attName = (String) iter.next(); + String attValue = replaceParam((String) attributes.get(attName), attValues); + conf.setAttribute(attName, attValue); + } + for (Iterator iter = macroRecord.getChildren().iterator(); iter.hasNext();) { + MacroRecord child = (MacroRecord) iter.next(); + Element elt = (Element) _elements.get(child.getName()); + if (elt != null) { + List elements = (List) childrenRecords.get(child.getName()); + if (elements != null) { + for (Iterator iterator = elements.iterator(); iterator.hasNext();) { + MacroRecord element = (MacroRecord) iterator.next(); + for (Iterator it2 = element.getChildren().iterator(); it2.hasNext();) { + MacroRecord r = (MacroRecord) it2.next(); + play(conf, r, attValues, Collections.EMPTY_MAP); + } + } + } else if (!elt.isOptional()) { + throw new IllegalArgumentException( + "non optional element is not specified: " + elt.getName() + + " in macro " + getName()); + } + continue; + } + play(conf, child, attValues, childrenRecords); + } + return conf.endCreateChild(); + } + + private String replaceParam(String string, Map attValues) { + return IvyPatternHelper.substituteParams(string, attValues); + } + + public String getName() { + return _name; + } + + public void addConfiguredAttribute(Attribute att) { + _attributes.put(att.getName(), att); + } + + public void addConfiguredElement(Element elt) { + _elements.put(elt.getName(), elt); + } + + public Macro createMacro() { + return new Macro(this); + } + + public void addAttribute(String attName, String attDefaultValue) { + Attribute att = new Attribute(); + att.setName(attName); + att.setDefault(attDefaultValue); + addConfiguredAttribute(att); + } + + public void addElement(String elementName, boolean optional) { + Element elt = new Element(); + elt.setName(elementName); + elt.setOptional(optional); + addConfiguredElement(elt); + } + + public MacroRecord recordCreateChild(String name) { + _macroRecord = new MacroRecord(name); + return _macroRecord; + } + } + + private static class ObjectDescriptor { + private Object _obj; + + private String _objName; + + private Map _createMethods = new HashMap(); + + private Map _addMethods = new HashMap(); + + private Map _addConfiguredMethods = new HashMap(); + + private Map _setMethods = new HashMap(); + + private Map _typeAddMethods = new HashMap(); + + private Map _typeAddConfiguredMethods = new HashMap(); + + public ObjectDescriptor(Object object, String objName) { + _obj = object; + _objName = objName; + Method[] methods = object.getClass().getMethods(); + for (int i = 0; i < methods.length; i++) { + Method m = methods[i]; + if (m.getName().startsWith("create") && m.getParameterTypes().length == 0 + && !Void.TYPE.equals(m.getReturnType())) { + String name = StringUtils + .uncapitalize(m.getName().substring("create".length())); + if (name.length() == 0) { + continue; + } + addCreateMethod(name, m); + } else if (m.getName().startsWith("addConfigured") + && m.getParameterTypes().length == 1 && Void.TYPE.equals(m.getReturnType())) { + String name = StringUtils.uncapitalize(m.getName().substring( + "addConfigured".length())); + if (name.length() == 0) { + addAddConfiguredMethod(m); + } + addAddConfiguredMethod(name, m); + } else if (m.getName().startsWith("add") + && !m.getName().startsWith("addConfigured") + && m.getParameterTypes().length == 1 && Void.TYPE.equals(m.getReturnType())) { + String name = StringUtils.uncapitalize(m.getName().substring("add".length())); + if (name.length() == 0) { + addAddMethod(m); + } + addAddMethod(name, m); + } else if (m.getName().startsWith("set") && m.getParameterTypes().length == 1 + && Void.TYPE.equals(m.getReturnType())) { + String name = StringUtils.uncapitalize(m.getName().substring("set".length())); + if (name.length() == 0) { + continue; + } + addSetMethod(name, m); + } + } + } + + public void addCreateMethod(String name, Method m) { + _createMethods.put(name, m); + } + + public void addAddMethod(String name, Method m) { + _addMethods.put(name, m); + } + + public void addAddConfiguredMethod(String name, Method m) { + _addConfiguredMethods.put(name, m); + } + + private void addAddMethod(Method m) { + _typeAddMethods.put(m.getParameterTypes()[0], m); + } + + private void addAddConfiguredMethod(Method m) { + _typeAddConfiguredMethods.put(m.getParameterTypes()[0], m); + } + + public void addSetMethod(String name, Method m) { + _setMethods.put(name, m); + } + + public Object getObject() { + return _obj; + } + + public Method getCreateMethod(String name) { + return (Method) _createMethods.get(name); + } + + public Method getAddMethod(String name) { + return (Method) _addMethods.get(name); + } + + public Method getAddConfiguredMethod(String name) { + return (Method) _addConfiguredMethods.get(name); + } + + public Method getAddMethod(Class type) { + return getTypeMatchingMethod(type, _typeAddMethods); + } + + public Method getAddConfiguredMethod(Class type) { + return getTypeMatchingMethod(type, _typeAddConfiguredMethods); + } + + private Method getTypeMatchingMethod(Class type, Map typeMethods) { + Method m = (Method) typeMethods.get(type); + if (m != null) { + return m; + } + for (Iterator iter = typeMethods.keySet().iterator(); iter.hasNext();) { + Class clss = (Class) iter.next(); + if (clss.isAssignableFrom(type)) { + return (Method) typeMethods.get(clss); + } + } + return null; + } + + public Method getSetMethod(String name) { + return (Method) _setMethods.get(name); + } + + public String getObjectName() { + return _objName; + } + } + + private Map _typedefs = new HashMap(); + + private Map _macrodefs = new HashMap(); + + // stack in which the top is current configured object descriptor + private Stack _objectStack = new Stack(); + + private static final List TRUE_VALUES = Arrays.asList(new String[] {"true", "yes", "on"}); + + public void typeDef(String name, String className) throws ClassNotFoundException { + typeDef(name, Class.forName(className)); + } + + public void typeDef(String name, Class clazz) { + _typedefs.put(name, clazz); + } + + public void setRoot(Object root) { + if (root == null) { + throw new NullPointerException(); + } + _objectStack.clear(); + setCurrent(root, null); + } + + public void clear() { + _objectStack.clear(); + } + + private void setCurrent(Object object, String name) { + _objectStack.push(new ObjectDescriptor(object, name)); + } + + public Object startCreateChild(String name) { + if (_objectStack.isEmpty()) { + throw new IllegalStateException("set root before creating child"); + } + ObjectDescriptor parentOD = (ObjectDescriptor) _objectStack.peek(); + Object parent = parentOD.getObject(); + if (parent instanceof MacroDef) { + if (!"attribute".equals(name) && !"element".equals(name)) { + MacroRecord record = ((MacroDef) parent).recordCreateChild(name); + setCurrent(record, name); + return record; + } + } + if (parent instanceof Macro) { + MacroRecord record = ((Macro) parent).recordCreateChild(name); + setCurrent(record, name); + return record; + } + if (parent instanceof MacroRecord) { + MacroRecord record = ((MacroRecord) parent).recordChild(name); + setCurrent(record, name); + return record; + } + Object child = null; + MacroDef macrodef = (MacroDef) _macrodefs.get(name); + if (macrodef != null) { + Macro macro = macrodef.createMacro(); + setCurrent(macro, name); + return macro; + } + Class childClass = (Class) _typedefs.get(name); + Method addChild = null; + try { + if (childClass != null) { + return addChild(parentOD, childClass, name, null); + } else { + addChild = parentOD.getCreateMethod(name); + if (addChild != null) { + child = addChild.invoke(parent, new Object[0]); + setCurrent(child, name); + return child; + } + addChild = parentOD.getAddMethod(name); + if (addChild != null) { + childClass = addChild.getParameterTypes()[0]; + child = childClass.newInstance(); + addChild.invoke(parent, new Object[] {child}); + setCurrent(child, name); + return child; + } + addChild = parentOD.getAddConfiguredMethod(name); + if (addChild != null) { + childClass = addChild.getParameterTypes()[0]; + child = childClass.newInstance(); + setCurrent(child, name); + return child; + } + } + } catch (InstantiationException ex) { + throw new IllegalArgumentException("no default constructor on " + childClass + + " for adding " + name + " on " + parent.getClass()); + } catch (Exception ex) { + IllegalArgumentException iae = new IllegalArgumentException("bad method found for " + + name + " on " + parent.getClass()); + iae.initCause(ex); + throw iae; + } + throw new IllegalArgumentException("no appropriate method found for adding " + name + + " on " + parent.getClass()); + } + + public void addChild(String name, Object child) { + if (_objectStack.isEmpty()) { + throw new IllegalStateException("set root before creating child"); + } + ObjectDescriptor parentOD = (ObjectDescriptor) _objectStack.peek(); + try { + addChild(parentOD, child.getClass(), name, child); + } catch (InstantiationException ex) { + throw new IllegalArgumentException("no default constructor on " + child.getClass() + + " for adding " + name + " on " + parentOD.getObject().getClass()); + } catch (Exception ex) { + IllegalArgumentException iae = new IllegalArgumentException("bad method found for " + + name + " on " + parentOD.getObject().getClass()); + iae.initCause(ex); + throw iae; + } + } + + private Object addChild(ObjectDescriptor parentOD, Class childClass, String name, Object child) + throws InstantiationException, IllegalAccessException, InvocationTargetException { + Object parent = parentOD.getObject(); + Method addChild; + addChild = parentOD.getAddMethod(childClass); + if (addChild != null) { + if (child == null) { + child = childClass.newInstance(); + } + addChild.invoke(parent, new Object[] {child}); + setCurrent(child, name); + return child; + } + addChild = parentOD.getAddConfiguredMethod(childClass); + if (addChild != null) { + if (child == null) { + child = childClass.newInstance(); + } + setCurrent(child, name); + return child; + } + throw new IllegalArgumentException("no appropriate method found for adding " + name + + " on " + parent.getClass()); + } + + public boolean isTopLevelMacroRecord() { + if (_objectStack.isEmpty()) { + return false; + } + ObjectDescriptor od = (ObjectDescriptor) _objectStack.peek(); + return (od.getObject() instanceof MacroDef); + } + + public void setAttribute(String attributeName, String value) { + if (_objectStack.isEmpty()) { + throw new IllegalStateException("set root before setting attribute"); + } + ObjectDescriptor od = (ObjectDescriptor) _objectStack.peek(); + if (od.getObject() instanceof Macro) { + ((Macro) od.getObject()).defineAttribute(attributeName, value); + return; + } + if (od.getObject() instanceof MacroRecord) { + ((MacroRecord) od.getObject()).recordAttribute(attributeName, value); + return; + } + Method m = od.getSetMethod(attributeName); + if (m == null) { + throw new IllegalArgumentException("no set method found for " + attributeName + " on " + + od.getObject().getClass()); + } + Object convertedValue = null; + Class paramClass = m.getParameterTypes()[0]; + try { + if (paramClass.equals(String.class)) { + convertedValue = value; + } else if (paramClass.equals(Boolean.class) || paramClass.equals(boolean.class)) { + convertedValue = Boolean.valueOf(TRUE_VALUES.contains(value)); + } else if (paramClass.equals(Character.class) || paramClass.equals(char.class)) { + convertedValue = new Character(value.length() > 0 ? value.charAt(0) : ' '); + } else if (paramClass.equals(Short.class) || paramClass.equals(short.class)) { + convertedValue = Short.valueOf(value); + } else if (paramClass.equals(Integer.class) || paramClass.equals(int.class)) { + convertedValue = Integer.valueOf(value); + } else if (paramClass.equals(Long.class) || paramClass.equals(long.class)) { + convertedValue = Long.valueOf(value); + } else if (paramClass.equals(Class.class)) { + convertedValue = Class.forName(value); + } else { + convertedValue = paramClass.getConstructor(new Class[] {String.class}).newInstance( + new Object[] {value}); + } + } catch (Exception ex) { + IllegalArgumentException iae = new IllegalArgumentException("impossible to convert " + + value + " to " + paramClass + " for setting " + attributeName + " on " + + od.getObject().getClass()); + iae.initCause(ex); + throw iae; + } + try { + m.invoke(od.getObject(), new Object[] {convertedValue}); + } catch (Exception ex) { + IllegalArgumentException iae = new IllegalArgumentException("impossible to set " + + attributeName + " to " + convertedValue + " on " + od.getObject().getClass()); + iae.initCause(ex); + throw iae; + } + } + + public void addText(String text) { + if (_objectStack.isEmpty()) { + throw new IllegalStateException("set root before adding text"); + } + ObjectDescriptor od = (ObjectDescriptor) _objectStack.peek(); + try { + od.getObject().getClass().getMethod("addText", new Class[] {String.class}).invoke( + od.getObject(), new Object[] {text}); + } catch (Exception ex) { + IllegalArgumentException iae = new IllegalArgumentException( + "impossible to add text on " + od.getObject().getClass()); + iae.initCause(ex); + throw iae; + } + } + + /** + * @return the finished child + */ + public Object endCreateChild() { + if (_objectStack.isEmpty()) { + throw new IllegalStateException("set root before ending child"); + } + ObjectDescriptor od = (ObjectDescriptor) _objectStack.pop(); + if (_objectStack.isEmpty()) { + _objectStack.push(od); // back to previous state + throw new IllegalStateException("cannot end root"); + } + if (od.getObject() instanceof Macro) { + return ((Macro) od.getObject()).play(this); + } + ObjectDescriptor parentOD = (ObjectDescriptor) _objectStack.peek(); + String name = od.getObjectName(); + Class childClass = (Class) _typedefs.get(name); + Method m = null; + if (childClass != null) { + m = parentOD.getAddConfiguredMethod(childClass); + } else { + m = parentOD.getAddConfiguredMethod(name); + } + try { + if (m != null) { + m.invoke(parentOD.getObject(), new Object[] {od.getObject()}); + } + return od.getObject(); + } catch (Exception ex) { + IllegalArgumentException iae = new IllegalArgumentException( + "impossible to add configured child for " + name + " on " + + parentOD.getObject().getClass()); + iae.initCause(ex); + throw iae; + } + } + + public Object getCurrent() { + return _objectStack.isEmpty() ? null : ((ObjectDescriptor) _objectStack.peek()).getObject(); + } + + public int getDepth() { + return _objectStack.size(); + } + + public MacroDef startMacroDef(String macroName) { + MacroDef macroDef = new MacroDef(macroName); + setCurrent(macroDef, macroName); + return macroDef; + } + + public void addMacroAttribute(String attName, String attDefaultValue) { + ((MacroDef) getCurrent()).addAttribute(attName, attDefaultValue); + } + + public void addMacroElement(String elementName, boolean optional) { + ((MacroDef) getCurrent()).addElement(elementName, optional); + } + + public void endMacroDef() { + addConfiguredMacrodef(((MacroDef) getCurrent())); + _objectStack.pop(); + } + + public void addConfiguredMacrodef(MacroDef macrodef) { + _macrodefs.put(macrodef.getName(), macrodef); + } + + public Class getTypeDef(String name) { + return (Class) _typedefs.get(name); + } +} diff --git a/src/java/org/apache/ivy/util/CopyProgressEvent.java b/src/java/org/apache/ivy/util/CopyProgressEvent.java index 41fbd6c6..05e91525 100644 --- a/src/java/org/apache/ivy/util/CopyProgressEvent.java +++ b/src/java/org/apache/ivy/util/CopyProgressEvent.java @@ -1,60 +1,60 @@ -/* - * 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.util; - -/** - * Event reporting a stream copy progression - */ -public class CopyProgressEvent { - private long _totalReadBytes; - - private byte[] _buffer; - - private int _readBytes; - - public CopyProgressEvent() { - } - - public CopyProgressEvent(byte[] buffer, int read, long total) { - update(buffer, read, total); - } - - public CopyProgressEvent(byte[] buffer, long total) { - update(buffer, 0, total); - } - - protected CopyProgressEvent update(byte[] buffer, int read, long total) { - _buffer = buffer; - _readBytes = read; - _totalReadBytes = total; - return this; - } - - public long getTotalReadBytes() { - return _totalReadBytes; - } - - public byte[] getBuffer() { - return _buffer; - } - - public int getReadBytes() { - return _readBytes; - } - -} +/* + * 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.util; + +/** + * Event reporting a stream copy progression + */ +public class CopyProgressEvent { + private long _totalReadBytes; + + private byte[] _buffer; + + private int _readBytes; + + public CopyProgressEvent() { + } + + public CopyProgressEvent(byte[] buffer, int read, long total) { + update(buffer, read, total); + } + + public CopyProgressEvent(byte[] buffer, long total) { + update(buffer, 0, total); + } + + protected CopyProgressEvent update(byte[] buffer, int read, long total) { + _buffer = buffer; + _readBytes = read; + _totalReadBytes = total; + return this; + } + + public long getTotalReadBytes() { + return _totalReadBytes; + } + + public byte[] getBuffer() { + return _buffer; + } + + public int getReadBytes() { + return _readBytes; + } + +} diff --git a/src/java/org/apache/ivy/util/CopyProgressListener.java b/src/java/org/apache/ivy/util/CopyProgressListener.java index 04cf2ed8..2dbaa2ee 100644 --- a/src/java/org/apache/ivy/util/CopyProgressListener.java +++ b/src/java/org/apache/ivy/util/CopyProgressListener.java @@ -1,29 +1,29 @@ -/* - * 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.util; - -/** - * Listen to copy progression - */ -public interface CopyProgressListener { - void start(CopyProgressEvent evt); - - void progress(CopyProgressEvent evt); - - void end(CopyProgressEvent evt); -} +/* + * 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.util; + +/** + * Listen to copy progression + */ +public interface CopyProgressListener { + void start(CopyProgressEvent evt); + + void progress(CopyProgressEvent evt); + + void end(CopyProgressEvent evt); +} diff --git a/src/java/org/apache/ivy/util/Credentials.java b/src/java/org/apache/ivy/util/Credentials.java index 0cfbd610..0757b0f5 100644 --- a/src/java/org/apache/ivy/util/Credentials.java +++ b/src/java/org/apache/ivy/util/Credentials.java @@ -1,102 +1,102 @@ -/* - * 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.util; - -/** - * - */ -public class Credentials { - private String _realm; - - private String _host; - - private String _userName; - - private String _passwd; - - public Credentials(String realm, String host, String userName, String passwd) { - _realm = realm; - _host = host; - _userName = userName; - _passwd = passwd; - } - - public String getHost() { - return _host; - } - - public String getPasswd() { - return _passwd; - } - - public String getRealm() { - return _realm; - } - - public String getUserName() { - return _userName; - } - - public static String buildKey(String realm, String host) { - if (realm == null || "".equals(realm.trim())) { - return host; - } else { - return realm + "@" + host; - } - } - - /** - * Return a string that can be used for debug purpose. It contains only stars for each password - * character. - */ - public String toString() { - return getKey() + " " + getUserName() + "/" + getPasswdAsStars(); - } - - private String getPasswdAsStars() { - if (_passwd == null) { - return null; - } - StringBuffer sb = new StringBuffer(); - for (int i = _passwd.length(); i > 0; i--) { - sb.append('*'); - } - return sb.toString(); - } - - public boolean equals(Object o) { - if (o == null) { - return false; - } - - if (o instanceof Credentials) { - Credentials c = (Credentials) o; - return getKey().equals(c.getKey()); - } - - return false; - } - - public int hashCode() { - return getKey().hashCode(); - } - - public String getKey() { - return buildKey(_realm, _host); - } -} +/* + * 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.util; + +/** + * + */ +public class Credentials { + private String _realm; + + private String _host; + + private String _userName; + + private String _passwd; + + public Credentials(String realm, String host, String userName, String passwd) { + _realm = realm; + _host = host; + _userName = userName; + _passwd = passwd; + } + + public String getHost() { + return _host; + } + + public String getPasswd() { + return _passwd; + } + + public String getRealm() { + return _realm; + } + + public String getUserName() { + return _userName; + } + + public static String buildKey(String realm, String host) { + if (realm == null || "".equals(realm.trim())) { + return host; + } else { + return realm + "@" + host; + } + } + + /** + * Return a string that can be used for debug purpose. It contains only stars for each password + * character. + */ + public String toString() { + return getKey() + " " + getUserName() + "/" + getPasswdAsStars(); + } + + private String getPasswdAsStars() { + if (_passwd == null) { + return null; + } + StringBuffer sb = new StringBuffer(); + for (int i = _passwd.length(); i > 0; i--) { + sb.append('*'); + } + return sb.toString(); + } + + public boolean equals(Object o) { + if (o == null) { + return false; + } + + if (o instanceof Credentials) { + Credentials c = (Credentials) o; + return getKey().equals(c.getKey()); + } + + return false; + } + + public int hashCode() { + return getKey().hashCode(); + } + + public String getKey() { + return buildKey(_realm, _host); + } +} diff --git a/src/java/org/apache/ivy/util/CredentialsUtil.java b/src/java/org/apache/ivy/util/CredentialsUtil.java index c45e1cb3..0efab81f 100644 --- a/src/java/org/apache/ivy/util/CredentialsUtil.java +++ b/src/java/org/apache/ivy/util/CredentialsUtil.java @@ -1,161 +1,161 @@ -/* - * 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.util; - -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; - -import javax.swing.ImageIcon; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JTextField; - -import org.apache.ivy.Ivy; - -public class CredentialsUtil { - - private static final class CredentialPanel extends JPanel { - JTextField userNameField = new JTextField(20); - - JTextField passwordField = new JPasswordField(20); - - JCheckBox rememberDataCB = new JCheckBox("remember my information"); - - CredentialPanel(Credentials credentials, File passfile) { - GridBagLayout layout = new GridBagLayout(); - setLayout(layout); - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(2, 2, 2, 2); - - c.gridx = 1; - c.gridheight = 1; - c.gridwidth = 2; - String prompt = credentials.getRealm() != null ? "Enter username and password for \"" - + credentials.getRealm() + "\" at " + credentials.getHost() - : "Enter username and password for " + credentials.getHost(); - add(new JLabel(prompt), c); - - c.gridy = 1; - c.gridwidth = 1; - - add(new JLabel("username: "), c); - c.gridx = 2; - add(userNameField, c); - c.gridx = 1; - c.gridy++; - - if (credentials.getUserName() != null) { - userNameField.setText(credentials.getUserName()); - } - - if (credentials.getPasswd() == null) { - add(new JLabel("passwd: "), c); - c.gridx = 2; - add(passwordField, c); - c.gridx = 1; - c.gridy++; - } else { - passwordField.setText(credentials.getPasswd()); - } - - if (passfile != null) { - c.gridwidth = 2; - add(rememberDataCB, c); - c.gridy++; - } - c.gridwidth = 2; - add(new JLabel(), c); // spacer - - } - } - - public static Credentials promptCredentials(Credentials c, File passfile) { - c = loadPassfile(c, passfile); - if (c.getUserName() != null && c.getPasswd() != null) { - return c; - } - CredentialPanel credentialPanel = new CredentialPanel(c, passfile); - if (JOptionPane.showOptionDialog(null, credentialPanel, c.getHost() + " credentials", - JOptionPane.OK_CANCEL_OPTION, 0, new ImageIcon(Ivy.class.getResource("logo.png")), - null, new Integer(JOptionPane.OK_OPTION)) == JOptionPane.OK_OPTION) { - String username = credentialPanel.userNameField.getText(); - String passwd = credentialPanel.passwordField.getText(); - if (credentialPanel.rememberDataCB.isSelected()) { - Properties props = new EncrytedProperties(); - props.setProperty("username", username); - props.setProperty("passwd", passwd); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(passfile); - props.store(fos, ""); - } catch (Exception e) { - Message.warn("error occured while saving password file " + passfile + ": " + e); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (Exception e) { - } - } - } - } - c = new Credentials(c.getRealm(), c.getHost(), username, passwd); - } - return c; - } - - public static Credentials loadPassfile(Credentials c, File passfile) { - if (passfile != null && passfile.exists()) { - Properties props = new EncrytedProperties(); - FileInputStream fis = null; - try { - fis = new FileInputStream(passfile); - props.load(fis); - String username = c.getUserName(); - String passwd = c.getPasswd(); - if (username == null) { - username = props.getProperty("username"); - } - if (passwd == null) { - passwd = props.getProperty("passwd"); - } - return new Credentials(c.getRealm(), c.getHost(), username, passwd); - } catch (IOException e) { - Message.warn("error occured while loading password file " + passfile + ": " + e); - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - } - } - } - } - return c; - } - -} +/* + * 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.util; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import javax.swing.ImageIcon; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; + +import org.apache.ivy.Ivy; + +public class CredentialsUtil { + + private static final class CredentialPanel extends JPanel { + JTextField userNameField = new JTextField(20); + + JTextField passwordField = new JPasswordField(20); + + JCheckBox rememberDataCB = new JCheckBox("remember my information"); + + CredentialPanel(Credentials credentials, File passfile) { + GridBagLayout layout = new GridBagLayout(); + setLayout(layout); + GridBagConstraints c = new GridBagConstraints(); + c.insets = new Insets(2, 2, 2, 2); + + c.gridx = 1; + c.gridheight = 1; + c.gridwidth = 2; + String prompt = credentials.getRealm() != null ? "Enter username and password for \"" + + credentials.getRealm() + "\" at " + credentials.getHost() + : "Enter username and password for " + credentials.getHost(); + add(new JLabel(prompt), c); + + c.gridy = 1; + c.gridwidth = 1; + + add(new JLabel("username: "), c); + c.gridx = 2; + add(userNameField, c); + c.gridx = 1; + c.gridy++; + + if (credentials.getUserName() != null) { + userNameField.setText(credentials.getUserName()); + } + + if (credentials.getPasswd() == null) { + add(new JLabel("passwd: "), c); + c.gridx = 2; + add(passwordField, c); + c.gridx = 1; + c.gridy++; + } else { + passwordField.setText(credentials.getPasswd()); + } + + if (passfile != null) { + c.gridwidth = 2; + add(rememberDataCB, c); + c.gridy++; + } + c.gridwidth = 2; + add(new JLabel(), c); // spacer + + } + } + + public static Credentials promptCredentials(Credentials c, File passfile) { + c = loadPassfile(c, passfile); + if (c.getUserName() != null && c.getPasswd() != null) { + return c; + } + CredentialPanel credentialPanel = new CredentialPanel(c, passfile); + if (JOptionPane.showOptionDialog(null, credentialPanel, c.getHost() + " credentials", + JOptionPane.OK_CANCEL_OPTION, 0, new ImageIcon(Ivy.class.getResource("logo.png")), + null, new Integer(JOptionPane.OK_OPTION)) == JOptionPane.OK_OPTION) { + String username = credentialPanel.userNameField.getText(); + String passwd = credentialPanel.passwordField.getText(); + if (credentialPanel.rememberDataCB.isSelected()) { + Properties props = new EncrytedProperties(); + props.setProperty("username", username); + props.setProperty("passwd", passwd); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(passfile); + props.store(fos, ""); + } catch (Exception e) { + Message.warn("error occured while saving password file " + passfile + ": " + e); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (Exception e) { + } + } + } + } + c = new Credentials(c.getRealm(), c.getHost(), username, passwd); + } + return c; + } + + public static Credentials loadPassfile(Credentials c, File passfile) { + if (passfile != null && passfile.exists()) { + Properties props = new EncrytedProperties(); + FileInputStream fis = null; + try { + fis = new FileInputStream(passfile); + props.load(fis); + String username = c.getUserName(); + String passwd = c.getPasswd(); + if (username == null) { + username = props.getProperty("username"); + } + if (passwd == null) { + passwd = props.getProperty("passwd"); + } + return new Credentials(c.getRealm(), c.getHost(), username, passwd); + } catch (IOException e) { + Message.warn("error occured while loading password file " + passfile + ": " + e); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + } + } + } + } + return c; + } + +} diff --git a/src/java/org/apache/ivy/util/DefaultMessageImpl.java b/src/java/org/apache/ivy/util/DefaultMessageImpl.java index 703a847e..ae8dcd3c 100644 --- a/src/java/org/apache/ivy/util/DefaultMessageImpl.java +++ b/src/java/org/apache/ivy/util/DefaultMessageImpl.java @@ -1,51 +1,51 @@ -/* - * 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.util; - -public class DefaultMessageImpl implements MessageImpl { - private int _level = Message.MSG_INFO; - - /** - * @param level - */ - public DefaultMessageImpl(int level) { - _level = level; - } - - public void log(String msg, int level) { - if (level <= _level) { - System.out.println(msg); - } - } - - public void rawlog(String msg, int level) { - log(msg, level); - } - - public void progress() { - System.out.print("."); - } - - public void endProgress(String msg) { - System.out.println(msg); - } - - public int getLevel() { - return _level; - } -} +/* + * 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.util; + +public class DefaultMessageImpl implements MessageImpl { + private int _level = Message.MSG_INFO; + + /** + * @param level + */ + public DefaultMessageImpl(int level) { + _level = level; + } + + public void log(String msg, int level) { + if (level <= _level) { + System.out.println(msg); + } + } + + public void rawlog(String msg, int level) { + log(msg, level); + } + + public void progress() { + System.out.print("."); + } + + public void endProgress(String msg) { + System.out.println(msg); + } + + public int getLevel() { + return _level; + } +} diff --git a/src/java/org/apache/ivy/util/EncrytedProperties.java b/src/java/org/apache/ivy/util/EncrytedProperties.java index 7936db4d..8d38fefa 100644 --- a/src/java/org/apache/ivy/util/EncrytedProperties.java +++ b/src/java/org/apache/ivy/util/EncrytedProperties.java @@ -1,65 +1,65 @@ -/* - * 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.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Properties; - -/** - * An implementation of Properties which stores the values encrypted. The use is transparent from - * the user point of view (use as any Properties instance), except that get, put and putAll do not - * handle encryption/decryption. This means that get returns the encrypted value, while put and - * putAll puts given values without encrypting them. It this thus recommended to void using them, - * use setProperty and getProperty instead. - */ -public class EncrytedProperties extends Properties { - - public EncrytedProperties() { - super(); - } - - public synchronized Object setProperty(String key, String value) { - return StringUtils.decrypt((String) super.setProperty(key, StringUtils.encrypt(value))); - } - - public String getProperty(String key) { - return StringUtils.decrypt(super.getProperty(key)); - } - - public String getProperty(String key, String defaultValue) { - return StringUtils.decrypt(super.getProperty(key, StringUtils.encrypt(defaultValue))); - } - - public boolean containsValue(Object value) { - return super.containsValue(StringUtils.encrypt((String) value)); - } - - public synchronized boolean contains(Object value) { - return super.contains(StringUtils.encrypt((String) value)); - } - - public Collection values() { - List ret = new ArrayList(super.values()); - for (int i = 0; i < ret.size(); i++) { - ret.set(i, StringUtils.decrypt((String) ret.get(i))); - } - return ret; - } -} +/* + * 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.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Properties; + +/** + * An implementation of Properties which stores the values encrypted. The use is transparent from + * the user point of view (use as any Properties instance), except that get, put and putAll do not + * handle encryption/decryption. This means that get returns the encrypted value, while put and + * putAll puts given values without encrypting them. It this thus recommended to void using them, + * use setProperty and getProperty instead. + */ +public class EncrytedProperties extends Properties { + + public EncrytedProperties() { + super(); + } + + public synchronized Object setProperty(String key, String value) { + return StringUtils.decrypt((String) super.setProperty(key, StringUtils.encrypt(value))); + } + + public String getProperty(String key) { + return StringUtils.decrypt(super.getProperty(key)); + } + + public String getProperty(String key, String defaultValue) { + return StringUtils.decrypt(super.getProperty(key, StringUtils.encrypt(defaultValue))); + } + + public boolean containsValue(Object value) { + return super.containsValue(StringUtils.encrypt((String) value)); + } + + public synchronized boolean contains(Object value) { + return super.contains(StringUtils.encrypt((String) value)); + } + + public Collection values() { + List ret = new ArrayList(super.values()); + for (int i = 0; i < ret.size(); i++) { + ret.set(i, StringUtils.decrypt((String) ret.get(i))); + } + return ret; + } +} diff --git a/src/java/org/apache/ivy/util/FileUtil.java b/src/java/org/apache/ivy/util/FileUtil.java index e62427ea..e1bf6d81 100644 --- a/src/java/org/apache/ivy/util/FileUtil.java +++ b/src/java/org/apache/ivy/util/FileUtil.java @@ -1,259 +1,259 @@ -/* - * 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.util; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.ivy.util.url.URLHandlerRegistry; - -/** - * - */ -public class FileUtil { - // tried some other values with empty files... seems to be the best one (512 * 1024 is very bad) - // 8 * 1024 is also the size used by ant in its FileUtils... maybe they've done more study about - // it ;-) - private static final int BUFFER_SIZE = 8 * 1024; - - private static final byte[] EMPTY_BUFFER = new byte[0]; - - public static void symlink(File src, File dest, CopyProgressListener l, boolean overwrite) - throws IOException { - try { - if (dest.exists()) { - if (!dest.isFile()) { - throw new IOException("impossible to copy: destination is not a file: " + dest); - } - if (!overwrite) { - Message.verbose(dest + " already exists, nothing done"); - return; - } - } - if (dest.getParentFile() != null) { - dest.getParentFile().mkdirs(); - } - - Runtime runtime = Runtime.getRuntime(); - Message.verbose("executing 'ln -s -f " + src.getAbsolutePath() + " " + dest.getPath() - + "'"); - Process process = runtime.exec(new String[] {"ln", "-s", "-f", src.getAbsolutePath(), - dest.getPath()}); - - if (process.waitFor() != 0) { - InputStream errorStream = process.getErrorStream(); - InputStreamReader isr = new InputStreamReader(errorStream); - BufferedReader br = new BufferedReader(isr); - - StringBuffer error = new StringBuffer(); - String line; - while ((line = br.readLine()) != null) { - error.append(line); - error.append('\n'); - } - - throw new IOException("error symlinking " + src + " to " + dest + ":\n" + error); - } - } catch (IOException x) { - Message.verbose("symlink failed; falling back to copy"); - StringWriter buffer = new StringWriter(); - x.printStackTrace(new PrintWriter(buffer)); - Message.debug(buffer.toString()); - copy(src, dest, l, overwrite); - } catch (InterruptedException x) { - Thread.currentThread().interrupt(); - } - } - - public static boolean copy(File src, File dest, CopyProgressListener l) throws IOException { - return copy(src, dest, l, false); - } - - public static boolean copy(File src, File dest, CopyProgressListener l, boolean overwrite) - throws IOException { - if (dest.exists()) { - if (!dest.isFile()) { - throw new IOException("impossible to copy: destination is not a file: " + dest); - } - if (overwrite) { - if (!dest.canWrite()) { - dest.delete(); - } // if dest is writable, the copy will overwrite it without requiring a delete - } else { - Message.verbose(dest + " already exists, nothing done"); - return false; - } - } - copy(new FileInputStream(src), dest, l); - long srcLen = src.length(); - long destLen = dest.length(); - if (srcLen != destLen) { - dest.delete(); - throw new IOException("size of source file " + src.toString() + "(" + srcLen - + ") differs from size of dest file " + dest.toString() + "(" + destLen - + ") - please retry"); - } - dest.setLastModified(src.lastModified()); - return true; - } - - public static void copy(URL src, File dest, CopyProgressListener l) throws IOException { - URLHandlerRegistry.getDefault().download(src, dest, l); - } - - public static void copy(InputStream src, File dest, CopyProgressListener l) throws IOException { - if (dest.getParentFile() != null) { - dest.getParentFile().mkdirs(); - } - copy(src, new FileOutputStream(dest), l); - } - - public static void copy(InputStream src, OutputStream dest, CopyProgressListener l) - throws IOException { - CopyProgressEvent evt = null; - if (l != null) { - evt = new CopyProgressEvent(); - } - try { - byte buffer[] = new byte[BUFFER_SIZE]; - int c; - long total = 0; - - if (l != null) { - l.start(evt); - } - while ((c = src.read(buffer)) != -1) { - if (Thread.currentThread().isInterrupted()) { - throw new IOException("transfer interrupted"); - } - dest.write(buffer, 0, c); - total += c; - if (l != null) { - l.progress(evt.update(buffer, c, total)); - } - } - - if (l != null) { - evt.update(EMPTY_BUFFER, 0, total); - } - - // close the streams - src.close(); - dest.close(); - } finally { - try { - src.close(); - } catch (IOException ex) { - // ignore - } - try { - dest.close(); - } catch (IOException ex) { - // ignore - } - } - - if (l != null) { - l.end(evt); - } - } - - public static String readEntirely(BufferedReader in) throws IOException { - StringBuffer buf = new StringBuffer(); - - String line = in.readLine(); - while (line != null) { - buf.append(line + "\n"); - line = in.readLine(); - } - in.close(); - return buf.toString(); - } - - public static String concat(String dir, String file) { - return dir + "/" + file; - } - - public static void forceDelete(File f) { - if (f.isDirectory()) { - File[] sub = f.listFiles(); - for (int i = 0; i < sub.length; i++) { - forceDelete(sub[i]); - } - } - f.delete(); - } - - /** - * Returns a list of Files composed of all directories being parent of file and child of root + - * file and root themselves. Example: getPathFiles(new File("test"), new - * File("test/dir1/dir2/file.txt")) => {new File("test/dir1"), new File("test/dir1/dir2"), new - * File("test/dir1/dir2/file.txt") } Note that if root is not an ancester of file, or if root is - * null, all directories from the file system root will be returned. - */ - public static List getPathFiles(File root, File file) { - List ret = new ArrayList(); - while (file != null && !file.getAbsolutePath().equals(root.getAbsolutePath())) { - ret.add(file); - file = file.getParentFile(); - } - if (root != null) { - ret.add(root); - } - Collections.reverse(ret); - return ret; - } - - /** - * Returns a collection of all Files being contained in the given directory, recursively, - * including directories. - * - * @param dir - * @return - */ - public static Collection listAll(File dir) { - return listAll(dir, new ArrayList()); - } - - private static Collection listAll(File file, Collection list) { - if (file.exists()) { - list.add(file); - } - if (file.isDirectory()) { - File[] files = file.listFiles(); - for (int i = 0; i < files.length; i++) { - listAll(files[i], list); - } - } - return list; - } - -} +/* + * 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.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.apache.ivy.util.url.URLHandlerRegistry; + +/** + * + */ +public class FileUtil { + // tried some other values with empty files... seems to be the best one (512 * 1024 is very bad) + // 8 * 1024 is also the size used by ant in its FileUtils... maybe they've done more study about + // it ;-) + private static final int BUFFER_SIZE = 8 * 1024; + + private static final byte[] EMPTY_BUFFER = new byte[0]; + + public static void symlink(File src, File dest, CopyProgressListener l, boolean overwrite) + throws IOException { + try { + if (dest.exists()) { + if (!dest.isFile()) { + throw new IOException("impossible to copy: destination is not a file: " + dest); + } + if (!overwrite) { + Message.verbose(dest + " already exists, nothing done"); + return; + } + } + if (dest.getParentFile() != null) { + dest.getParentFile().mkdirs(); + } + + Runtime runtime = Runtime.getRuntime(); + Message.verbose("executing 'ln -s -f " + src.getAbsolutePath() + " " + dest.getPath() + + "'"); + Process process = runtime.exec(new String[] {"ln", "-s", "-f", src.getAbsolutePath(), + dest.getPath()}); + + if (process.waitFor() != 0) { + InputStream errorStream = process.getErrorStream(); + InputStreamReader isr = new InputStreamReader(errorStream); + BufferedReader br = new BufferedReader(isr); + + StringBuffer error = new StringBuffer(); + String line; + while ((line = br.readLine()) != null) { + error.append(line); + error.append('\n'); + } + + throw new IOException("error symlinking " + src + " to " + dest + ":\n" + error); + } + } catch (IOException x) { + Message.verbose("symlink failed; falling back to copy"); + StringWriter buffer = new StringWriter(); + x.printStackTrace(new PrintWriter(buffer)); + Message.debug(buffer.toString()); + copy(src, dest, l, overwrite); + } catch (InterruptedException x) { + Thread.currentThread().interrupt(); + } + } + + public static boolean copy(File src, File dest, CopyProgressListener l) throws IOException { + return copy(src, dest, l, false); + } + + public static boolean copy(File src, File dest, CopyProgressListener l, boolean overwrite) + throws IOException { + if (dest.exists()) { + if (!dest.isFile()) { + throw new IOException("impossible to copy: destination is not a file: " + dest); + } + if (overwrite) { + if (!dest.canWrite()) { + dest.delete(); + } // if dest is writable, the copy will overwrite it without requiring a delete + } else { + Message.verbose(dest + " already exists, nothing done"); + return false; + } + } + copy(new FileInputStream(src), dest, l); + long srcLen = src.length(); + long destLen = dest.length(); + if (srcLen != destLen) { + dest.delete(); + throw new IOException("size of source file " + src.toString() + "(" + srcLen + + ") differs from size of dest file " + dest.toString() + "(" + destLen + + ") - please retry"); + } + dest.setLastModified(src.lastModified()); + return true; + } + + public static void copy(URL src, File dest, CopyProgressListener l) throws IOException { + URLHandlerRegistry.getDefault().download(src, dest, l); + } + + public static void copy(InputStream src, File dest, CopyProgressListener l) throws IOException { + if (dest.getParentFile() != null) { + dest.getParentFile().mkdirs(); + } + copy(src, new FileOutputStream(dest), l); + } + + public static void copy(InputStream src, OutputStream dest, CopyProgressListener l) + throws IOException { + CopyProgressEvent evt = null; + if (l != null) { + evt = new CopyProgressEvent(); + } + try { + byte buffer[] = new byte[BUFFER_SIZE]; + int c; + long total = 0; + + if (l != null) { + l.start(evt); + } + while ((c = src.read(buffer)) != -1) { + if (Thread.currentThread().isInterrupted()) { + throw new IOException("transfer interrupted"); + } + dest.write(buffer, 0, c); + total += c; + if (l != null) { + l.progress(evt.update(buffer, c, total)); + } + } + + if (l != null) { + evt.update(EMPTY_BUFFER, 0, total); + } + + // close the streams + src.close(); + dest.close(); + } finally { + try { + src.close(); + } catch (IOException ex) { + // ignore + } + try { + dest.close(); + } catch (IOException ex) { + // ignore + } + } + + if (l != null) { + l.end(evt); + } + } + + public static String readEntirely(BufferedReader in) throws IOException { + StringBuffer buf = new StringBuffer(); + + String line = in.readLine(); + while (line != null) { + buf.append(line + "\n"); + line = in.readLine(); + } + in.close(); + return buf.toString(); + } + + public static String concat(String dir, String file) { + return dir + "/" + file; + } + + public static void forceDelete(File f) { + if (f.isDirectory()) { + File[] sub = f.listFiles(); + for (int i = 0; i < sub.length; i++) { + forceDelete(sub[i]); + } + } + f.delete(); + } + + /** + * Returns a list of Files composed of all directories being parent of file and child of root + + * file and root themselves. Example: getPathFiles(new File("test"), new + * File("test/dir1/dir2/file.txt")) => {new File("test/dir1"), new File("test/dir1/dir2"), new + * File("test/dir1/dir2/file.txt") } Note that if root is not an ancester of file, or if root is + * null, all directories from the file system root will be returned. + */ + public static List getPathFiles(File root, File file) { + List ret = new ArrayList(); + while (file != null && !file.getAbsolutePath().equals(root.getAbsolutePath())) { + ret.add(file); + file = file.getParentFile(); + } + if (root != null) { + ret.add(root); + } + Collections.reverse(ret); + return ret; + } + + /** + * Returns a collection of all Files being contained in the given directory, recursively, + * including directories. + * + * @param dir + * @return + */ + public static Collection listAll(File dir) { + return listAll(dir, new ArrayList()); + } + + private static Collection listAll(File file, Collection list) { + if (file.exists()) { + list.add(file); + } + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + listAll(files[i], list); + } + } + return list; + } + +} diff --git a/src/java/org/apache/ivy/util/HostUtil.java b/src/java/org/apache/ivy/util/HostUtil.java index 8ab2f438..3c8e6b00 100644 --- a/src/java/org/apache/ivy/util/HostUtil.java +++ b/src/java/org/apache/ivy/util/HostUtil.java @@ -1,31 +1,31 @@ -/* - * 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.util; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -public class HostUtil { - public static String getLocalHostName() { - try { - return InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - return "localhost"; - } - } -} +/* + * 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.util; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class HostUtil { + public static String getLocalHostName() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + return "localhost"; + } + } +} diff --git a/src/java/org/apache/ivy/util/Message.java b/src/java/org/apache/ivy/util/Message.java index 18ffe1bc..016e3a0e 100644 --- a/src/java/org/apache/ivy/util/Message.java +++ b/src/java/org/apache/ivy/util/Message.java @@ -1,245 +1,245 @@ -/* - * 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.util; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import org.apache.ivy.core.IvyContext; - -/** - * - */ -public class Message { - // messages level copied from ant project, to avoid dependency on ant - /** Message priority of "error". */ - public static final int MSG_ERR = 0; - - /** Message priority of "warning". */ - public static final int MSG_WARN = 1; - - /** Message priority of "information". */ - public static final int MSG_INFO = 2; - - /** Message priority of "verbose". */ - public static final int MSG_VERBOSE = 3; - - /** Message priority of "debug". */ - public static final int MSG_DEBUG = 4; - - private static List _problems = new ArrayList(); - - private static List _warns = new ArrayList(); - - private static List _errors = new ArrayList(); - - private static boolean _showProgress = true; - - private static boolean _showedInfo = false; - - public static void init(MessageImpl impl) { - IvyContext.getContext().setMessageImpl(impl); - showInfo(); - } - - /** - * same as init, but without displaying info - * - * @param impl - */ - public static void setImpl(MessageImpl impl) { - IvyContext.getContext().setMessageImpl(impl); - } - - public static MessageImpl getImpl() { - return IvyContext.getContext().getMessageImpl(); - } - - public static boolean isInitialised() { - return IvyContext.getContext().getMessageImpl() != null; - } - - private static void showInfo() { - if (!_showedInfo) { - Properties props = new Properties(); - URL moduleURL = Message.class.getResource("/module.properties"); - if (moduleURL != null) { - try { - InputStream module = moduleURL.openStream(); - props.load(module); - debug("version information loaded from " + moduleURL); - info(":: Ivy " + props.getProperty("version") + " - " - + props.getProperty("date") + " :: http://incubator.apache.org/ivy/ ::"); - module.close(); - } catch (IOException e) { - info(":: Ivy non official version :: http://incubator.apache.org/ivy/ ::"); - } - } else { - info(":: Ivy non official version :: http://incubator.apache.org/ivy/ ::"); - } - _showedInfo = true; - } - } - - public static void debug(String msg) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.log(msg, MSG_DEBUG); - } else { - System.err.println(msg); - } - } - - public static void verbose(String msg) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.log(msg, MSG_VERBOSE); - } else { - System.err.println(msg); - } - } - - public static void info(String msg) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.log(msg, MSG_INFO); - } else { - System.err.println(msg); - } - } - - public static void rawinfo(String msg) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.rawlog(msg, MSG_INFO); - } else { - System.err.println(msg); - } - } - - public static void deprecated(String msg) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.log("DEPRECATED: " + msg, MSG_WARN); - } else { - System.err.println(msg); - } - } - - public static void warn(String msg) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.log("WARN: " + msg, MSG_VERBOSE); - } else { - System.err.println(msg); - } - _problems.add("WARN: " + msg); - _warns.add(msg); - } - - public static void error(String msg) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - // log in verbose mode because message is appended as a problem, and will be - // logged at the end at error level - messageImpl.log("ERROR: " + msg, MSG_VERBOSE); - } else { - System.err.println(msg); - } - _problems.add("\tERROR: " + msg); - _errors.add(msg); - } - - public static List getProblems() { - return _problems; - } - - public static void sumupProblems() { - if (_problems.size() > 0) { - info("\n:: problems summary ::"); - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (_warns.size() > 0) { - info(":::: WARNINGS"); - for (Iterator iter = _warns.iterator(); iter.hasNext();) { - String msg = (String) iter.next(); - if (messageImpl != null) { - messageImpl.log("\t" + msg + "\n", MSG_WARN); - } else { - System.err.println(msg); - } - } - } - if (_errors.size() > 0) { - info(":::: ERRORS"); - for (Iterator iter = _errors.iterator(); iter.hasNext();) { - String msg = (String) iter.next(); - if (messageImpl != null) { - messageImpl.log("\t" + msg + "\n", MSG_ERR); - } else { - System.err.println(msg); - } - } - } - info("\n:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS"); - _problems.clear(); - _warns.clear(); - _errors.clear(); - } - } - - public static void progress() { - if (_showProgress) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.progress(); - } else { - System.out.println("."); - } - } - } - - public static void endProgress() { - endProgress(""); - } - - public static void endProgress(String msg) { - if (_showProgress) { - MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); - if (messageImpl != null) { - messageImpl.endProgress(msg); - } - } - } - - public static boolean isShowProgress() { - return _showProgress; - } - - public static void setShowProgress(boolean progress) { - _showProgress = progress; - } - - public static void uninit() { - IvyContext.getContext().setMessageImpl(null); - } -} +/* + * 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.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import org.apache.ivy.core.IvyContext; + +/** + * + */ +public class Message { + // messages level copied from ant project, to avoid dependency on ant + /** Message priority of "error". */ + public static final int MSG_ERR = 0; + + /** Message priority of "warning". */ + public static final int MSG_WARN = 1; + + /** Message priority of "information". */ + public static final int MSG_INFO = 2; + + /** Message priority of "verbose". */ + public static final int MSG_VERBOSE = 3; + + /** Message priority of "debug". */ + public static final int MSG_DEBUG = 4; + + private static List _problems = new ArrayList(); + + private static List _warns = new ArrayList(); + + private static List _errors = new ArrayList(); + + private static boolean _showProgress = true; + + private static boolean _showedInfo = false; + + public static void init(MessageImpl impl) { + IvyContext.getContext().setMessageImpl(impl); + showInfo(); + } + + /** + * same as init, but without displaying info + * + * @param impl + */ + public static void setImpl(MessageImpl impl) { + IvyContext.getContext().setMessageImpl(impl); + } + + public static MessageImpl getImpl() { + return IvyContext.getContext().getMessageImpl(); + } + + public static boolean isInitialised() { + return IvyContext.getContext().getMessageImpl() != null; + } + + private static void showInfo() { + if (!_showedInfo) { + Properties props = new Properties(); + URL moduleURL = Message.class.getResource("/module.properties"); + if (moduleURL != null) { + try { + InputStream module = moduleURL.openStream(); + props.load(module); + debug("version information loaded from " + moduleURL); + info(":: Ivy " + props.getProperty("version") + " - " + + props.getProperty("date") + " :: http://incubator.apache.org/ivy/ ::"); + module.close(); + } catch (IOException e) { + info(":: Ivy non official version :: http://incubator.apache.org/ivy/ ::"); + } + } else { + info(":: Ivy non official version :: http://incubator.apache.org/ivy/ ::"); + } + _showedInfo = true; + } + } + + public static void debug(String msg) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.log(msg, MSG_DEBUG); + } else { + System.err.println(msg); + } + } + + public static void verbose(String msg) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.log(msg, MSG_VERBOSE); + } else { + System.err.println(msg); + } + } + + public static void info(String msg) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.log(msg, MSG_INFO); + } else { + System.err.println(msg); + } + } + + public static void rawinfo(String msg) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.rawlog(msg, MSG_INFO); + } else { + System.err.println(msg); + } + } + + public static void deprecated(String msg) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.log("DEPRECATED: " + msg, MSG_WARN); + } else { + System.err.println(msg); + } + } + + public static void warn(String msg) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.log("WARN: " + msg, MSG_VERBOSE); + } else { + System.err.println(msg); + } + _problems.add("WARN: " + msg); + _warns.add(msg); + } + + public static void error(String msg) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + // log in verbose mode because message is appended as a problem, and will be + // logged at the end at error level + messageImpl.log("ERROR: " + msg, MSG_VERBOSE); + } else { + System.err.println(msg); + } + _problems.add("\tERROR: " + msg); + _errors.add(msg); + } + + public static List getProblems() { + return _problems; + } + + public static void sumupProblems() { + if (_problems.size() > 0) { + info("\n:: problems summary ::"); + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (_warns.size() > 0) { + info(":::: WARNINGS"); + for (Iterator iter = _warns.iterator(); iter.hasNext();) { + String msg = (String) iter.next(); + if (messageImpl != null) { + messageImpl.log("\t" + msg + "\n", MSG_WARN); + } else { + System.err.println(msg); + } + } + } + if (_errors.size() > 0) { + info(":::: ERRORS"); + for (Iterator iter = _errors.iterator(); iter.hasNext();) { + String msg = (String) iter.next(); + if (messageImpl != null) { + messageImpl.log("\t" + msg + "\n", MSG_ERR); + } else { + System.err.println(msg); + } + } + } + info("\n:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS"); + _problems.clear(); + _warns.clear(); + _errors.clear(); + } + } + + public static void progress() { + if (_showProgress) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.progress(); + } else { + System.out.println("."); + } + } + } + + public static void endProgress() { + endProgress(""); + } + + public static void endProgress(String msg) { + if (_showProgress) { + MessageImpl messageImpl = IvyContext.getContext().getMessageImpl(); + if (messageImpl != null) { + messageImpl.endProgress(msg); + } + } + } + + public static boolean isShowProgress() { + return _showProgress; + } + + public static void setShowProgress(boolean progress) { + _showProgress = progress; + } + + public static void uninit() { + IvyContext.getContext().setMessageImpl(null); + } +} diff --git a/src/java/org/apache/ivy/util/MessageImpl.java b/src/java/org/apache/ivy/util/MessageImpl.java index 96760763..2980ed89 100644 --- a/src/java/org/apache/ivy/util/MessageImpl.java +++ b/src/java/org/apache/ivy/util/MessageImpl.java @@ -1,28 +1,28 @@ -/* - * 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.util; - -public interface MessageImpl { - public void log(String msg, int level); - - public void rawlog(String msg, int level); - - public void progress(); - - public void endProgress(String msg); -} +/* + * 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.util; + +public interface MessageImpl { + public void log(String msg, int level); + + public void rawlog(String msg, int level); + + public void progress(); + + public void endProgress(String msg); +} diff --git a/src/java/org/apache/ivy/util/PropertiesFile.java b/src/java/org/apache/ivy/util/PropertiesFile.java index 50fc1a4c..e4361bfb 100644 --- a/src/java/org/apache/ivy/util/PropertiesFile.java +++ b/src/java/org/apache/ivy/util/PropertiesFile.java @@ -1,75 +1,75 @@ -/* - * 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.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; - -/** - * A simple Properties extension easing the loading and saving of data - */ -public class PropertiesFile extends Properties { - private File _file; - - private String _header; - - public PropertiesFile(File file, String header) { - _file = file; - _header = header; - if (_file.exists()) { - FileInputStream fis = null; - try { - fis = new FileInputStream(_file); - load(fis); - } catch (Exception ex) { - Message.warn("exception occured while reading properties file " + _file + ": " - + ex.getMessage()); - } - try { - if (fis != null) { - fis.close(); - } - } catch (IOException e) { - } - } - } - - public void save() { - FileOutputStream fos = null; - try { - if (_file.getParentFile() != null && !_file.getParentFile().exists()) { - _file.getParentFile().mkdirs(); - } - fos = new FileOutputStream(_file); - store(fos, _header); - } catch (Exception ex) { - Message.warn("exception occured while writing properties file " + _file + ": " - + ex.getMessage()); - } - try { - if (fos != null) { - fos.close(); - } - } catch (IOException e) { - } - } - -} \ No newline at end of file +/* + * 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.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * A simple Properties extension easing the loading and saving of data + */ +public class PropertiesFile extends Properties { + private File _file; + + private String _header; + + public PropertiesFile(File file, String header) { + _file = file; + _header = header; + if (_file.exists()) { + FileInputStream fis = null; + try { + fis = new FileInputStream(_file); + load(fis); + } catch (Exception ex) { + Message.warn("exception occured while reading properties file " + _file + ": " + + ex.getMessage()); + } + try { + if (fis != null) { + fis.close(); + } + } catch (IOException e) { + } + } + } + + public void save() { + FileOutputStream fos = null; + try { + if (_file.getParentFile() != null && !_file.getParentFile().exists()) { + _file.getParentFile().mkdirs(); + } + fos = new FileOutputStream(_file); + store(fos, _header); + } catch (Exception ex) { + Message.warn("exception occured while writing properties file " + _file + ": " + + ex.getMessage()); + } + try { + if (fos != null) { + fos.close(); + } + } catch (IOException e) { + } + } + +} diff --git a/src/java/org/apache/ivy/util/StringUtils.java b/src/java/org/apache/ivy/util/StringUtils.java index 7d9bedd3..04762299 100644 --- a/src/java/org/apache/ivy/util/StringUtils.java +++ b/src/java/org/apache/ivy/util/StringUtils.java @@ -1,126 +1,126 @@ -/* - * 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.util; - -/** - * Convenient class used only for uncapitalization Usually use commons lang but here we do not want - * to have such a dependency for only one feature - */ -public class StringUtils { - public static String uncapitalize(String string) { - if (string == null || string.length() == 0) { - return string; - } - if (string.length() == 1) { - return string.toLowerCase(); - } - return string.substring(0, 1).toLowerCase() + string.substring(1); - } - - /** - * Joins the given object array in one string, each separated by the given separator. Example: - * join(new String[] {"one", "two", "three"}, ", ") -> "one, two, three" - * - * @param objs - * @param sep - * @return - */ - public static String join(Object[] objs, String sep) { - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < objs.length; i++) { - buf.append(objs[i]).append(sep); - } - if (objs.length > 0) { - buf.setLength(buf.length() - sep.length()); // delete sep - } - return buf.toString(); - } - - // basic string codec (same algo as CVS passfile, inspired by ant CVSPass class - /** Array contain char conversion data */ - private final static char[] SHIFTS = {0, 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, 114, 120, 53, 79, 96, 109, - 72, 108, 70, 64, 76, 67, 116, 74, 68, 87, 111, 52, 75, 119, 49, 34, 82, 81, 95, 65, - 112, 86, 118, 110, 122, 105, 41, 57, 83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, - 91, 35, 125, 55, 54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56, 36, 121, - 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, 58, 113, 32, 90, 44, 98, - 60, 51, 33, 97, 62, 77, 84, 80, 85, 223, 225, 216, 187, 166, 229, 189, 222, 188, 141, - 249, 148, 200, 184, 136, 248, 190, 199, 170, 181, 204, 138, 232, 218, 183, 255, 234, - 220, 247, 213, 203, 226, 193, 174, 172, 228, 252, 217, 201, 131, 230, 197, 211, 145, - 238, 161, 179, 160, 212, 207, 221, 254, 173, 202, 146, 224, 151, 140, 196, 205, 130, - 135, 133, 143, 246, 192, 159, 244, 239, 185, 168, 215, 144, 139, 165, 180, 157, 147, - 186, 214, 176, 227, 231, 219, 169, 175, 156, 206, 198, 129, 164, 150, 210, 154, 177, - 134, 127, 182, 128, 158, 208, 162, 132, 167, 209, 149, 241, 153, 251, 237, 236, 171, - 195, 243, 233, 253, 240, 194, 250, 191, 155, 142, 137, 245, 235, 163, 242, 178, 152}; - - /** - * Encrypt the given string in a way which anybody having access to this method algorithm can - * easily decrypt. This is useful only to avoid clear string storage in a file for example, but - * shouldn't be considered as a real mean of security. This only works with simple characters - * (char < 256). - * - * @param str - * the string to encrypt - * @return the encrypted version of the string - */ - public final static String encrypt(String str) { - if (str == null) { - return null; - } - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < str.length(); i++) { - char c = str.charAt(i); - if (c >= SHIFTS.length) { - throw new IllegalArgumentException( - "encrypt method can only be used with simple characters. '" + c - + "' not allowed"); - } - buf.append(SHIFTS[c]); - } - return buf.toString(); - } - - /** - * Decrypts a string encrypted with encrypt. - * - * @param str - * the encrypted string to decrypt - * @return - */ - public final static String decrypt(String str) { - if (str == null) { - return null; - } - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < str.length(); i++) { - buf.append(decrypt(str.charAt(i))); - } - return buf.toString(); - } - - private static char decrypt(char c) { - for (char i = 0; i < SHIFTS.length; i++) { - if (SHIFTS[i] == c) { - return i; - } - } - throw new IllegalArgumentException("Impossible to decrypt '" + c - + "'. Unhandled character."); - } - -} +/* + * 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.util; + +/** + * Convenient class used only for uncapitalization Usually use commons lang but here we do not want + * to have such a dependency for only one feature + */ +public class StringUtils { + public static String uncapitalize(String string) { + if (string == null || string.length() == 0) { + return string; + } + if (string.length() == 1) { + return string.toLowerCase(); + } + return string.substring(0, 1).toLowerCase() + string.substring(1); + } + + /** + * Joins the given object array in one string, each separated by the given separator. Example: + * join(new String[] {"one", "two", "three"}, ", ") -> "one, two, three" + * + * @param objs + * @param sep + * @return + */ + public static String join(Object[] objs, String sep) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < objs.length; i++) { + buf.append(objs[i]).append(sep); + } + if (objs.length > 0) { + buf.setLength(buf.length() - sep.length()); // delete sep + } + return buf.toString(); + } + + // basic string codec (same algo as CVS passfile, inspired by ant CVSPass class + /** Array contain char conversion data */ + private final static char[] SHIFTS = {0, 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, 114, 120, 53, 79, 96, 109, + 72, 108, 70, 64, 76, 67, 116, 74, 68, 87, 111, 52, 75, 119, 49, 34, 82, 81, 95, 65, + 112, 86, 118, 110, 122, 105, 41, 57, 83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, + 91, 35, 125, 55, 54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56, 36, 121, + 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, 58, 113, 32, 90, 44, 98, + 60, 51, 33, 97, 62, 77, 84, 80, 85, 223, 225, 216, 187, 166, 229, 189, 222, 188, 141, + 249, 148, 200, 184, 136, 248, 190, 199, 170, 181, 204, 138, 232, 218, 183, 255, 234, + 220, 247, 213, 203, 226, 193, 174, 172, 228, 252, 217, 201, 131, 230, 197, 211, 145, + 238, 161, 179, 160, 212, 207, 221, 254, 173, 202, 146, 224, 151, 140, 196, 205, 130, + 135, 133, 143, 246, 192, 159, 244, 239, 185, 168, 215, 144, 139, 165, 180, 157, 147, + 186, 214, 176, 227, 231, 219, 169, 175, 156, 206, 198, 129, 164, 150, 210, 154, 177, + 134, 127, 182, 128, 158, 208, 162, 132, 167, 209, 149, 241, 153, 251, 237, 236, 171, + 195, 243, 233, 253, 240, 194, 250, 191, 155, 142, 137, 245, 235, 163, 242, 178, 152}; + + /** + * Encrypt the given string in a way which anybody having access to this method algorithm can + * easily decrypt. This is useful only to avoid clear string storage in a file for example, but + * shouldn't be considered as a real mean of security. This only works with simple characters + * (char < 256). + * + * @param str + * the string to encrypt + * @return the encrypted version of the string + */ + public final static String encrypt(String str) { + if (str == null) { + return null; + } + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + if (c >= SHIFTS.length) { + throw new IllegalArgumentException( + "encrypt method can only be used with simple characters. '" + c + + "' not allowed"); + } + buf.append(SHIFTS[c]); + } + return buf.toString(); + } + + /** + * Decrypts a string encrypted with encrypt. + * + * @param str + * the encrypted string to decrypt + * @return + */ + public final static String decrypt(String str) { + if (str == null) { + return null; + } + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < str.length(); i++) { + buf.append(decrypt(str.charAt(i))); + } + return buf.toString(); + } + + private static char decrypt(char c) { + for (char i = 0; i < SHIFTS.length; i++) { + if (SHIFTS[i] == c) { + return i; + } + } + throw new IllegalArgumentException("Impossible to decrypt '" + c + + "'. Unhandled character."); + } + +} diff --git a/src/java/org/apache/ivy/util/XMLHelper.java b/src/java/org/apache/ivy/util/XMLHelper.java index 92e72d6b..9ef0286e 100644 --- a/src/java/org/apache/ivy/util/XMLHelper.java +++ b/src/java/org/apache/ivy/util/XMLHelper.java @@ -1,128 +1,128 @@ -/* - * 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.util; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.apache.ivy.util.url.URLHandlerRegistry; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.DefaultHandler; - -public abstract class XMLHelper { - private static SAXParserFactory _validatingFactory = SAXParserFactory.newInstance(); - - private static SAXParserFactory _factory = SAXParserFactory.newInstance(); - - static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; - - static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; - - static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; - - private static boolean _canUseSchemaValidation = true; - - static { - _validatingFactory.setNamespaceAware(true); - _validatingFactory.setValidating(true); - } - - private static SAXParser newSAXParser(URL schema, InputStream schemaStream) - throws ParserConfigurationException, SAXException { - if (!_canUseSchemaValidation || schema == null) { - return _factory.newSAXParser(); - } - try { - SAXParser parser = _validatingFactory.newSAXParser(); - parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); - parser.setProperty(JAXP_SCHEMA_SOURCE, schemaStream); - return parser; - } catch (SAXNotRecognizedException ex) { - System.err - .println("WARNING: problem while setting JAXP validating property on SAXParser... XML validation will not be done: " - + ex.getMessage()); - _canUseSchemaValidation = false; - return _factory.newSAXParser(); - } - } - - // IMPORTANT: validation errors are only notified to the given handler, and - // do not cause exception - // implement warning error and fatalError methods in handler to be informed - // of validation errors - public static void parse(URL xmlURL, URL schema, DefaultHandler handler) throws SAXException, - IOException, ParserConfigurationException { - parse(xmlURL, schema, handler, null); - } - - public static void parse(URL xmlURL, URL schema, DefaultHandler handler, LexicalHandler lHandler) - throws SAXException, IOException, ParserConfigurationException { - InputStream xmlStream = URLHandlerRegistry.getDefault().openStream(xmlURL); - try { - parse(xmlStream, schema, handler, lHandler); - } finally { - try { - xmlStream.close(); - } catch (IOException e) { - } - } - } - - public static void parse(InputStream xmlStream, URL schema, DefaultHandler handler, - LexicalHandler lHandler) throws SAXException, IOException, ParserConfigurationException { - InputStream schemaStream = null; - try { - if (schema != null) { - schemaStream = URLHandlerRegistry.getDefault().openStream(schema); - } - SAXParser parser = XMLHelper.newSAXParser(schema, schemaStream); - - if (lHandler != null) { - try { - parser.setProperty("http://xml.org/sax/properties/lexical-handler", lHandler); - } catch (SAXException ex) { - System.err - .println("WARNING: problem while setting the lexical handler property on SAXParser: " - + ex.getMessage()); - // continue without the lexical handler - } - } - - parser.parse(xmlStream, handler); - } finally { - if (schemaStream != null) { - try { - schemaStream.close(); - } catch (IOException ex) { - } - } - } - } - - public static boolean canUseSchemaValidation() { - return _canUseSchemaValidation; - } - -} +/* + * 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.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.apache.ivy.util.url.URLHandlerRegistry; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.DefaultHandler; + +public abstract class XMLHelper { + private static SAXParserFactory _validatingFactory = SAXParserFactory.newInstance(); + + private static SAXParserFactory _factory = SAXParserFactory.newInstance(); + + static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; + + static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; + + static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; + + private static boolean _canUseSchemaValidation = true; + + static { + _validatingFactory.setNamespaceAware(true); + _validatingFactory.setValidating(true); + } + + private static SAXParser newSAXParser(URL schema, InputStream schemaStream) + throws ParserConfigurationException, SAXException { + if (!_canUseSchemaValidation || schema == null) { + return _factory.newSAXParser(); + } + try { + SAXParser parser = _validatingFactory.newSAXParser(); + parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); + parser.setProperty(JAXP_SCHEMA_SOURCE, schemaStream); + return parser; + } catch (SAXNotRecognizedException ex) { + System.err + .println("WARNING: problem while setting JAXP validating property on SAXParser... XML validation will not be done: " + + ex.getMessage()); + _canUseSchemaValidation = false; + return _factory.newSAXParser(); + } + } + + // IMPORTANT: validation errors are only notified to the given handler, and + // do not cause exception + // implement warning error and fatalError methods in handler to be informed + // of validation errors + public static void parse(URL xmlURL, URL schema, DefaultHandler handler) throws SAXException, + IOException, ParserConfigurationException { + parse(xmlURL, schema, handler, null); + } + + public static void parse(URL xmlURL, URL schema, DefaultHandler handler, LexicalHandler lHandler) + throws SAXException, IOException, ParserConfigurationException { + InputStream xmlStream = URLHandlerRegistry.getDefault().openStream(xmlURL); + try { + parse(xmlStream, schema, handler, lHandler); + } finally { + try { + xmlStream.close(); + } catch (IOException e) { + } + } + } + + public static void parse(InputStream xmlStream, URL schema, DefaultHandler handler, + LexicalHandler lHandler) throws SAXException, IOException, ParserConfigurationException { + InputStream schemaStream = null; + try { + if (schema != null) { + schemaStream = URLHandlerRegistry.getDefault().openStream(schema); + } + SAXParser parser = XMLHelper.newSAXParser(schema, schemaStream); + + if (lHandler != null) { + try { + parser.setProperty("http://xml.org/sax/properties/lexical-handler", lHandler); + } catch (SAXException ex) { + System.err + .println("WARNING: problem while setting the lexical handler property on SAXParser: " + + ex.getMessage()); + // continue without the lexical handler + } + } + + parser.parse(xmlStream, handler); + } finally { + if (schemaStream != null) { + try { + schemaStream.close(); + } catch (IOException ex) { + } + } + } + } + + public static boolean canUseSchemaValidation() { + return _canUseSchemaValidation; + } + +} diff --git a/src/java/org/apache/ivy/util/extendable/DefaultExtendableItem.java b/src/java/org/apache/ivy/util/extendable/DefaultExtendableItem.java index 93ddc229..0e325b30 100644 --- a/src/java/org/apache/ivy/util/extendable/DefaultExtendableItem.java +++ b/src/java/org/apache/ivy/util/extendable/DefaultExtendableItem.java @@ -1,45 +1,45 @@ -/* - * 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.util.extendable; - -import java.util.Map; - -/** - * An item which is meant to be extended, i.e. defined using extra attributes - */ -public class DefaultExtendableItem extends UnmodifiableExtendableItem { - public DefaultExtendableItem() { - this(null, null); - } - - public DefaultExtendableItem(Map stdAttributes, Map extraAttributes) { - super(stdAttributes, extraAttributes); - } - - public void setExtraAttribute(String attName, String attValue) { - super.setExtraAttribute(attName, attValue); - } - - public void setStandardAttribute(String attName, String attValue) { - super.setStandardAttribute(attName, attValue); - } - - public void setAttribute(String attName, String attValue, boolean extra) { - super.setAttribute(attName, attValue, extra); - } -} +/* + * 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.util.extendable; + +import java.util.Map; + +/** + * An item which is meant to be extended, i.e. defined using extra attributes + */ +public class DefaultExtendableItem extends UnmodifiableExtendableItem { + public DefaultExtendableItem() { + this(null, null); + } + + public DefaultExtendableItem(Map stdAttributes, Map extraAttributes) { + super(stdAttributes, extraAttributes); + } + + public void setExtraAttribute(String attName, String attValue) { + super.setExtraAttribute(attName, attValue); + } + + public void setStandardAttribute(String attName, String attValue) { + super.setStandardAttribute(attName, attValue); + } + + public void setAttribute(String attName, String attValue, boolean extra) { + super.setAttribute(attName, attValue, extra); + } +} diff --git a/src/java/org/apache/ivy/util/extendable/ExtendableItem.java b/src/java/org/apache/ivy/util/extendable/ExtendableItem.java index 06496d59..ad1f0a28 100644 --- a/src/java/org/apache/ivy/util/extendable/ExtendableItem.java +++ b/src/java/org/apache/ivy/util/extendable/ExtendableItem.java @@ -1,77 +1,77 @@ -/* - * 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.util.extendable; - -import java.util.Map; - -public interface ExtendableItem { - /** - * Gets the value of an attribute Can be used to access the value of a standard attribute (like - * organisation, revision) or of an extra attribute. - * - * @param attName - * the name of the attribute to get - * @return the value of the attribute, null if the attribute doesn't exist - */ - String getAttribute(String attName); - - /** - * Gets the value of a standard attribute Can be used only to access the value of a standard - * attribute (like organisation, revision), not an extra one - * - * @param attName - * the name of the standard attribute to get - * @return the value of the attribute, null if the attribute doesn't exist - */ - String getStandardAttribute(String attName); - - /** - * Gets the value of an extra attribute Can be used only to access the value of an extra - * attribute, not a standard one (like organisation, revision) - * - * @param attName - * the name of the extra attribute to get - * @return the value of the attribute, null if the attribute doesn't exist - */ - String getExtraAttribute(String attName); - - /** - * Returns a Map of all attributes of this extendable item, including standard and extra ones. - * The Map keys are attribute names as Strings, and values are corresponding attribute values - * (as String too) - * - * @return - */ - Map getAttributes(); - - /** - * Returns a Map of all standard attributes of this extendable item. The Map keys are attribute - * names as Strings, and values are corresponding attribute values (as String too) - * - * @return - */ - Map getStandardAttributes(); - - /** - * Returns a Map of all extra attributes of this extendable item. The Map keys are attribute - * names as Strings, and values are corresponding attribute values (as String too) - * - * @return - */ - Map getExtraAttributes(); -} \ No newline at end of file +/* + * 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.util.extendable; + +import java.util.Map; + +public interface ExtendableItem { + /** + * Gets the value of an attribute Can be used to access the value of a standard attribute (like + * organisation, revision) or of an extra attribute. + * + * @param attName + * the name of the attribute to get + * @return the value of the attribute, null if the attribute doesn't exist + */ + String getAttribute(String attName); + + /** + * Gets the value of a standard attribute Can be used only to access the value of a standard + * attribute (like organisation, revision), not an extra one + * + * @param attName + * the name of the standard attribute to get + * @return the value of the attribute, null if the attribute doesn't exist + */ + String getStandardAttribute(String attName); + + /** + * Gets the value of an extra attribute Can be used only to access the value of an extra + * attribute, not a standard one (like organisation, revision) + * + * @param attName + * the name of the extra attribute to get + * @return the value of the attribute, null if the attribute doesn't exist + */ + String getExtraAttribute(String attName); + + /** + * Returns a Map of all attributes of this extendable item, including standard and extra ones. + * The Map keys are attribute names as Strings, and values are corresponding attribute values + * (as String too) + * + * @return + */ + Map getAttributes(); + + /** + * Returns a Map of all standard attributes of this extendable item. The Map keys are attribute + * names as Strings, and values are corresponding attribute values (as String too) + * + * @return + */ + Map getStandardAttributes(); + + /** + * Returns a Map of all extra attributes of this extendable item. The Map keys are attribute + * names as Strings, and values are corresponding attribute values (as String too) + * + * @return + */ + Map getExtraAttributes(); +} diff --git a/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java b/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java index e69fe4a0..de9c1db3 100644 --- a/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java +++ b/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java @@ -1,61 +1,61 @@ -/* - * 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.util.extendable; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.xml.sax.Attributes; - -public class ExtendableItemHelper { - - public static Map getExtraAttributes(Attributes attributes, String prefix) { - Map ret = new HashMap(); - for (int i = 0; i < attributes.getLength(); i++) { - if (attributes.getQName(i).startsWith(prefix)) { - ret.put(attributes.getQName(i).substring(prefix.length()), attributes.getValue(i)); - } - } - return ret; - } - - public static Map getExtraAttributes(Attributes attributes, String[] ignoredAttNames) { - Map ret = new HashMap(); - Collection ignored = Arrays.asList(ignoredAttNames); - for (int i = 0; i < attributes.getLength(); i++) { - if (!ignored.contains(attributes.getQName(i))) { - ret.put(attributes.getQName(i), attributes.getValue(i)); - } - } - return ret; - } - - public static void fillExtraAttributes(DefaultExtendableItem item, Attributes attributes, - String[] ignoredAttNames) { - Map att = getExtraAttributes(attributes, ignoredAttNames); - for (Iterator iter = att.keySet().iterator(); iter.hasNext();) { - String attName = (String) iter.next(); - String attValue = (String) att.get(attName); - item.setExtraAttribute(attName, attValue); - } - } - -} +/* + * 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.util.extendable; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.xml.sax.Attributes; + +public class ExtendableItemHelper { + + public static Map getExtraAttributes(Attributes attributes, String prefix) { + Map ret = new HashMap(); + for (int i = 0; i < attributes.getLength(); i++) { + if (attributes.getQName(i).startsWith(prefix)) { + ret.put(attributes.getQName(i).substring(prefix.length()), attributes.getValue(i)); + } + } + return ret; + } + + public static Map getExtraAttributes(Attributes attributes, String[] ignoredAttNames) { + Map ret = new HashMap(); + Collection ignored = Arrays.asList(ignoredAttNames); + for (int i = 0; i < attributes.getLength(); i++) { + if (!ignored.contains(attributes.getQName(i))) { + ret.put(attributes.getQName(i), attributes.getValue(i)); + } + } + return ret; + } + + public static void fillExtraAttributes(DefaultExtendableItem item, Attributes attributes, + String[] ignoredAttNames) { + Map att = getExtraAttributes(attributes, ignoredAttNames); + for (Iterator iter = att.keySet().iterator(); iter.hasNext();) { + String attName = (String) iter.next(); + String attValue = (String) att.get(attName); + item.setExtraAttribute(attName, attValue); + } + } + +} diff --git a/src/java/org/apache/ivy/util/extendable/UnmodifiableExtendableItem.java b/src/java/org/apache/ivy/util/extendable/UnmodifiableExtendableItem.java index 39e5aeca..25269ad4 100644 --- a/src/java/org/apache/ivy/util/extendable/UnmodifiableExtendableItem.java +++ b/src/java/org/apache/ivy/util/extendable/UnmodifiableExtendableItem.java @@ -1,89 +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.util.extendable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class UnmodifiableExtendableItem implements ExtendableItem { - private Map _attributes = new HashMap(); - - private Map _unmodifiableAttributesView = Collections.unmodifiableMap(_attributes); - - private Map _stdAttributes = new HashMap(); - - private Map _unmodifiableStdAttributesView = Collections.unmodifiableMap(_stdAttributes); - - private Map _extraAttributes = new HashMap(); - - private Map _unmodifiableExtraAttributesView = Collections.unmodifiableMap(_extraAttributes); - - public UnmodifiableExtendableItem(Map stdAttributes, Map extraAttributes) { - if (stdAttributes != null) { - _attributes.putAll(stdAttributes); - _stdAttributes.putAll(stdAttributes); - } - if (extraAttributes != null) { - _attributes.putAll(extraAttributes); - _extraAttributes.putAll(extraAttributes); - } - } - - public String getAttribute(String attName) { - return (String) _attributes.get(attName); - } - - public String getExtraAttribute(String attName) { - return (String) _extraAttributes.get(attName); - } - - public String getStandardAttribute(String attName) { - return (String) _stdAttributes.get(attName); - } - - protected void setExtraAttribute(String attName, String attValue) { - setAttribute(attName, attValue, true); - } - - protected void setStandardAttribute(String attName, String attValue) { - setAttribute(attName, attValue, false); - } - - protected void setAttribute(String attName, String attValue, boolean extra) { - if (extra) { - _extraAttributes.put(attName, attValue); - } else { - _stdAttributes.put(attName, attValue); - } - _attributes.put(attName, attValue); - } - - public Map getAttributes() { - return _unmodifiableAttributesView; - } - - public Map getStandardAttributes() { - return _unmodifiableStdAttributesView; - } - - public Map getExtraAttributes() { - return _unmodifiableExtraAttributesView; - } - -} +/* + * 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.util.extendable; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class UnmodifiableExtendableItem implements ExtendableItem { + private Map _attributes = new HashMap(); + + private Map _unmodifiableAttributesView = Collections.unmodifiableMap(_attributes); + + private Map _stdAttributes = new HashMap(); + + private Map _unmodifiableStdAttributesView = Collections.unmodifiableMap(_stdAttributes); + + private Map _extraAttributes = new HashMap(); + + private Map _unmodifiableExtraAttributesView = Collections.unmodifiableMap(_extraAttributes); + + public UnmodifiableExtendableItem(Map stdAttributes, Map extraAttributes) { + if (stdAttributes != null) { + _attributes.putAll(stdAttributes); + _stdAttributes.putAll(stdAttributes); + } + if (extraAttributes != null) { + _attributes.putAll(extraAttributes); + _extraAttributes.putAll(extraAttributes); + } + } + + public String getAttribute(String attName) { + return (String) _attributes.get(attName); + } + + public String getExtraAttribute(String attName) { + return (String) _extraAttributes.get(attName); + } + + public String getStandardAttribute(String attName) { + return (String) _stdAttributes.get(attName); + } + + protected void setExtraAttribute(String attName, String attValue) { + setAttribute(attName, attValue, true); + } + + protected void setStandardAttribute(String attName, String attValue) { + setAttribute(attName, attValue, false); + } + + protected void setAttribute(String attName, String attValue, boolean extra) { + if (extra) { + _extraAttributes.put(attName, attValue); + } else { + _stdAttributes.put(attName, attValue); + } + _attributes.put(attName, attValue); + } + + public Map getAttributes() { + return _unmodifiableAttributesView; + } + + public Map getStandardAttributes() { + return _unmodifiableStdAttributesView; + } + + public Map getExtraAttributes() { + return _unmodifiableExtraAttributesView; + } + +} diff --git a/src/java/org/apache/ivy/util/filter/AndFilter.java b/src/java/org/apache/ivy/util/filter/AndFilter.java index 6ac56fdc..020e08b4 100644 --- a/src/java/org/apache/ivy/util/filter/AndFilter.java +++ b/src/java/org/apache/ivy/util/filter/AndFilter.java @@ -1,41 +1,41 @@ -/* - * 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.util.filter; - -public class AndFilter implements Filter { - private Filter _op1; - - private Filter _op2; - - public AndFilter(Filter op1, Filter op2) { - _op1 = op1; - _op2 = op2; - } - - public Filter getOp1() { - return _op1; - } - - public Filter getOp2() { - return _op2; - } - - public boolean accept(Object o) { - return _op1.accept(o) && _op2.accept(o); - } -} +/* + * 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.util.filter; + +public class AndFilter implements Filter { + private Filter _op1; + + private Filter _op2; + + public AndFilter(Filter op1, Filter op2) { + _op1 = op1; + _op2 = op2; + } + + public Filter getOp1() { + return _op1; + } + + public Filter getOp2() { + return _op2; + } + + public boolean accept(Object o) { + return _op1.accept(o) && _op2.accept(o); + } +} diff --git a/src/java/org/apache/ivy/util/filter/ArtifactTypeFilter.java b/src/java/org/apache/ivy/util/filter/ArtifactTypeFilter.java index 41eecdfb..830b7c36 100644 --- a/src/java/org/apache/ivy/util/filter/ArtifactTypeFilter.java +++ b/src/java/org/apache/ivy/util/filter/ArtifactTypeFilter.java @@ -1,39 +1,39 @@ -/* - * 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.util.filter; - -import java.util.ArrayList; -import java.util.Collection; - -import org.apache.ivy.core.module.descriptor.Artifact; - -public class ArtifactTypeFilter implements Filter { - private Collection _acceptedTypes; - - public ArtifactTypeFilter(Collection acceptedTypes) { - _acceptedTypes = new ArrayList(acceptedTypes); - } - - public boolean accept(Object o) { - if (!(o instanceof Artifact)) { - return false; - } - Artifact art = (Artifact) o; - return _acceptedTypes.contains(art.getType()); - } -} +/* + * 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.util.filter; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.ivy.core.module.descriptor.Artifact; + +public class ArtifactTypeFilter implements Filter { + private Collection _acceptedTypes; + + public ArtifactTypeFilter(Collection acceptedTypes) { + _acceptedTypes = new ArrayList(acceptedTypes); + } + + public boolean accept(Object o) { + if (!(o instanceof Artifact)) { + return false; + } + Artifact art = (Artifact) o; + return _acceptedTypes.contains(art.getType()); + } +} diff --git a/src/java/org/apache/ivy/util/filter/Filter.java b/src/java/org/apache/ivy/util/filter/Filter.java index ef3213c2..2950e144 100644 --- a/src/java/org/apache/ivy/util/filter/Filter.java +++ b/src/java/org/apache/ivy/util/filter/Filter.java @@ -1,22 +1,22 @@ -/* - * 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.util.filter; - -public interface Filter { - boolean accept(Object o); -} +/* + * 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.util.filter; + +public interface Filter { + boolean accept(Object o); +} diff --git a/src/java/org/apache/ivy/util/filter/FilterHelper.java b/src/java/org/apache/ivy/util/filter/FilterHelper.java index 26b05be0..625b4027 100644 --- a/src/java/org/apache/ivy/util/filter/FilterHelper.java +++ b/src/java/org/apache/ivy/util/filter/FilterHelper.java @@ -1,61 +1,61 @@ -/* - * 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.util.filter; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -public class FilterHelper { - public static Filter NO_FILTER = NoFilter.INSTANCE; - - public static Filter getArtifactTypeFilter(String types) { - if (types == null || types.trim().equals("*")) { - return NO_FILTER; - } - String[] t = types.split(","); - List acceptedTypes = new ArrayList(types.length()); - for (int i = 0; i < t.length; i++) { - acceptedTypes.add(t[i].trim()); - } - return new ArtifactTypeFilter(acceptedTypes); - } - - /** - * we could have used commons-collections facility for this... if we accepted to add - * dependencies on third party jars - * - * @param col - * @param filter - * @return - */ - public static Collection filter(Collection col, Filter filter) { - if (filter == null) { - return col; - } - Collection ret = new ArrayList(col); - for (Iterator iter = ret.iterator(); iter.hasNext();) { - Object element = (Object) iter.next(); - if (!filter.accept(element)) { - iter.remove(); - } - } - return ret; - } -} +/* + * 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.util.filter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +public class FilterHelper { + public static Filter NO_FILTER = NoFilter.INSTANCE; + + public static Filter getArtifactTypeFilter(String types) { + if (types == null || types.trim().equals("*")) { + return NO_FILTER; + } + String[] t = types.split(","); + List acceptedTypes = new ArrayList(types.length()); + for (int i = 0; i < t.length; i++) { + acceptedTypes.add(t[i].trim()); + } + return new ArtifactTypeFilter(acceptedTypes); + } + + /** + * we could have used commons-collections facility for this... if we accepted to add + * dependencies on third party jars + * + * @param col + * @param filter + * @return + */ + public static Collection filter(Collection col, Filter filter) { + if (filter == null) { + return col; + } + Collection ret = new ArrayList(col); + for (Iterator iter = ret.iterator(); iter.hasNext();) { + Object element = (Object) iter.next(); + if (!filter.accept(element)) { + iter.remove(); + } + } + return ret; + } +} diff --git a/src/java/org/apache/ivy/util/filter/NoFilter.java b/src/java/org/apache/ivy/util/filter/NoFilter.java index 52a37914..25e0c0b8 100644 --- a/src/java/org/apache/ivy/util/filter/NoFilter.java +++ b/src/java/org/apache/ivy/util/filter/NoFilter.java @@ -1,30 +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. - * - */ -package org.apache.ivy.util.filter; - -public class NoFilter implements Filter { - public static final Filter INSTANCE = new NoFilter(); - - private NoFilter() { - } - - public boolean accept(Object o) { - return true; - } - -} +/* + * 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.util.filter; + +public class NoFilter implements Filter { + public static final Filter INSTANCE = new NoFilter(); + + private NoFilter() { + } + + public boolean accept(Object o) { + return true; + } + +} diff --git a/src/java/org/apache/ivy/util/filter/NotFilter.java b/src/java/org/apache/ivy/util/filter/NotFilter.java index 10cf5bac..b7ddcae4 100644 --- a/src/java/org/apache/ivy/util/filter/NotFilter.java +++ b/src/java/org/apache/ivy/util/filter/NotFilter.java @@ -1,34 +1,34 @@ -/* - * 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.util.filter; - -public class NotFilter implements Filter { - private Filter _op; - - public NotFilter(Filter op) { - _op = op; - } - - public Filter getOp() { - return _op; - } - - public boolean accept(Object o) { - return !_op.accept(o); - } -} +/* + * 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.util.filter; + +public class NotFilter implements Filter { + private Filter _op; + + public NotFilter(Filter op) { + _op = op; + } + + public Filter getOp() { + return _op; + } + + public boolean accept(Object o) { + return !_op.accept(o); + } +} diff --git a/src/java/org/apache/ivy/util/filter/OrFilter.java b/src/java/org/apache/ivy/util/filter/OrFilter.java index c1070bae..fad759d6 100644 --- a/src/java/org/apache/ivy/util/filter/OrFilter.java +++ b/src/java/org/apache/ivy/util/filter/OrFilter.java @@ -1,41 +1,41 @@ -/* - * 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.util.filter; - -public class OrFilter implements Filter { - private Filter _op1; - - private Filter _op2; - - public OrFilter(Filter op1, Filter op2) { - _op1 = op1; - _op2 = op2; - } - - public Filter getOp1() { - return _op1; - } - - public Filter getOp2() { - return _op2; - } - - public boolean accept(Object o) { - return _op1.accept(o) || _op2.accept(o); - } -} +/* + * 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.util.filter; + +public class OrFilter implements Filter { + private Filter _op1; + + private Filter _op2; + + public OrFilter(Filter op1, Filter op2) { + _op1 = op1; + _op2 = op2; + } + + public Filter getOp1() { + return _op1; + } + + public Filter getOp2() { + return _op2; + } + + public boolean accept(Object o) { + return _op1.accept(o) || _op2.accept(o); + } +} diff --git a/src/java/org/apache/ivy/util/url/AbstractURLHandler.java b/src/java/org/apache/ivy/util/url/AbstractURLHandler.java index cf7d1297..bea7918a 100644 --- a/src/java/org/apache/ivy/util/url/AbstractURLHandler.java +++ b/src/java/org/apache/ivy/util/url/AbstractURLHandler.java @@ -1,46 +1,46 @@ -/* - * 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.util.url; - -import java.net.URL; - -public abstract class AbstractURLHandler implements URLHandler { - public boolean isReachable(URL url) { - return getURLInfo(url).isReachable(); - } - - public boolean isReachable(URL url, int timeout) { - return getURLInfo(url, timeout).isReachable(); - } - - public long getContentLength(URL url) { - return getURLInfo(url).getContentLength(); - } - - public long getContentLength(URL url, int timeout) { - return getURLInfo(url, timeout).getContentLength(); - } - - public long getLastModified(URL url) { - return getURLInfo(url).getLastModified(); - } - - public long getLastModified(URL url, int timeout) { - return getURLInfo(url, timeout).getLastModified(); - } -} +/* + * 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.util.url; + +import java.net.URL; + +public abstract class AbstractURLHandler implements URLHandler { + public boolean isReachable(URL url) { + return getURLInfo(url).isReachable(); + } + + public boolean isReachable(URL url, int timeout) { + return getURLInfo(url, timeout).isReachable(); + } + + public long getContentLength(URL url) { + return getURLInfo(url).getContentLength(); + } + + public long getContentLength(URL url, int timeout) { + return getURLInfo(url, timeout).getContentLength(); + } + + public long getLastModified(URL url) { + return getURLInfo(url).getLastModified(); + } + + public long getLastModified(URL url, int timeout) { + return getURLInfo(url, timeout).getLastModified(); + } +} diff --git a/src/java/org/apache/ivy/util/url/ApacheURLLister.java b/src/java/org/apache/ivy/util/url/ApacheURLLister.java index 1c985949..726f0e01 100644 --- a/src/java/org/apache/ivy/util/url/ApacheURLLister.java +++ b/src/java/org/apache/ivy/util/url/ApacheURLLister.java @@ -1,156 +1,156 @@ -/* - * 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.util.url; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; - -/** - * Utility class which helps to list urls under a given url. This has been tested with Apache 1.3.33 - * server listing, as the one used at ibiblio, and with Apache 2.0.53 server listing, as the one on - * mirrors.sunsite.dk. - */ -public class ApacheURLLister { - // ~ Static variables/initializers ------------------------------------------ - - private static final Pattern PATTERN = Pattern.compile( - "]*href=\"([^\"]*)\"[^>]*>(?:<[^>]+>)*?([^<>]+?)(?:<[^>]+>)*?", - Pattern.CASE_INSENSITIVE); - - // ~ Methods ---------------------------------------------------------------- - - /** - * Returns a list of sub urls of the given url. The returned list is a list of URL. - * - * @param url - * The base URL from which to retrieve the listing. - * @return a list of sub urls of the given url. - * @throws IOException - * If an error occures retrieving the HTML. - */ - public List listAll(URL url) throws IOException { - return retrieveListing(url, true, true); - } - - /** - * Returns a list of sub 'directories' of the given url. The returned list is a list of URL. - * - * @param url - * The base URL from which to retrieve the listing. - * @return a list of sub 'directories' of the given url. - * @throws IOException - * If an error occures retrieving the HTML. - */ - public List listDirectories(URL url) throws IOException { - return retrieveListing(url, false, true); - } - - /** - * Returns a list of sub 'files' (in opposition to directories) of the given url. The returned - * list is a list of URL. - * - * @param url - * The base URL from which to retrieve the listing. - * @return a list of sub 'files' of the given url. - * @throws IOException - * If an error occures retrieving the HTML. - */ - public List listFiles(URL url) throws IOException { - return retrieveListing(url, true, false); - } - - /** - * Retrieves a {@link List} of {@link URL}s corresponding to the files and/or directories found - * at the supplied base URL. - * - * @param url - * The base URL from which to retrieve the listing. - * @param includeFiles - * If true include files in the returned list. - * @param includeDirectories - * If true include directories in the returned list. - * @return A {@link List} of {@link URL}s. - * @throws IOException - * If an error occures retrieving the HTML. - */ - public List retrieveListing(URL url, boolean includeFiles, boolean includeDirectories) - throws IOException { - List urlList = new ArrayList(); - - // add trailing slash for relative urls - if (!url.getPath().endsWith("/") && !url.getPath().endsWith(".html")) { - url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "/"); - } - - BufferedReader r = new BufferedReader(new InputStreamReader(URLHandlerRegistry.getDefault() - .openStream(url))); - - String htmlText = FileUtil.readEntirely(r); - - Matcher matcher = PATTERN.matcher(htmlText); - - while (matcher.find()) { - // get the href text and the displayed text - String href = matcher.group(1); - String text = matcher.group(2); - - if ((href == null) || (text == null)) { - // the groups were not found (shouldn't happen, really) - continue; - } - - text = text.trim(); - - // absolute href: convert to relative one - if (href.startsWith("/")) { - int slashIndex = href.substring(0, href.length() - 1).lastIndexOf('/'); - href = href.substring(slashIndex + 1); - } - - // exclude those where they do not match - // href will never be truncated, text may be truncated by apache - // may have a '.' from either the extension (.jar) or "..>" - int dotIndex = text.indexOf('.'); - - if (((dotIndex != -1) && !href.startsWith(text.substring(0, dotIndex))) - || ((dotIndex == -1) && !href.equalsIgnoreCase(text))) { - // the href and the text do not "match" - continue; - } - - boolean directory = href.endsWith("/"); - - if ((directory && includeDirectories) || (!directory && includeFiles)) { - URL child = new URL(url, href); - urlList.add(child); - Message.debug("ApacheURLLister found URL=[" + child + "]."); - } - } - - return urlList; - } -} +/* + * 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.util.url; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; + +/** + * Utility class which helps to list urls under a given url. This has been tested with Apache 1.3.33 + * server listing, as the one used at ibiblio, and with Apache 2.0.53 server listing, as the one on + * mirrors.sunsite.dk. + */ +public class ApacheURLLister { + // ~ Static variables/initializers ------------------------------------------ + + private static final Pattern PATTERN = Pattern.compile( + "]*href=\"([^\"]*)\"[^>]*>(?:<[^>]+>)*?([^<>]+?)(?:<[^>]+>)*?", + Pattern.CASE_INSENSITIVE); + + // ~ Methods ---------------------------------------------------------------- + + /** + * Returns a list of sub urls of the given url. The returned list is a list of URL. + * + * @param url + * The base URL from which to retrieve the listing. + * @return a list of sub urls of the given url. + * @throws IOException + * If an error occures retrieving the HTML. + */ + public List listAll(URL url) throws IOException { + return retrieveListing(url, true, true); + } + + /** + * Returns a list of sub 'directories' of the given url. The returned list is a list of URL. + * + * @param url + * The base URL from which to retrieve the listing. + * @return a list of sub 'directories' of the given url. + * @throws IOException + * If an error occures retrieving the HTML. + */ + public List listDirectories(URL url) throws IOException { + return retrieveListing(url, false, true); + } + + /** + * Returns a list of sub 'files' (in opposition to directories) of the given url. The returned + * list is a list of URL. + * + * @param url + * The base URL from which to retrieve the listing. + * @return a list of sub 'files' of the given url. + * @throws IOException + * If an error occures retrieving the HTML. + */ + public List listFiles(URL url) throws IOException { + return retrieveListing(url, true, false); + } + + /** + * Retrieves a {@link List} of {@link URL}s corresponding to the files and/or directories found + * at the supplied base URL. + * + * @param url + * The base URL from which to retrieve the listing. + * @param includeFiles + * If true include files in the returned list. + * @param includeDirectories + * If true include directories in the returned list. + * @return A {@link List} of {@link URL}s. + * @throws IOException + * If an error occures retrieving the HTML. + */ + public List retrieveListing(URL url, boolean includeFiles, boolean includeDirectories) + throws IOException { + List urlList = new ArrayList(); + + // add trailing slash for relative urls + if (!url.getPath().endsWith("/") && !url.getPath().endsWith(".html")) { + url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "/"); + } + + BufferedReader r = new BufferedReader(new InputStreamReader(URLHandlerRegistry.getDefault() + .openStream(url))); + + String htmlText = FileUtil.readEntirely(r); + + Matcher matcher = PATTERN.matcher(htmlText); + + while (matcher.find()) { + // get the href text and the displayed text + String href = matcher.group(1); + String text = matcher.group(2); + + if ((href == null) || (text == null)) { + // the groups were not found (shouldn't happen, really) + continue; + } + + text = text.trim(); + + // absolute href: convert to relative one + if (href.startsWith("/")) { + int slashIndex = href.substring(0, href.length() - 1).lastIndexOf('/'); + href = href.substring(slashIndex + 1); + } + + // exclude those where they do not match + // href will never be truncated, text may be truncated by apache + // may have a '.' from either the extension (.jar) or "..>" + int dotIndex = text.indexOf('.'); + + if (((dotIndex != -1) && !href.startsWith(text.substring(0, dotIndex))) + || ((dotIndex == -1) && !href.equalsIgnoreCase(text))) { + // the href and the text do not "match" + continue; + } + + boolean directory = href.endsWith("/"); + + if ((directory && includeDirectories) || (!directory && includeFiles)) { + URL child = new URL(url, href); + urlList.add(child); + Message.debug("ApacheURLLister found URL=[" + child + "]."); + } + } + + return urlList; + } +} diff --git a/src/java/org/apache/ivy/util/url/BasicURLHandler.java b/src/java/org/apache/ivy/util/url/BasicURLHandler.java index b9e2eec9..7dc7cbcf 100644 --- a/src/java/org/apache/ivy/util/url/BasicURLHandler.java +++ b/src/java/org/apache/ivy/util/url/BasicURLHandler.java @@ -1,153 +1,153 @@ -/* - * 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.util.url; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.net.UnknownHostException; - -import org.apache.ivy.util.CopyProgressListener; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; - -/** - * - */ -public class BasicURLHandler extends AbstractURLHandler { - - private static interface HttpStatus { - static final int SC_OK = 200; - - static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407; - } - - public BasicURLHandler() { - Message.debug("installing " + IvyAuthenticator.INSTANCE.getClass()); // do not remove, - // ensure - // IvyAuthenticator - // class loading! - } - - public URLInfo getURLInfo(URL url) { - return getURLInfo(url, 0); - } - - public URLInfo getURLInfo(URL url, int timeout) { - URLConnection con = null; - try { - con = url.openConnection(); - if (con instanceof HttpURLConnection) { - int status = ((HttpURLConnection) con).getResponseCode(); - if (status == HttpStatus.SC_OK) { - return new URLInfo(true, ((HttpURLConnection) con).getContentLength(), con - .getLastModified()); - } - if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { - Message.warn("Your proxy requires authentication."); - } else if (String.valueOf(status).startsWith("4")) { - Message.verbose("CLIENT ERROR: " - + ((HttpURLConnection) con).getResponseMessage() + " url=" + url); - } else if (String.valueOf(status).startsWith("5")) { - Message.error("SERVER ERROR: " + ((HttpURLConnection) con).getResponseMessage() - + " url=" + url); - } - Message.debug("HTTP response status: " + status + " url=" + url); - } else { - int contentLength = con.getContentLength(); - if (contentLength <= 0) { - return UNAVAILABLE; - } else { - return new URLInfo(true, contentLength, con.getLastModified()); - } - } - } catch (UnknownHostException e) { - Message.warn("Host " + e.getMessage() + " not found. url=" + url); - Message - .info("You probably access the destination server through a proxy server that is not well configured."); - } catch (IOException e) { - Message.error("Server access Error: " + e.getMessage() + " url=" + url); - } finally { - disconnect(con); - } - return UNAVAILABLE; - } - - public InputStream openStream(URL url) throws IOException { - URLConnection conn = null; - InputStream inStream = null; - try { - conn = url.openConnection(); - inStream = conn.getInputStream(); - ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - - byte[] buffer = new byte[4096]; - int len; - while ((len = inStream.read(buffer)) > 0) { - outStream.write(buffer, 0, len); - } - return new ByteArrayInputStream(outStream.toByteArray()); - } finally { - if (inStream != null) { - inStream.close(); - } - - disconnect(conn); - } - } - - public void download(URL src, File dest, CopyProgressListener l) throws IOException { - URLConnection srcConn = null; - try { - srcConn = src.openConnection(); - int contentLength = srcConn.getContentLength(); - FileUtil.copy(srcConn.getInputStream(), dest, l); - if (dest.length() != contentLength && contentLength != -1) { - dest.delete(); - throw new IOException( - "Downloaded file size doesn't match expected Content Length for " + src - + ". Please retry."); - } - } finally { - disconnect(srcConn); - } - } - - private void disconnect(URLConnection con) { - if (con instanceof HttpURLConnection) { - ((HttpURLConnection) con).disconnect(); - } else if (con != null - && "sun.net.www.protocol.file.FileURLConnection".equals(con.getClass().getName())) { - // ugly fix for a sun jre bug: - // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700 - // - // getting header info on the fileurlconnection opens the connection, - // which opens a file input stream without closing it. - try { - con.getInputStream().close(); - } catch (IOException e) { - } - } - } - -} +/* + * 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.util.url; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.net.UnknownHostException; + +import org.apache.ivy.util.CopyProgressListener; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; + +/** + * + */ +public class BasicURLHandler extends AbstractURLHandler { + + private static interface HttpStatus { + static final int SC_OK = 200; + + static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407; + } + + public BasicURLHandler() { + Message.debug("installing " + IvyAuthenticator.INSTANCE.getClass()); // do not remove, + // ensure + // IvyAuthenticator + // class loading! + } + + public URLInfo getURLInfo(URL url) { + return getURLInfo(url, 0); + } + + public URLInfo getURLInfo(URL url, int timeout) { + URLConnection con = null; + try { + con = url.openConnection(); + if (con instanceof HttpURLConnection) { + int status = ((HttpURLConnection) con).getResponseCode(); + if (status == HttpStatus.SC_OK) { + return new URLInfo(true, ((HttpURLConnection) con).getContentLength(), con + .getLastModified()); + } + if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { + Message.warn("Your proxy requires authentication."); + } else if (String.valueOf(status).startsWith("4")) { + Message.verbose("CLIENT ERROR: " + + ((HttpURLConnection) con).getResponseMessage() + " url=" + url); + } else if (String.valueOf(status).startsWith("5")) { + Message.error("SERVER ERROR: " + ((HttpURLConnection) con).getResponseMessage() + + " url=" + url); + } + Message.debug("HTTP response status: " + status + " url=" + url); + } else { + int contentLength = con.getContentLength(); + if (contentLength <= 0) { + return UNAVAILABLE; + } else { + return new URLInfo(true, contentLength, con.getLastModified()); + } + } + } catch (UnknownHostException e) { + Message.warn("Host " + e.getMessage() + " not found. url=" + url); + Message + .info("You probably access the destination server through a proxy server that is not well configured."); + } catch (IOException e) { + Message.error("Server access Error: " + e.getMessage() + " url=" + url); + } finally { + disconnect(con); + } + return UNAVAILABLE; + } + + public InputStream openStream(URL url) throws IOException { + URLConnection conn = null; + InputStream inStream = null; + try { + conn = url.openConnection(); + inStream = conn.getInputStream(); + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + + byte[] buffer = new byte[4096]; + int len; + while ((len = inStream.read(buffer)) > 0) { + outStream.write(buffer, 0, len); + } + return new ByteArrayInputStream(outStream.toByteArray()); + } finally { + if (inStream != null) { + inStream.close(); + } + + disconnect(conn); + } + } + + public void download(URL src, File dest, CopyProgressListener l) throws IOException { + URLConnection srcConn = null; + try { + srcConn = src.openConnection(); + int contentLength = srcConn.getContentLength(); + FileUtil.copy(srcConn.getInputStream(), dest, l); + if (dest.length() != contentLength && contentLength != -1) { + dest.delete(); + throw new IOException( + "Downloaded file size doesn't match expected Content Length for " + src + + ". Please retry."); + } + } finally { + disconnect(srcConn); + } + } + + private void disconnect(URLConnection con) { + if (con instanceof HttpURLConnection) { + ((HttpURLConnection) con).disconnect(); + } else if (con != null + && "sun.net.www.protocol.file.FileURLConnection".equals(con.getClass().getName())) { + // ugly fix for a sun jre bug: + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700 + // + // getting header info on the fileurlconnection opens the connection, + // which opens a file input stream without closing it. + try { + con.getInputStream().close(); + } catch (IOException e) { + } + } + } + +} diff --git a/src/java/org/apache/ivy/util/url/CredentialsStore.java b/src/java/org/apache/ivy/util/url/CredentialsStore.java index 65a537d3..104d34f6 100644 --- a/src/java/org/apache/ivy/util/url/CredentialsStore.java +++ b/src/java/org/apache/ivy/util/url/CredentialsStore.java @@ -1,56 +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. - * - */ -package org.apache.ivy.util.url; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.ivy.util.Credentials; -import org.apache.ivy.util.Message; - -/** - * - */ -public class CredentialsStore { - /** - * A Map of Credentials objects keyed by the 'key' of the Credentials. - */ - private final static Map keyring = new HashMap(); - - public final static CredentialsStore INSTANCE = new CredentialsStore(); - - private CredentialsStore() { - } - - public void addCredentials(String realm, String host, String userName, String passwd) { - if (userName == null) { - return; - } - Credentials c = new Credentials(realm, host, userName, passwd); - Message.debug("credentials added: " + c); - keyring.put(c.getKey(), c); - // add also with host only, to be able to find credential with host only - // (useful for httpclient especially) - keyring.put(c.getHost(), c); - } - - public Credentials getCredentials(String realm, String host) { - return (Credentials) keyring.get(Credentials.buildKey(realm, host)); - } - -} +/* + * 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.util.url; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.ivy.util.Credentials; +import org.apache.ivy.util.Message; + +/** + * + */ +public class CredentialsStore { + /** + * A Map of Credentials objects keyed by the 'key' of the Credentials. + */ + private final static Map keyring = new HashMap(); + + public final static CredentialsStore INSTANCE = new CredentialsStore(); + + private CredentialsStore() { + } + + public void addCredentials(String realm, String host, String userName, String passwd) { + if (userName == null) { + return; + } + Credentials c = new Credentials(realm, host, userName, passwd); + Message.debug("credentials added: " + c); + keyring.put(c.getKey(), c); + // add also with host only, to be able to find credential with host only + // (useful for httpclient especially) + keyring.put(c.getHost(), c); + } + + public Credentials getCredentials(String realm, String host) { + return (Credentials) keyring.get(Credentials.buildKey(realm, host)); + } + +} diff --git a/src/java/org/apache/ivy/util/url/HttpClientHandler.java b/src/java/org/apache/ivy/util/url/HttpClientHandler.java index 4ea032b2..7952e7b6 100644 --- a/src/java/org/apache/ivy/util/url/HttpClientHandler.java +++ b/src/java/org/apache/ivy/util/url/HttpClientHandler.java @@ -1,346 +1,346 @@ -/* - * 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.util.url; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.UnknownHostException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpMethodBase; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthPolicy; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.ivy.util.CopyProgressListener; -import org.apache.ivy.util.Credentials; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; - -/** - * - */ -public class HttpClientHandler extends AbstractURLHandler { - private static final SimpleDateFormat LAST_MODIFIED_FORMAT = new SimpleDateFormat( - "EEE, d MMM yyyy HH:mm:ss z", Locale.US); - - // proxy configuration: obtain from system properties - private int _proxyPort; - - private String _proxyRealm = null; - - private String _proxyHost = null; - - private String _proxyUserName = null; - - private String _proxyPasswd = null; - - private HttpClientHelper _httpClientHelper; - - public HttpClientHandler() { - configureProxy(); - } - - private void configureProxy() { - _proxyRealm = null; - // no equivalent for realm in jdk proxy support ? - _proxyHost = System.getProperty("http.proxyHost"); - // TODO constant is better ... - if (useProxy()) { - _proxyPort = Integer.parseInt(System.getProperty("http.proxyPort", "80")); - _proxyUserName = System.getProperty("http.proxyUser"); - _proxyPasswd = System.getProperty("http.proxyPassword"); - // It seems there is no equivalent in HttpClient for - // 'http.nonProxyHosts' property - Message.verbose("proxy configured: host=" + _proxyHost + " port=" + _proxyPort - + " user=" + _proxyUserName); - } else { - Message.verbose("no proxy configured"); - } - } - - public InputStream openStream(URL url) throws IOException { - GetMethod get = doGet(url); - return new GETInputStream(get); - } - - public void download(URL src, File dest, CopyProgressListener l) throws IOException { - GetMethod get = doGet(src); - FileUtil.copy(get.getResponseBodyAsStream(), dest, l); - get.releaseConnection(); - } - - public URLInfo getURLInfo(URL url) { - return getURLInfo(url, 0); - } - - public URLInfo getURLInfo(URL url, int timeout) { - HeadMethod head = null; - try { - head = doHead(url, timeout); - int status = head.getStatusCode(); - head.releaseConnection(); - if (status == HttpStatus.SC_OK) { - return new URLInfo(true, getResponseContentLength(head), getLastModified(head)); - } - if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { - Message.error("Your proxy requires authentication."); - } else if (String.valueOf(status).startsWith("4")) { - Message.verbose("CLIENT ERROR: " + head.getStatusText() + " url=" + url); - } else if (String.valueOf(status).startsWith("5")) { - Message.warn("SERVER ERROR: " + head.getStatusText() + " url=" + url); - } - Message.debug("HTTP response status: " + status + "=" + head.getStatusText() + " url=" - + url); - } catch (HttpException e) { - Message.error("HttpClientHandler: " + e.getMessage() + ":" + e.getReasonCode() + "=" - + e.getReason() + " url=" + url); - } catch (UnknownHostException e) { - Message.warn("Host " + e.getMessage() + " not found. url=" + url); - Message - .info("You probably access the destination server through a proxy server that is not well configured."); - } catch (IOException e) { - Message.error("HttpClientHandler: " + e.getMessage() + " url=" + url); - } finally { - if (head != null) { - head.releaseConnection(); - } - } - return UNAVAILABLE; - } - - private long getLastModified(HeadMethod head) { - Header header = head.getResponseHeader("last-modified"); - if (header != null) { - String lastModified = header.getValue(); - try { - return LAST_MODIFIED_FORMAT.parse(lastModified).getTime(); - } catch (ParseException e) { - } - return System.currentTimeMillis(); - } else { - return System.currentTimeMillis(); - } - } - - private long getResponseContentLength(HeadMethod head) { - return getHttpClientHelper().getResponseContentLength(head); - } - - private HttpClientHelper getHttpClientHelper() { - if (_httpClientHelper == null) { - // use commons httpclient 3.0 if available - try { - HttpMethodBase.class.getMethod("getResponseContentLength", new Class[0]); - _httpClientHelper = new HttpClientHelper3x(); - Message.verbose("using commons httpclient 3.x helper"); - } catch (SecurityException e) { - Message - .verbose("unable to get access to getResponseContentLength of commons-httpclient HeadMethod. Please use commons-httpclient 3.0 or use ivy with sufficient security permissions."); - Message.verbose("exception: " + e.getMessage()); - _httpClientHelper = new HttpClientHelper2x(); - Message.verbose("using commons httpclient 2.x helper"); - } catch (NoSuchMethodException e) { - _httpClientHelper = new HttpClientHelper2x(); - Message.verbose("using commons httpclient 2.x helper"); - } - } - return _httpClientHelper; - } - - public int getHttpClientMajorVersion() { - HttpClientHelper helper = getHttpClientHelper(); - return helper.getHttpClientMajorVersion(); - } - - private GetMethod doGet(URL url) throws IOException, HttpException { - HttpClient client = getClient(url); - - GetMethod get = new GetMethod(url.toExternalForm()); - get.setDoAuthentication(useAuthentication(url) || useProxyAuthentication()); - client.executeMethod(get); - return get; - } - - private HeadMethod doHead(URL url, int timeout) throws IOException, HttpException { - HttpClient client = getClient(url); - client.setTimeout(timeout); - - HeadMethod head = new HeadMethod(url.toExternalForm()); - head.setDoAuthentication(useAuthentication(url) || useProxyAuthentication()); - client.executeMethod(head); - return head; - } - - private HttpClient getClient(URL url) { - HttpClient client = new HttpClient(); - - List authPrefs = new ArrayList(2); - authPrefs.add(AuthPolicy.DIGEST); - authPrefs.add(AuthPolicy.BASIC); - // Exclude the NTLM authentication scheme because it is not supported by this class - client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); - - if (useProxy()) { - client.getHostConfiguration().setProxy(_proxyHost, _proxyPort); - if (useProxyAuthentication()) { - client.getState().setProxyCredentials(_proxyRealm, _proxyHost, - new UsernamePasswordCredentials(_proxyUserName, _proxyPasswd)); - } - } - Credentials c = getCredentials(url); - if (c != null) { - Message.debug("found credentials for " + url + ": " + c); - client.getState().setCredentials(c.getRealm(), c.getHost(), - new UsernamePasswordCredentials(c.getUserName(), c.getPasswd())); - } - return client; - } - - private boolean useProxy() { - return _proxyHost != null && _proxyHost.trim().length() > 0; - } - - private boolean useAuthentication(URL url) { - return getCredentials(url) != null; - } - - private Credentials getCredentials(URL url) { - return CredentialsStore.INSTANCE.getCredentials(null, url.getHost()); - } - - private boolean useProxyAuthentication() { - return (_proxyUserName != null && _proxyUserName.trim().length() > 0); - } - - private static final class GETInputStream extends InputStream { - private InputStream _is; - - private GetMethod _get; - - private GETInputStream(GetMethod get) throws IOException { - _get = get; - _is = get.getResponseBodyAsStream(); - } - - public int available() throws IOException { - return _is.available(); - } - - public void close() throws IOException { - _is.close(); - _get.releaseConnection(); - } - - public boolean equals(Object obj) { - return _is.equals(obj); - } - - public int hashCode() { - return _is.hashCode(); - } - - public void mark(int readlimit) { - _is.mark(readlimit); - } - - public boolean markSupported() { - return _is.markSupported(); - } - - public int read() throws IOException { - return _is.read(); - } - - public int read(byte[] b, int off, int len) throws IOException { - return _is.read(b, off, len); - } - - public int read(byte[] b) throws IOException { - return _is.read(b); - } - - public void reset() throws IOException { - _is.reset(); - } - - public long skip(long n) throws IOException { - return _is.skip(n); - } - - public String toString() { - return _is.toString(); - } - } - - private static final class HttpClientHelper3x implements HttpClientHelper { - private HttpClientHelper3x() { - } - - public long getResponseContentLength(HeadMethod head) { - return head.getResponseContentLength(); - } - - /** - * {@inheritDoc} - */ - public int getHttpClientMajorVersion() { - return 3; - } - } - - private static final class HttpClientHelper2x implements HttpClientHelper { - private HttpClientHelper2x() { - } - - public long getResponseContentLength(HeadMethod head) { - Header header = head.getResponseHeader("Content-Length"); - if (header != null) { - try { - return Integer.parseInt(header.getValue()); - } catch (NumberFormatException e) { - Message.verbose("Invalid content-length value: " + e.getMessage()); - } - } - return 0; - } - - /** - * {@inheritDoc} - */ - public int getHttpClientMajorVersion() { - return 2; - } - } - - public interface HttpClientHelper { - long getResponseContentLength(HeadMethod head); - - int getHttpClientMajorVersion(); - } -} +/* + * 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.util.url; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.UnknownHostException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthPolicy; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.ivy.util.CopyProgressListener; +import org.apache.ivy.util.Credentials; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; + +/** + * + */ +public class HttpClientHandler extends AbstractURLHandler { + private static final SimpleDateFormat LAST_MODIFIED_FORMAT = new SimpleDateFormat( + "EEE, d MMM yyyy HH:mm:ss z", Locale.US); + + // proxy configuration: obtain from system properties + private int _proxyPort; + + private String _proxyRealm = null; + + private String _proxyHost = null; + + private String _proxyUserName = null; + + private String _proxyPasswd = null; + + private HttpClientHelper _httpClientHelper; + + public HttpClientHandler() { + configureProxy(); + } + + private void configureProxy() { + _proxyRealm = null; + // no equivalent for realm in jdk proxy support ? + _proxyHost = System.getProperty("http.proxyHost"); + // TODO constant is better ... + if (useProxy()) { + _proxyPort = Integer.parseInt(System.getProperty("http.proxyPort", "80")); + _proxyUserName = System.getProperty("http.proxyUser"); + _proxyPasswd = System.getProperty("http.proxyPassword"); + // It seems there is no equivalent in HttpClient for + // 'http.nonProxyHosts' property + Message.verbose("proxy configured: host=" + _proxyHost + " port=" + _proxyPort + + " user=" + _proxyUserName); + } else { + Message.verbose("no proxy configured"); + } + } + + public InputStream openStream(URL url) throws IOException { + GetMethod get = doGet(url); + return new GETInputStream(get); + } + + public void download(URL src, File dest, CopyProgressListener l) throws IOException { + GetMethod get = doGet(src); + FileUtil.copy(get.getResponseBodyAsStream(), dest, l); + get.releaseConnection(); + } + + public URLInfo getURLInfo(URL url) { + return getURLInfo(url, 0); + } + + public URLInfo getURLInfo(URL url, int timeout) { + HeadMethod head = null; + try { + head = doHead(url, timeout); + int status = head.getStatusCode(); + head.releaseConnection(); + if (status == HttpStatus.SC_OK) { + return new URLInfo(true, getResponseContentLength(head), getLastModified(head)); + } + if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { + Message.error("Your proxy requires authentication."); + } else if (String.valueOf(status).startsWith("4")) { + Message.verbose("CLIENT ERROR: " + head.getStatusText() + " url=" + url); + } else if (String.valueOf(status).startsWith("5")) { + Message.warn("SERVER ERROR: " + head.getStatusText() + " url=" + url); + } + Message.debug("HTTP response status: " + status + "=" + head.getStatusText() + " url=" + + url); + } catch (HttpException e) { + Message.error("HttpClientHandler: " + e.getMessage() + ":" + e.getReasonCode() + "=" + + e.getReason() + " url=" + url); + } catch (UnknownHostException e) { + Message.warn("Host " + e.getMessage() + " not found. url=" + url); + Message + .info("You probably access the destination server through a proxy server that is not well configured."); + } catch (IOException e) { + Message.error("HttpClientHandler: " + e.getMessage() + " url=" + url); + } finally { + if (head != null) { + head.releaseConnection(); + } + } + return UNAVAILABLE; + } + + private long getLastModified(HeadMethod head) { + Header header = head.getResponseHeader("last-modified"); + if (header != null) { + String lastModified = header.getValue(); + try { + return LAST_MODIFIED_FORMAT.parse(lastModified).getTime(); + } catch (ParseException e) { + } + return System.currentTimeMillis(); + } else { + return System.currentTimeMillis(); + } + } + + private long getResponseContentLength(HeadMethod head) { + return getHttpClientHelper().getResponseContentLength(head); + } + + private HttpClientHelper getHttpClientHelper() { + if (_httpClientHelper == null) { + // use commons httpclient 3.0 if available + try { + HttpMethodBase.class.getMethod("getResponseContentLength", new Class[0]); + _httpClientHelper = new HttpClientHelper3x(); + Message.verbose("using commons httpclient 3.x helper"); + } catch (SecurityException e) { + Message + .verbose("unable to get access to getResponseContentLength of commons-httpclient HeadMethod. Please use commons-httpclient 3.0 or use ivy with sufficient security permissions."); + Message.verbose("exception: " + e.getMessage()); + _httpClientHelper = new HttpClientHelper2x(); + Message.verbose("using commons httpclient 2.x helper"); + } catch (NoSuchMethodException e) { + _httpClientHelper = new HttpClientHelper2x(); + Message.verbose("using commons httpclient 2.x helper"); + } + } + return _httpClientHelper; + } + + public int getHttpClientMajorVersion() { + HttpClientHelper helper = getHttpClientHelper(); + return helper.getHttpClientMajorVersion(); + } + + private GetMethod doGet(URL url) throws IOException, HttpException { + HttpClient client = getClient(url); + + GetMethod get = new GetMethod(url.toExternalForm()); + get.setDoAuthentication(useAuthentication(url) || useProxyAuthentication()); + client.executeMethod(get); + return get; + } + + private HeadMethod doHead(URL url, int timeout) throws IOException, HttpException { + HttpClient client = getClient(url); + client.setTimeout(timeout); + + HeadMethod head = new HeadMethod(url.toExternalForm()); + head.setDoAuthentication(useAuthentication(url) || useProxyAuthentication()); + client.executeMethod(head); + return head; + } + + private HttpClient getClient(URL url) { + HttpClient client = new HttpClient(); + + List authPrefs = new ArrayList(2); + authPrefs.add(AuthPolicy.DIGEST); + authPrefs.add(AuthPolicy.BASIC); + // Exclude the NTLM authentication scheme because it is not supported by this class + client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); + + if (useProxy()) { + client.getHostConfiguration().setProxy(_proxyHost, _proxyPort); + if (useProxyAuthentication()) { + client.getState().setProxyCredentials(_proxyRealm, _proxyHost, + new UsernamePasswordCredentials(_proxyUserName, _proxyPasswd)); + } + } + Credentials c = getCredentials(url); + if (c != null) { + Message.debug("found credentials for " + url + ": " + c); + client.getState().setCredentials(c.getRealm(), c.getHost(), + new UsernamePasswordCredentials(c.getUserName(), c.getPasswd())); + } + return client; + } + + private boolean useProxy() { + return _proxyHost != null && _proxyHost.trim().length() > 0; + } + + private boolean useAuthentication(URL url) { + return getCredentials(url) != null; + } + + private Credentials getCredentials(URL url) { + return CredentialsStore.INSTANCE.getCredentials(null, url.getHost()); + } + + private boolean useProxyAuthentication() { + return (_proxyUserName != null && _proxyUserName.trim().length() > 0); + } + + private static final class GETInputStream extends InputStream { + private InputStream _is; + + private GetMethod _get; + + private GETInputStream(GetMethod get) throws IOException { + _get = get; + _is = get.getResponseBodyAsStream(); + } + + public int available() throws IOException { + return _is.available(); + } + + public void close() throws IOException { + _is.close(); + _get.releaseConnection(); + } + + public boolean equals(Object obj) { + return _is.equals(obj); + } + + public int hashCode() { + return _is.hashCode(); + } + + public void mark(int readlimit) { + _is.mark(readlimit); + } + + public boolean markSupported() { + return _is.markSupported(); + } + + public int read() throws IOException { + return _is.read(); + } + + public int read(byte[] b, int off, int len) throws IOException { + return _is.read(b, off, len); + } + + public int read(byte[] b) throws IOException { + return _is.read(b); + } + + public void reset() throws IOException { + _is.reset(); + } + + public long skip(long n) throws IOException { + return _is.skip(n); + } + + public String toString() { + return _is.toString(); + } + } + + private static final class HttpClientHelper3x implements HttpClientHelper { + private HttpClientHelper3x() { + } + + public long getResponseContentLength(HeadMethod head) { + return head.getResponseContentLength(); + } + + /** + * {@inheritDoc} + */ + public int getHttpClientMajorVersion() { + return 3; + } + } + + private static final class HttpClientHelper2x implements HttpClientHelper { + private HttpClientHelper2x() { + } + + public long getResponseContentLength(HeadMethod head) { + Header header = head.getResponseHeader("Content-Length"); + if (header != null) { + try { + return Integer.parseInt(header.getValue()); + } catch (NumberFormatException e) { + Message.verbose("Invalid content-length value: " + e.getMessage()); + } + } + return 0; + } + + /** + * {@inheritDoc} + */ + public int getHttpClientMajorVersion() { + return 2; + } + } + + public interface HttpClientHelper { + long getResponseContentLength(HeadMethod head); + + int getHttpClientMajorVersion(); + } +} diff --git a/src/java/org/apache/ivy/util/url/IvyAuthenticator.java b/src/java/org/apache/ivy/util/url/IvyAuthenticator.java index 319f4852..95091c5d 100644 --- a/src/java/org/apache/ivy/util/url/IvyAuthenticator.java +++ b/src/java/org/apache/ivy/util/url/IvyAuthenticator.java @@ -1,59 +1,59 @@ -/* - * 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.util.url; - -import java.net.Authenticator; -import java.net.PasswordAuthentication; - -import org.apache.ivy.util.Credentials; -import org.apache.ivy.util.Message; - -/** - * - */ -public final class IvyAuthenticator extends Authenticator { - - /** - * The sole instance. - */ - public final static IvyAuthenticator INSTANCE = new IvyAuthenticator(); - - /** - * Private c'tor to prevent instantiation. Also installs this as the default Authenticator to - * use by the JVM. - */ - private IvyAuthenticator() { - // Install this as the default Authenticator object. - Authenticator.setDefault(this); - } - - // API ****************************************************************** - - // Overriding Authenticator ********************************************* - - protected PasswordAuthentication getPasswordAuthentication() { - Credentials c = CredentialsStore.INSTANCE.getCredentials(getRequestingPrompt(), - getRequestingHost()); - Message.debug("authentication: k='" - + Credentials.buildKey(getRequestingPrompt(), getRequestingHost()) + "' c='" + c - + "'"); - return c != null ? new PasswordAuthentication(c.getUserName(), c.getPasswd().toCharArray()) - : null; - } - -} +/* + * 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.util.url; + +import java.net.Authenticator; +import java.net.PasswordAuthentication; + +import org.apache.ivy.util.Credentials; +import org.apache.ivy.util.Message; + +/** + * + */ +public final class IvyAuthenticator extends Authenticator { + + /** + * The sole instance. + */ + public final static IvyAuthenticator INSTANCE = new IvyAuthenticator(); + + /** + * Private c'tor to prevent instantiation. Also installs this as the default Authenticator to + * use by the JVM. + */ + private IvyAuthenticator() { + // Install this as the default Authenticator object. + Authenticator.setDefault(this); + } + + // API ****************************************************************** + + // Overriding Authenticator ********************************************* + + protected PasswordAuthentication getPasswordAuthentication() { + Credentials c = CredentialsStore.INSTANCE.getCredentials(getRequestingPrompt(), + getRequestingHost()); + Message.debug("authentication: k='" + + Credentials.buildKey(getRequestingPrompt(), getRequestingHost()) + "' c='" + c + + "'"); + return c != null ? new PasswordAuthentication(c.getUserName(), c.getPasswd().toCharArray()) + : null; + } + +} diff --git a/src/java/org/apache/ivy/util/url/URLHandler.java b/src/java/org/apache/ivy/util/url/URLHandler.java index 7358357c..96c56551 100644 --- a/src/java/org/apache/ivy/util/url/URLHandler.java +++ b/src/java/org/apache/ivy/util/url/URLHandler.java @@ -1,138 +1,138 @@ -/* - * 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.util.url; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - -import org.apache.ivy.util.CopyProgressListener; - -/** - * This interface is responsible for handling some URL manipulation (stream opening, downloading, - * check reachability, ...). - */ -public interface URLHandler { - public static class URLInfo { - private long _contentLength; - - private long _lastModified; - - private boolean _available; - - protected URLInfo(boolean available, long contentLength, long lastModified) { - _available = available; - _contentLength = contentLength; - _lastModified = lastModified; - } - - public boolean isReachable() { - return _available; - } - - public long getContentLength() { - return _contentLength; - } - - public long getLastModified() { - return _lastModified; - } - } - - public static final URLInfo UNAVAILABLE = new URLInfo(false, 0, 0); - - /** - * Please prefer getURLInfo when several infos are needed. - * - * @param url - * the url to check - * @return true if the target is reachable - */ - public boolean isReachable(URL url); - - /** - * Please prefer getURLInfo when several infos are needed. - * - * @param url - * the url to check - * @return true if the target is reachable - */ - public boolean isReachable(URL url, int timeout); - - /** - * Returns the length of the target if the given url is reachable, and without error code in - * case of http urls. Please prefer getURLInfo when several infos are needed. - * - * @param url - * the url to check - * @return the length of the target if available, 0 if not reachable - */ - public long getContentLength(URL url); - - /** - * Returns the length of the target if the given url is reachable, and without error code in - * case of http urls. - * - * @param url - * the url to check - * @param timeout - * the maximum time before considering an url is not reachable a timeout of zero - * indicates no timeout - * @return the length of the target if available, 0 if not reachable - */ - public long getContentLength(URL url, int timeout); - - /** - * Please prefer getURLInfo when several infos are needed. - * - * @param url - * the url to check - * @return last modified timestamp of the given url - */ - public long getLastModified(URL url); - - /** - * Please prefer getURLInfo when several infos are needed. - * - * @param url - * the url to check - * @return last modified timestamp of the given url - */ - public long getLastModified(URL url, int timeout); - - /** - * never returns null, return UNAVAILABLE when url is not reachable - * - * @param url - * @return - */ - public URLInfo getURLInfo(URL url); - - /** - * never returns null, return UNAVAILABLE when url is not reachable - * - * @param url - * @return - */ - public URLInfo getURLInfo(URL url, int timeout); - - public InputStream openStream(URL url) throws IOException; - - public void download(URL src, File dest, CopyProgressListener l) throws IOException; -} +/* + * 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.util.url; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.apache.ivy.util.CopyProgressListener; + +/** + * This interface is responsible for handling some URL manipulation (stream opening, downloading, + * check reachability, ...). + */ +public interface URLHandler { + public static class URLInfo { + private long _contentLength; + + private long _lastModified; + + private boolean _available; + + protected URLInfo(boolean available, long contentLength, long lastModified) { + _available = available; + _contentLength = contentLength; + _lastModified = lastModified; + } + + public boolean isReachable() { + return _available; + } + + public long getContentLength() { + return _contentLength; + } + + public long getLastModified() { + return _lastModified; + } + } + + public static final URLInfo UNAVAILABLE = new URLInfo(false, 0, 0); + + /** + * Please prefer getURLInfo when several infos are needed. + * + * @param url + * the url to check + * @return true if the target is reachable + */ + public boolean isReachable(URL url); + + /** + * Please prefer getURLInfo when several infos are needed. + * + * @param url + * the url to check + * @return true if the target is reachable + */ + public boolean isReachable(URL url, int timeout); + + /** + * Returns the length of the target if the given url is reachable, and without error code in + * case of http urls. Please prefer getURLInfo when several infos are needed. + * + * @param url + * the url to check + * @return the length of the target if available, 0 if not reachable + */ + public long getContentLength(URL url); + + /** + * Returns the length of the target if the given url is reachable, and without error code in + * case of http urls. + * + * @param url + * the url to check + * @param timeout + * the maximum time before considering an url is not reachable a timeout of zero + * indicates no timeout + * @return the length of the target if available, 0 if not reachable + */ + public long getContentLength(URL url, int timeout); + + /** + * Please prefer getURLInfo when several infos are needed. + * + * @param url + * the url to check + * @return last modified timestamp of the given url + */ + public long getLastModified(URL url); + + /** + * Please prefer getURLInfo when several infos are needed. + * + * @param url + * the url to check + * @return last modified timestamp of the given url + */ + public long getLastModified(URL url, int timeout); + + /** + * never returns null, return UNAVAILABLE when url is not reachable + * + * @param url + * @return + */ + public URLInfo getURLInfo(URL url); + + /** + * never returns null, return UNAVAILABLE when url is not reachable + * + * @param url + * @return + */ + public URLInfo getURLInfo(URL url, int timeout); + + public InputStream openStream(URL url) throws IOException; + + public void download(URL src, File dest, CopyProgressListener l) throws IOException; +} diff --git a/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java b/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java index d2b1506c..f3ec0690 100644 --- a/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java +++ b/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java @@ -1,96 +1,96 @@ -/* - * 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.util.url; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import org.apache.ivy.util.CopyProgressListener; - -/** - * This class is used to dispatch downloading requests - */ -public class URLHandlerDispatcher implements URLHandler { - protected Map _handlers = new HashMap(); - - protected URLHandler _default = new BasicURLHandler(); - - public URLHandlerDispatcher() { - } - - public boolean isReachable(URL url) { - return getHandler(url.getProtocol()).isReachable(url); - } - - public boolean isReachable(URL url, int timeout) { - return getHandler(url.getProtocol()).isReachable(url, timeout); - } - - public long getContentLength(URL url) { - return getHandler(url.getProtocol()).getContentLength(url); - } - - public long getContentLength(URL url, int timeout) { - return getHandler(url.getProtocol()).getContentLength(url, timeout); - } - - public long getLastModified(URL url) { - return getHandler(url.getProtocol()).getLastModified(url); - } - - public long getLastModified(URL url, int timeout) { - return getHandler(url.getProtocol()).getLastModified(url, timeout); - } - - public URLInfo getURLInfo(URL url) { - return getHandler(url.getProtocol()).getURLInfo(url); - } - - public URLInfo getURLInfo(URL url, int timeout) { - return getHandler(url.getProtocol()).getURLInfo(url, timeout); - } - - public InputStream openStream(URL url) throws IOException { - return getHandler(url.getProtocol()).openStream(url); - } - - public void download(URL src, File dest, CopyProgressListener l) throws IOException { - getHandler(src.getProtocol()).download(src, dest, l); - } - - public void setDownloader(String protocol, URLHandler downloader) { - _handlers.put(protocol, downloader); - } - - public URLHandler getHandler(String protocol) { - URLHandler downloader = (URLHandler) _handlers.get(protocol); - return downloader == null ? _default : downloader; - } - - public URLHandler getDefault() { - return _default; - } - - public void setDefault(URLHandler default1) { - _default = default1; - } -} +/* + * 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.util.url; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.apache.ivy.util.CopyProgressListener; + +/** + * This class is used to dispatch downloading requests + */ +public class URLHandlerDispatcher implements URLHandler { + protected Map _handlers = new HashMap(); + + protected URLHandler _default = new BasicURLHandler(); + + public URLHandlerDispatcher() { + } + + public boolean isReachable(URL url) { + return getHandler(url.getProtocol()).isReachable(url); + } + + public boolean isReachable(URL url, int timeout) { + return getHandler(url.getProtocol()).isReachable(url, timeout); + } + + public long getContentLength(URL url) { + return getHandler(url.getProtocol()).getContentLength(url); + } + + public long getContentLength(URL url, int timeout) { + return getHandler(url.getProtocol()).getContentLength(url, timeout); + } + + public long getLastModified(URL url) { + return getHandler(url.getProtocol()).getLastModified(url); + } + + public long getLastModified(URL url, int timeout) { + return getHandler(url.getProtocol()).getLastModified(url, timeout); + } + + public URLInfo getURLInfo(URL url) { + return getHandler(url.getProtocol()).getURLInfo(url); + } + + public URLInfo getURLInfo(URL url, int timeout) { + return getHandler(url.getProtocol()).getURLInfo(url, timeout); + } + + public InputStream openStream(URL url) throws IOException { + return getHandler(url.getProtocol()).openStream(url); + } + + public void download(URL src, File dest, CopyProgressListener l) throws IOException { + getHandler(src.getProtocol()).download(src, dest, l); + } + + public void setDownloader(String protocol, URLHandler downloader) { + _handlers.put(protocol, downloader); + } + + public URLHandler getHandler(String protocol) { + URLHandler downloader = (URLHandler) _handlers.get(protocol); + return downloader == null ? _default : downloader; + } + + public URLHandler getDefault() { + return _default; + } + + public void setDefault(URLHandler default1) { + _default = default1; + } +} diff --git a/src/java/org/apache/ivy/util/url/URLHandlerRegistry.java b/src/java/org/apache/ivy/util/url/URLHandlerRegistry.java index 110a3098..9af4f40c 100644 --- a/src/java/org/apache/ivy/util/url/URLHandlerRegistry.java +++ b/src/java/org/apache/ivy/util/url/URLHandlerRegistry.java @@ -1,65 +1,65 @@ -/* - * 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.util.url; - -import org.apache.ivy.util.Message; - -/** - * - */ -public class URLHandlerRegistry { - private static URLHandler _default = new BasicURLHandler(); - - public static URLHandler getDefault() { - return _default; - } - - public static void setDefault(URLHandler def) { - _default = def; - } - - /** - * This method is used to get appropriate http downloader dependening on Jakarta Commons - * HttpClient availability in classpath, or simply use jdk url handling in other cases. - * - * @return most accurate http downloader - */ - public static URLHandler getHttp() { - try { - Class.forName("org.apache.commons.httpclient.HttpClient"); - Class handler = Class.forName("org.apache.ivy.util.url.HttpClientHandler"); - Message.verbose("jakarta commons httpclient detected: using it for http downloading"); - return (URLHandler) handler.newInstance(); - } catch (ClassNotFoundException e) { - Message.verbose("jakarta commons httpclient not found: using jdk url handling"); - return new BasicURLHandler(); - } catch (NoClassDefFoundError e) { - Message.verbose("error occurred while loading jakarta commons httpclient: " - + e.getMessage()); - Message.verbose("Using jdk url handling instead."); - return new BasicURLHandler(); - } catch (InstantiationException e) { - Message.verbose("couldn't instantiate HttpClientHandler: using jdk url handling"); - return new BasicURLHandler(); - } catch (IllegalAccessException e) { - Message.verbose("couldn't instantiate HttpClientHandler: using jdk url handling"); - return new BasicURLHandler(); - } - } - -} +/* + * 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.util.url; + +import org.apache.ivy.util.Message; + +/** + * + */ +public class URLHandlerRegistry { + private static URLHandler _default = new BasicURLHandler(); + + public static URLHandler getDefault() { + return _default; + } + + public static void setDefault(URLHandler def) { + _default = def; + } + + /** + * This method is used to get appropriate http downloader dependening on Jakarta Commons + * HttpClient availability in classpath, or simply use jdk url handling in other cases. + * + * @return most accurate http downloader + */ + public static URLHandler getHttp() { + try { + Class.forName("org.apache.commons.httpclient.HttpClient"); + Class handler = Class.forName("org.apache.ivy.util.url.HttpClientHandler"); + Message.verbose("jakarta commons httpclient detected: using it for http downloading"); + return (URLHandler) handler.newInstance(); + } catch (ClassNotFoundException e) { + Message.verbose("jakarta commons httpclient not found: using jdk url handling"); + return new BasicURLHandler(); + } catch (NoClassDefFoundError e) { + Message.verbose("error occurred while loading jakarta commons httpclient: " + + e.getMessage()); + Message.verbose("Using jdk url handling instead."); + return new BasicURLHandler(); + } catch (InstantiationException e) { + Message.verbose("couldn't instantiate HttpClientHandler: using jdk url handling"); + return new BasicURLHandler(); + } catch (IllegalAccessException e) { + Message.verbose("couldn't instantiate HttpClientHandler: using jdk url handling"); + return new BasicURLHandler(); + } + } + +} diff --git a/test/buildlist/A/build.xml b/test/buildlist/A/build.xml index 84312b7a..1c1b8cf7 100644 --- a/test/buildlist/A/build.xml +++ b/test/buildlist/A/build.xml @@ -1,18 +1,18 @@ - + diff --git a/test/buildlist/A/ivy.xml b/test/buildlist/A/ivy.xml index 86d92e3f..d729c8f7 100644 --- a/test/buildlist/A/ivy.xml +++ b/test/buildlist/A/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/buildlist/B/build.xml b/test/buildlist/B/build.xml index 84312b7a..1c1b8cf7 100644 --- a/test/buildlist/B/build.xml +++ b/test/buildlist/B/build.xml @@ -1,18 +1,18 @@ - + diff --git a/test/buildlist/B/ivy.xml b/test/buildlist/B/ivy.xml index a690d9bf..8db38655 100644 --- a/test/buildlist/B/ivy.xml +++ b/test/buildlist/B/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/buildlist/C/build.xml b/test/buildlist/C/build.xml index 84312b7a..1c1b8cf7 100644 --- a/test/buildlist/C/build.xml +++ b/test/buildlist/C/build.xml @@ -1,18 +1,18 @@ - + diff --git a/test/buildlist/C/ivy.xml b/test/buildlist/C/ivy.xml index 6b39cee9..c6793ac2 100644 --- a/test/buildlist/C/ivy.xml +++ b/test/buildlist/C/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/buildlist/D/build.xml b/test/buildlist/D/build.xml index 84312b7a..1c1b8cf7 100644 --- a/test/buildlist/D/build.xml +++ b/test/buildlist/D/build.xml @@ -1,18 +1,18 @@ - + diff --git a/test/buildlist/D/ivy.xml b/test/buildlist/D/ivy.xml index 8e9811ef..029b60ac 100644 --- a/test/buildlist/D/ivy.xml +++ b/test/buildlist/D/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/buildlist/E/build.xml b/test/buildlist/E/build.xml index 84312b7a..1c1b8cf7 100644 --- a/test/buildlist/E/build.xml +++ b/test/buildlist/E/build.xml @@ -1,18 +1,18 @@ - + diff --git a/test/buildlist/E/ivy.xml b/test/buildlist/E/ivy.xml index 2335471a..a46e6676 100644 --- a/test/buildlist/E/ivy.xml +++ b/test/buildlist/E/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/custom-classpath/org/apache/ivy/plugins/resolver/CustomResolver.java b/test/custom-classpath/org/apache/ivy/plugins/resolver/CustomResolver.java index 03c40b4a..c64588ad 100644 --- a/test/custom-classpath/org/apache/ivy/plugins/resolver/CustomResolver.java +++ b/test/custom-classpath/org/apache/ivy/plugins/resolver/CustomResolver.java @@ -1,29 +1,29 @@ -/* - * 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; - -/** - * This custom resolver is only used to test custom classpath, and has absolutely - * no interest in itself - * - * @author Xavier Hanin - * - */ -public class CustomResolver extends IBiblioResolver { - -} +/* + * 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; + +/** + * This custom resolver is only used to test custom classpath, and has absolutely + * no interest in itself + * + * @author Xavier Hanin + * + */ +public class CustomResolver extends IBiblioResolver { + +} diff --git a/test/java/org/apache/ivy/TestHelper.java b/test/java/org/apache/ivy/TestHelper.java index 9e5a4274..6d996e34 100644 --- a/test/java/org/apache/ivy/TestHelper.java +++ b/test/java/org/apache/ivy/TestHelper.java @@ -1,41 +1,41 @@ -/* - * 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; - -import java.io.File; -import java.util.Date; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class TestHelper { - - public static File getArchiveFileInCache(Ivy ivy, File cache, String organisation, - String module, String revision, String artifact, String type, String ext) { - return getArchiveFileInCache(ivy.getCacheManager(cache), organisation, module, revision, - artifact, type, ext); - } - - public static File getArchiveFileInCache(CacheManager cacheManager, String organisation, - String module, String revision, String artifact, String type, String ext) { - return cacheManager.getArchiveFileInCache(new DefaultArtifact(ModuleRevisionId.newInstance( - organisation, module, revision), new Date(), artifact, type, ext)); - } - -} +/* + * 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; + +import java.io.File; +import java.util.Date; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class TestHelper { + + public static File getArchiveFileInCache(Ivy ivy, File cache, String organisation, + String module, String revision, String artifact, String type, String ext) { + return getArchiveFileInCache(ivy.getCacheManager(cache), organisation, module, revision, + artifact, type, ext); + } + + public static File getArchiveFileInCache(CacheManager cacheManager, String organisation, + String module, String revision, String artifact, String type, String ext) { + return cacheManager.getArchiveFileInCache(new DefaultArtifact(ModuleRevisionId.newInstance( + organisation, module, revision), new Date(), artifact, type, ext)); + } + +} diff --git a/test/java/org/apache/ivy/ant/AntBuildTriggerTest.java b/test/java/org/apache/ivy/ant/AntBuildTriggerTest.java index 15e671a8..50a9fcbb 100644 --- a/test/java/org/apache/ivy/ant/AntBuildTriggerTest.java +++ b/test/java/org/apache/ivy/ant/AntBuildTriggerTest.java @@ -1,46 +1,46 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.util.FileUtil; - -public class AntBuildTriggerTest extends TestCase { - public void test() throws Exception { - assertFalse(new File("test/triggers/ant-build/A/A.jar").exists()); - - Ivy ivy = new Ivy(); - ivy.configure(new File("test/triggers/ant-build/ivysettings.xml")); - - ResolveReport r = ivy.resolve(new File("test/triggers/ant-build/B/ivy.xml")); - assertFalse(r.hasError()); - - // should have triggered an A publish - assertTrue(new File("test/triggers/ant-build/local/A/A.jar").exists()); - } - - protected void tearDown() throws Exception { - FileUtil.forceDelete(new File("test/triggers/ant-build/local/A")); - FileUtil.forceDelete(new File("test/triggers/ant-build/cache")); - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.util.FileUtil; + +public class AntBuildTriggerTest extends TestCase { + public void test() throws Exception { + assertFalse(new File("test/triggers/ant-build/A/A.jar").exists()); + + Ivy ivy = new Ivy(); + ivy.configure(new File("test/triggers/ant-build/ivysettings.xml")); + + ResolveReport r = ivy.resolve(new File("test/triggers/ant-build/B/ivy.xml")); + assertFalse(r.hasError()); + + // should have triggered an A publish + assertTrue(new File("test/triggers/ant-build/local/A/A.jar").exists()); + } + + protected void tearDown() throws Exception { + FileUtil.forceDelete(new File("test/triggers/ant-build/local/A")); + FileUtil.forceDelete(new File("test/triggers/ant-build/cache")); + } +} diff --git a/test/java/org/apache/ivy/ant/AntCallTriggerTest.java b/test/java/org/apache/ivy/ant/AntCallTriggerTest.java index 8c1d4807..3f1ecc18 100644 --- a/test/java/org/apache/ivy/ant/AntCallTriggerTest.java +++ b/test/java/org/apache/ivy/ant/AntCallTriggerTest.java @@ -1,223 +1,223 @@ -/* - * 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.InputStream; -import java.io.PrintStream; -import java.util.Vector; - -import junit.framework.TestCase; - -import org.apache.ivy.util.FileUtil; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.BuildLogger; -import org.apache.tools.ant.DefaultLogger; -import org.apache.tools.ant.DemuxInputStream; -import org.apache.tools.ant.DemuxOutputStream; -import org.apache.tools.ant.Main; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; -import org.apache.tools.ant.input.DefaultInputHandler; -import org.apache.tools.ant.input.InputHandler; - -public class AntCallTriggerTest extends TestCase { - public void test() throws Exception { - assertFalse(new File("test/triggers/ant-call/A/out/foo.txt").exists()); - runAnt(new File("test/triggers/ant-call/A/build.xml"), "resolve"); - // should have unzipped foo.zip - assertTrue(new File("test/triggers/ant-call/A/out/foo.txt").exists()); - } - - protected void tearDown() throws Exception { - FileUtil.forceDelete(new File("test/triggers/ant-call/A/out")); - FileUtil.forceDelete(new File("test/triggers/ant-call/cache")); - } - - private void runAnt(File buildFile, String target) throws BuildException { - runAnt(buildFile, target, Project.MSG_INFO); - } - - private void runAnt(File buildFile, String target, int messageLevel) throws BuildException { - Vector targets = new Vector(); - targets.add(target); - runAnt(buildFile, targets, messageLevel); - } - - private void runAnt(File buildFile, Vector targets, int messageLevel) throws BuildException { - runBuild(buildFile, targets, messageLevel); - - // this exits the jvm at the end of the call - // Main.main(new String[] {"-f", buildFile.getAbsolutePath(), target}); - - // this does not set the good message level - // Ant ant = new Ant(); - // Project project = new Project(); - // project.setBaseDir(buildFile.getParentFile()); - // project.init(); - // - // ant.setProject(project); - // ant.setTaskName("ant"); - // - // ant.setAntfile(buildFile.getAbsolutePath()); - // ant.setInheritAll(false); - // if (target != null) { - // ant.setTarget(target); - // } - // ant.execute(); - } - - // //////////////////////////////////////////////////////////////////////////// - // miserable copy (updated to simple test cases) from ant Main class: - // the only available way I found to easily run ant exits jvm at the end - private void runBuild(File buildFile, Vector targets, int messageLevel) throws BuildException { - - final Project project = new Project(); - project.setCoreLoader(null); - - Throwable error = null; - - try { - addBuildListeners(project, messageLevel); - addInputHandler(project, null); - - PrintStream err = System.err; - PrintStream out = System.out; - InputStream in = System.in; - - // use a system manager that prevents from System.exit() - SecurityManager oldsm = null; - oldsm = System.getSecurityManager(); - - // SecurityManager can not be installed here for backwards - // compatibility reasons (PD). Needs to be loaded prior to - // ant class if we are going to implement it. - // System.setSecurityManager(new NoExitSecurityManager()); - try { - project.setDefaultInputStream(System.in); - System.setIn(new DemuxInputStream(project)); - System.setOut(new PrintStream(new DemuxOutputStream(project, false))); - System.setErr(new PrintStream(new DemuxOutputStream(project, true))); - - project.fireBuildStarted(); - - project.init(); - project.setUserProperty("ant.version", Main.getAntVersion()); - - project.setUserProperty("ant.file", buildFile.getAbsolutePath()); - - ProjectHelper.configureProject(project, buildFile); - - // make sure that we have a target to execute - if (targets.size() == 0) { - if (project.getDefaultTarget() != null) { - targets.addElement(project.getDefaultTarget()); - } - } - - project.executeTargets(targets); - } finally { - // put back the original security manager - // The following will never eval to true. (PD) - if (oldsm != null) { - System.setSecurityManager(oldsm); - } - - System.setOut(out); - System.setErr(err); - System.setIn(in); - } - } catch (RuntimeException exc) { - error = exc; - throw exc; - } catch (Error err) { - error = err; - throw err; - } finally { - project.fireBuildFinished(error); - } - } - - /** - * Adds the listeners specified in the command line arguments, along with the default listener, - * to the specified project. - * - * @param project - * The project to add listeners to. Must not be null. - */ - protected void addBuildListeners(Project project, int level) { - - // Add the default listener - project.addBuildListener(createLogger(level)); - - } - - /** - * Creates the InputHandler and adds it to the project. - * - * @param project - * the project instance. - * @param inputHandlerClassname - * @exception BuildException - * if a specified InputHandler implementation could not be loaded. - */ - private void addInputHandler(Project project, String inputHandlerClassname) - throws BuildException { - InputHandler handler = null; - if (inputHandlerClassname == null) { - handler = new DefaultInputHandler(); - } else { - try { - handler = (InputHandler) (Class.forName(inputHandlerClassname).newInstance()); - if (project != null) { - project.setProjectReference(handler); - } - } catch (ClassCastException e) { - String msg = "The specified input handler class " + inputHandlerClassname - + " does not implement the InputHandler interface"; - throw new BuildException(msg); - } catch (Exception e) { - String msg = "Unable to instantiate specified input handler " + "class " - + inputHandlerClassname + " : " + e.getClass().getName(); - throw new BuildException(msg); - } - } - project.setInputHandler(handler); - } - - // XXX: (Jon Skeet) Any reason for writing a message and then using a bare - // RuntimeException rather than just using a BuildException here? Is it - // in case the message could end up being written to no loggers (as the - // loggers could have failed to be created due to this failure)? - /** - * Creates the default build logger for sending build events to the ant log. - * - * @return the logger instance for this build. - */ - private BuildLogger createLogger(int level) { - BuildLogger logger = null; - logger = new DefaultLogger(); - - logger.setMessageOutputLevel(level); - logger.setOutputPrintStream(System.out); - logger.setErrorPrintStream(System.err); - - return logger; - } - -} +/* + * 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.InputStream; +import java.io.PrintStream; +import java.util.Vector; + +import junit.framework.TestCase; + +import org.apache.ivy.util.FileUtil; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildLogger; +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.DemuxInputStream; +import org.apache.tools.ant.DemuxOutputStream; +import org.apache.tools.ant.Main; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectHelper; +import org.apache.tools.ant.input.DefaultInputHandler; +import org.apache.tools.ant.input.InputHandler; + +public class AntCallTriggerTest extends TestCase { + public void test() throws Exception { + assertFalse(new File("test/triggers/ant-call/A/out/foo.txt").exists()); + runAnt(new File("test/triggers/ant-call/A/build.xml"), "resolve"); + // should have unzipped foo.zip + assertTrue(new File("test/triggers/ant-call/A/out/foo.txt").exists()); + } + + protected void tearDown() throws Exception { + FileUtil.forceDelete(new File("test/triggers/ant-call/A/out")); + FileUtil.forceDelete(new File("test/triggers/ant-call/cache")); + } + + private void runAnt(File buildFile, String target) throws BuildException { + runAnt(buildFile, target, Project.MSG_INFO); + } + + private void runAnt(File buildFile, String target, int messageLevel) throws BuildException { + Vector targets = new Vector(); + targets.add(target); + runAnt(buildFile, targets, messageLevel); + } + + private void runAnt(File buildFile, Vector targets, int messageLevel) throws BuildException { + runBuild(buildFile, targets, messageLevel); + + // this exits the jvm at the end of the call + // Main.main(new String[] {"-f", buildFile.getAbsolutePath(), target}); + + // this does not set the good message level + // Ant ant = new Ant(); + // Project project = new Project(); + // project.setBaseDir(buildFile.getParentFile()); + // project.init(); + // + // ant.setProject(project); + // ant.setTaskName("ant"); + // + // ant.setAntfile(buildFile.getAbsolutePath()); + // ant.setInheritAll(false); + // if (target != null) { + // ant.setTarget(target); + // } + // ant.execute(); + } + + // //////////////////////////////////////////////////////////////////////////// + // miserable copy (updated to simple test cases) from ant Main class: + // the only available way I found to easily run ant exits jvm at the end + private void runBuild(File buildFile, Vector targets, int messageLevel) throws BuildException { + + final Project project = new Project(); + project.setCoreLoader(null); + + Throwable error = null; + + try { + addBuildListeners(project, messageLevel); + addInputHandler(project, null); + + PrintStream err = System.err; + PrintStream out = System.out; + InputStream in = System.in; + + // use a system manager that prevents from System.exit() + SecurityManager oldsm = null; + oldsm = System.getSecurityManager(); + + // SecurityManager can not be installed here for backwards + // compatibility reasons (PD). Needs to be loaded prior to + // ant class if we are going to implement it. + // System.setSecurityManager(new NoExitSecurityManager()); + try { + project.setDefaultInputStream(System.in); + System.setIn(new DemuxInputStream(project)); + System.setOut(new PrintStream(new DemuxOutputStream(project, false))); + System.setErr(new PrintStream(new DemuxOutputStream(project, true))); + + project.fireBuildStarted(); + + project.init(); + project.setUserProperty("ant.version", Main.getAntVersion()); + + project.setUserProperty("ant.file", buildFile.getAbsolutePath()); + + ProjectHelper.configureProject(project, buildFile); + + // make sure that we have a target to execute + if (targets.size() == 0) { + if (project.getDefaultTarget() != null) { + targets.addElement(project.getDefaultTarget()); + } + } + + project.executeTargets(targets); + } finally { + // put back the original security manager + // The following will never eval to true. (PD) + if (oldsm != null) { + System.setSecurityManager(oldsm); + } + + System.setOut(out); + System.setErr(err); + System.setIn(in); + } + } catch (RuntimeException exc) { + error = exc; + throw exc; + } catch (Error err) { + error = err; + throw err; + } finally { + project.fireBuildFinished(error); + } + } + + /** + * Adds the listeners specified in the command line arguments, along with the default listener, + * to the specified project. + * + * @param project + * The project to add listeners to. Must not be null. + */ + protected void addBuildListeners(Project project, int level) { + + // Add the default listener + project.addBuildListener(createLogger(level)); + + } + + /** + * Creates the InputHandler and adds it to the project. + * + * @param project + * the project instance. + * @param inputHandlerClassname + * @exception BuildException + * if a specified InputHandler implementation could not be loaded. + */ + private void addInputHandler(Project project, String inputHandlerClassname) + throws BuildException { + InputHandler handler = null; + if (inputHandlerClassname == null) { + handler = new DefaultInputHandler(); + } else { + try { + handler = (InputHandler) (Class.forName(inputHandlerClassname).newInstance()); + if (project != null) { + project.setProjectReference(handler); + } + } catch (ClassCastException e) { + String msg = "The specified input handler class " + inputHandlerClassname + + " does not implement the InputHandler interface"; + throw new BuildException(msg); + } catch (Exception e) { + String msg = "Unable to instantiate specified input handler " + "class " + + inputHandlerClassname + " : " + e.getClass().getName(); + throw new BuildException(msg); + } + } + project.setInputHandler(handler); + } + + // XXX: (Jon Skeet) Any reason for writing a message and then using a bare + // RuntimeException rather than just using a BuildException here? Is it + // in case the message could end up being written to no loggers (as the + // loggers could have failed to be created due to this failure)? + /** + * Creates the default build logger for sending build events to the ant log. + * + * @return the logger instance for this build. + */ + private BuildLogger createLogger(int level) { + BuildLogger logger = null; + logger = new DefaultLogger(); + + logger.setMessageOutputLevel(level); + logger.setOutputPrintStream(System.out); + logger.setErrorPrintStream(System.err); + + return logger; + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyArtifactPropertyTest.java b/test/java/org/apache/ivy/ant/IvyArtifactPropertyTest.java index 582b8a0f..7cb94a53 100644 --- a/test/java/org/apache/ivy/ant/IvyArtifactPropertyTest.java +++ b/test/java/org/apache/ivy/ant/IvyArtifactPropertyTest.java @@ -1,107 +1,107 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyArtifactPropertyTest extends TestCase { - private File _cache; - - private IvyArtifactProperty _prop; - - private Project _project; - - protected void setUp() throws Exception { - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _prop = new IvyArtifactProperty(); - _prop.setProject(_project); - _prop.setCache(_cache); - } - - 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(); - } - - public void testSimple() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - _prop.setName("[module].[artifact]-[revision]"); - _prop.setValue("${cache.dir}/[module]/[artifact]-[revision].[type]"); - _prop.execute(); - String val = _project.getProperty("mod1.2.mod1.2-2.0"); - assertNotNull(val); - assertEquals("build/cache/mod1.2/mod1.2-2.0.jar", val); - } - - public void testWithResolveId() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setResolveId("abc"); - resolve.execute(); - - // resolve another ivy file - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - _prop.setName("[module].[artifact]-[revision]"); - _prop.setValue("${cache.dir}/[module]/[artifact]-[revision].[type]"); - _prop.setResolveId("abc"); - _prop.execute(); - - String val = _project.getProperty("mod1.2.mod1.2-2.0"); - assertNotNull(val); - assertEquals("build/cache/mod1.2/mod1.2-2.0.jar", val); - } - - public void testWithResolveIdWithoutResolve() throws Exception { - try { - _prop.setName("[module].[artifact]-[revision]"); - _prop.setValue("${cache.dir}/[module]/[artifact]-[revision].[type]"); - _prop.setResolveId("abc"); - _prop.execute(); - fail("Task should have failed because no resolve was performed!"); - } catch (BuildException e) { - // this is expected! - } - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyArtifactPropertyTest extends TestCase { + private File _cache; + + private IvyArtifactProperty _prop; + + private Project _project; + + protected void setUp() throws Exception { + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _prop = new IvyArtifactProperty(); + _prop.setProject(_project); + _prop.setCache(_cache); + } + + 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(); + } + + public void testSimple() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + _prop.setName("[module].[artifact]-[revision]"); + _prop.setValue("${cache.dir}/[module]/[artifact]-[revision].[type]"); + _prop.execute(); + String val = _project.getProperty("mod1.2.mod1.2-2.0"); + assertNotNull(val); + assertEquals("build/cache/mod1.2/mod1.2-2.0.jar", val); + } + + public void testWithResolveId() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setResolveId("abc"); + resolve.execute(); + + // resolve another ivy file + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + _prop.setName("[module].[artifact]-[revision]"); + _prop.setValue("${cache.dir}/[module]/[artifact]-[revision].[type]"); + _prop.setResolveId("abc"); + _prop.execute(); + + String val = _project.getProperty("mod1.2.mod1.2-2.0"); + assertNotNull(val); + assertEquals("build/cache/mod1.2/mod1.2-2.0.jar", val); + } + + public void testWithResolveIdWithoutResolve() throws Exception { + try { + _prop.setName("[module].[artifact]-[revision]"); + _prop.setValue("${cache.dir}/[module]/[artifact]-[revision].[type]"); + _prop.setResolveId("abc"); + _prop.execute(); + fail("Task should have failed because no resolve was performed!"); + } catch (BuildException e) { + // this is expected! + } + } +} diff --git a/test/java/org/apache/ivy/ant/IvyArtifactReportTest.java b/test/java/org/apache/ivy/ant/IvyArtifactReportTest.java index 884ac8a2..ffb7f64a 100644 --- a/test/java/org/apache/ivy/ant/IvyArtifactReportTest.java +++ b/test/java/org/apache/ivy/ant/IvyArtifactReportTest.java @@ -1,67 +1,67 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyArtifactReportTest extends TestCase { - private File _cache; - - private IvyArtifactReport _prop; - - private Project _project; - - protected void setUp() throws Exception { - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _prop = new IvyArtifactReport(); - _prop.setProject(_project); - _prop.setCache(_cache); - } - - 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(); - } - - public void testSimple() throws Exception { - _prop.setTofile(new File("build/test-artifact-report.xml")); - _prop.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _prop.execute(); - - assertTrue(new File("build/test-artifact-report.xml").exists()); - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyArtifactReportTest extends TestCase { + private File _cache; + + private IvyArtifactReport _prop; + + private Project _project; + + protected void setUp() throws Exception { + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _prop = new IvyArtifactReport(); + _prop.setProject(_project); + _prop.setCache(_cache); + } + + 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(); + } + + public void testSimple() throws Exception { + _prop.setTofile(new File("build/test-artifact-report.xml")); + _prop.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _prop.execute(); + + assertTrue(new File("build/test-artifact-report.xml").exists()); + } +} diff --git a/test/java/org/apache/ivy/ant/IvyBuildListTest.java b/test/java/org/apache/ivy/ant/IvyBuildListTest.java index 2f68be1f..79416095 100644 --- a/test/java/org/apache/ivy/ant/IvyBuildListTest.java +++ b/test/java/org/apache/ivy/ant/IvyBuildListTest.java @@ -1,297 +1,297 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Path; - -public class IvyBuildListTest extends TestCase { - - public void testSimple() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(5, files.length); - - assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[2]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[3]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[4]) - .getAbsolutePath()); - } - - public void testReverse() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - buildlist.setReverse(true); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("reverse.ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("reverse.ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(5, files.length); - - assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[1]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[2]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[3]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[4]) - .getAbsolutePath()); - } - - public void testWithRoot() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - buildlist.setRoot("C"); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(2, files.length); // A and D should be filtered out - - assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]) - .getAbsolutePath()); - } - - public void testWithTwoRoots() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - buildlist.setRoot("C,E"); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(3, files.length); // A and D should be filtered out - - assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[2]) - .getAbsolutePath()); - } - - public void testWithRootExclude() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - buildlist.setRoot("C"); - buildlist.setExcludeRoot(true); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(1, files.length); // A, D and C should be filtered out - - assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - } - - public void testWithLeaf() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - buildlist.setLeaf("C"); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(3, files.length); // B should be filtered out - - assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[1]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[2]) - .getAbsolutePath()); - } - - public void testWithTwoLeafs() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - buildlist.setLeaf("C,E"); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(4, files.length); // B should be filtered out - - assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[1]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[2]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[3]) - .getAbsolutePath()); - } - - public void testWithLeafExclude() { - Project p = new Project(); - - IvyBuildList buildlist = new IvyBuildList(); - buildlist.setProject(p); - buildlist.setLeaf("C"); - buildlist.setExcludeLeaf(true); - - FileSet fs = new FileSet(); - fs.setDir(new File("test/buildlist")); - fs.setIncludes("**/build.xml"); - buildlist.addFileset(fs); - - buildlist.setReference("ordered.build.files"); - - buildlist.execute(); - - Object o = p.getReference("ordered.build.files"); - assertNotNull(o); - assertTrue(o instanceof Path); - - Path path = (Path) o; - String[] files = path.list(); - assertNotNull(files); - assertEquals(2, files.length); // B and C should be filtered out - - assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[0]) - .getAbsolutePath()); - assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[1]) - .getAbsolutePath()); - } - -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Path; + +public class IvyBuildListTest extends TestCase { + + public void testSimple() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(5, files.length); + + assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[2]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[3]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[4]) + .getAbsolutePath()); + } + + public void testReverse() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + buildlist.setReverse(true); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("reverse.ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("reverse.ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(5, files.length); + + assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[1]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[2]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[3]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[4]) + .getAbsolutePath()); + } + + public void testWithRoot() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + buildlist.setRoot("C"); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(2, files.length); // A and D should be filtered out + + assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]) + .getAbsolutePath()); + } + + public void testWithTwoRoots() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + buildlist.setRoot("C,E"); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(3, files.length); // A and D should be filtered out + + assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[2]) + .getAbsolutePath()); + } + + public void testWithRootExclude() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + buildlist.setRoot("C"); + buildlist.setExcludeRoot(true); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(1, files.length); // A, D and C should be filtered out + + assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + } + + public void testWithLeaf() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + buildlist.setLeaf("C"); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(3, files.length); // B should be filtered out + + assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[1]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[2]) + .getAbsolutePath()); + } + + public void testWithTwoLeafs() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + buildlist.setLeaf("C,E"); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(4, files.length); // B should be filtered out + + assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[1]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[2]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[3]) + .getAbsolutePath()); + } + + public void testWithLeafExclude() { + Project p = new Project(); + + IvyBuildList buildlist = new IvyBuildList(); + buildlist.setProject(p); + buildlist.setLeaf("C"); + buildlist.setExcludeLeaf(true); + + FileSet fs = new FileSet(); + fs.setDir(new File("test/buildlist")); + fs.setIncludes("**/build.xml"); + buildlist.addFileset(fs); + + buildlist.setReference("ordered.build.files"); + + buildlist.execute(); + + Object o = p.getReference("ordered.build.files"); + assertNotNull(o); + assertTrue(o instanceof Path); + + Path path = (Path) o; + String[] files = path.list(); + assertNotNull(files); + assertEquals(2, files.length); // B and C should be filtered out + + assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[0]) + .getAbsolutePath()); + assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[1]) + .getAbsolutePath()); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyBuildNumberTest.java b/test/java/org/apache/ivy/ant/IvyBuildNumberTest.java index d32985bf..09f988e9 100644 --- a/test/java/org/apache/ivy/ant/IvyBuildNumberTest.java +++ b/test/java/org/apache/ivy/ant/IvyBuildNumberTest.java @@ -1,164 +1,164 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyBuildNumberTest extends TestCase { - private File _cache; - - private IvyBuildNumber _buildNumber; - - protected void setUp() throws Exception { - createCache(); - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _buildNumber = new IvyBuildNumber(); - _buildNumber.setProject(project); - } - - 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(); - } - - public void testDefault() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("newmod"); - _buildNumber.execute(); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("0", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("0", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testDefault2() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("newmod"); - _buildNumber.setDefault("1.0-dev-1"); - _buildNumber.execute(); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("1.0-dev-1", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testDefault3() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("newmod"); - _buildNumber.setDefault("mydefault"); - _buildNumber.execute(); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("mydefault", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testLatest() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("mod1.1"); - _buildNumber.execute(); - assertEquals("2.0", _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("2.1", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals("0", _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testLatest2() throws Exception { - _buildNumber.setOrganisation("orgbn"); - _buildNumber.setModule("buildnumber"); - _buildNumber.execute(); - assertEquals("test", _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("test.1", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testPrefix() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("mod1.1"); - _buildNumber.setPrefix("test"); - _buildNumber.execute(); - assertEquals("2.0", _buildNumber.getProject().getProperty("test.revision")); - assertEquals("2.1", _buildNumber.getProject().getProperty("test.new.revision")); - assertEquals("0", _buildNumber.getProject().getProperty("test.build.number")); - assertEquals("1", _buildNumber.getProject().getProperty("test.new.build.number")); - } - - public void testBuildNumber() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("mod1.1"); - _buildNumber.setRevision("1."); - _buildNumber.execute(); - assertEquals("1.1", _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("1.2", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals("1", _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("2", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testBuildNumber2() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("mod1.5"); - _buildNumber.setRevision("1."); - _buildNumber.execute(); - assertEquals("1.0.2", _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("1.1", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals("0", _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testBuildNumber3() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("mod1.1"); - _buildNumber.setRevision("1.1"); - _buildNumber.execute(); - assertEquals("1.1", _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("1.1.1", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - - public void testBuildNumber4() throws Exception { - _buildNumber.setOrganisation("org1"); - _buildNumber.setModule("mod1.1"); - _buildNumber.setRevision("3."); - _buildNumber.execute(); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); - assertEquals("3.0", _buildNumber.getProject().getProperty("ivy.new.revision")); - assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); - assertEquals("0", _buildNumber.getProject().getProperty("ivy.new.build.number")); - } - -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyBuildNumberTest extends TestCase { + private File _cache; + + private IvyBuildNumber _buildNumber; + + protected void setUp() throws Exception { + createCache(); + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _buildNumber = new IvyBuildNumber(); + _buildNumber.setProject(project); + } + + 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(); + } + + public void testDefault() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("newmod"); + _buildNumber.execute(); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("0", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("0", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testDefault2() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("newmod"); + _buildNumber.setDefault("1.0-dev-1"); + _buildNumber.execute(); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("1.0-dev-1", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testDefault3() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("newmod"); + _buildNumber.setDefault("mydefault"); + _buildNumber.execute(); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("mydefault", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testLatest() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("mod1.1"); + _buildNumber.execute(); + assertEquals("2.0", _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("2.1", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals("0", _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testLatest2() throws Exception { + _buildNumber.setOrganisation("orgbn"); + _buildNumber.setModule("buildnumber"); + _buildNumber.execute(); + assertEquals("test", _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("test.1", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testPrefix() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("mod1.1"); + _buildNumber.setPrefix("test"); + _buildNumber.execute(); + assertEquals("2.0", _buildNumber.getProject().getProperty("test.revision")); + assertEquals("2.1", _buildNumber.getProject().getProperty("test.new.revision")); + assertEquals("0", _buildNumber.getProject().getProperty("test.build.number")); + assertEquals("1", _buildNumber.getProject().getProperty("test.new.build.number")); + } + + public void testBuildNumber() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("mod1.1"); + _buildNumber.setRevision("1."); + _buildNumber.execute(); + assertEquals("1.1", _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("1.2", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals("1", _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("2", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testBuildNumber2() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("mod1.5"); + _buildNumber.setRevision("1."); + _buildNumber.execute(); + assertEquals("1.0.2", _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("1.1", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals("0", _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testBuildNumber3() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("mod1.1"); + _buildNumber.setRevision("1.1"); + _buildNumber.execute(); + assertEquals("1.1", _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("1.1.1", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("1", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + + public void testBuildNumber4() throws Exception { + _buildNumber.setOrganisation("org1"); + _buildNumber.setModule("mod1.1"); + _buildNumber.setRevision("3."); + _buildNumber.execute(); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.revision")); + assertEquals("3.0", _buildNumber.getProject().getProperty("ivy.new.revision")); + assertEquals(null, _buildNumber.getProject().getProperty("ivy.build.number")); + assertEquals("0", _buildNumber.getProject().getProperty("ivy.new.build.number")); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java b/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java index 717a8dcb..c733cf29 100644 --- a/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java +++ b/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java @@ -1,152 +1,152 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.ivy.TestHelper; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; -import org.apache.tools.ant.types.FileSet; - -public class IvyCacheFilesetTest extends TestCase { - private File _cache; - - private IvyCacheFileset _fileset; - - private Project _project; - - protected void setUp() throws Exception { - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _fileset = new IvyCacheFileset(); - _fileset.setProject(_project); - _fileset.setCache(_cache); - } - - 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(); - } - - public void testSimple() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - _fileset.setSetid("simple-setid"); - _fileset.execute(); - Object ref = _project.getReference("simple-setid"); - assertNotNull(ref); - assertTrue(ref instanceof FileSet); - FileSet fs = (FileSet) ref; - DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); - assertEquals(1, directoryScanner.getIncludedFiles().length); - assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") - .getAbsolutePath(), new File("build/cache/" - + directoryScanner.getIncludedFiles()[0]).getAbsolutePath()); - } - - private File getArchiveFileInCache(String organisation, String module, String revision, - String artifact, String type, String ext) { - return TestHelper.getArchiveFileInCache(_fileset.getIvyInstance(), _cache, organisation, - module, revision, artifact, type, ext); - } - - private File getArchiveFileInCache(String organisation, String module, String revision, - String artifact, String type, String ext, File cache) { - return TestHelper.getArchiveFileInCache(_fileset.getIvyInstance(), cache, organisation, - module, revision, artifact, type, ext); - } - - public void testEmptyConf() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-108.xml"); - _fileset.setSetid("emptyconf-setid"); - _fileset.setConf("empty"); - _fileset.execute(); - Object ref = _project.getReference("emptyconf-setid"); - assertNotNull(ref); - assertTrue(ref instanceof FileSet); - FileSet fs = (FileSet) ref; - DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); - assertEquals(0, directoryScanner.getIncludedFiles().length); - } - - public void testFailure() throws Exception { - try { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); - _fileset.setSetid("failure-setid"); - _fileset.execute(); - fail("failure didn't raised an exception with default haltonfailure setting"); - } catch (BuildException ex) { - // ok => should raised an exception - } - } - - public void testHaltOnFailure() throws Exception { - try { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); - _fileset.setSetid("haltfailure-setid"); - _fileset.setHaltonfailure(false); - _fileset.execute(); - } catch (BuildException ex) { - fail("failure raised an exception with haltonfailure set to false"); - } - } - - public void testWithoutPreviousResolveAndNonDefaultCache() throws Exception { - File cache2 = new File("build/cache2"); - cache2.mkdirs(); - - try { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - _fileset.setSetid("simple-setid"); - _fileset.setCache(cache2); - _fileset.execute(); - Object ref = _project.getReference("simple-setid"); - assertNotNull(ref); - assertTrue(ref instanceof FileSet); - FileSet fs = (FileSet) ref; - DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); - assertEquals(1, directoryScanner.getIncludedFiles().length); - assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", - cache2).getAbsolutePath(), new File("build/cache2/" - + directoryScanner.getIncludedFiles()[0]).getAbsolutePath()); - } finally { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(cache2); - del.execute(); - } - } - -} +/* + * 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 junit.framework.TestCase; + +import org.apache.ivy.TestHelper; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; +import org.apache.tools.ant.types.FileSet; + +public class IvyCacheFilesetTest extends TestCase { + private File _cache; + + private IvyCacheFileset _fileset; + + private Project _project; + + protected void setUp() throws Exception { + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _fileset = new IvyCacheFileset(); + _fileset.setProject(_project); + _fileset.setCache(_cache); + } + + 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(); + } + + public void testSimple() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + _fileset.setSetid("simple-setid"); + _fileset.execute(); + Object ref = _project.getReference("simple-setid"); + assertNotNull(ref); + assertTrue(ref instanceof FileSet); + FileSet fs = (FileSet) ref; + DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); + assertEquals(1, directoryScanner.getIncludedFiles().length); + assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") + .getAbsolutePath(), new File("build/cache/" + + directoryScanner.getIncludedFiles()[0]).getAbsolutePath()); + } + + private File getArchiveFileInCache(String organisation, String module, String revision, + String artifact, String type, String ext) { + return TestHelper.getArchiveFileInCache(_fileset.getIvyInstance(), _cache, organisation, + module, revision, artifact, type, ext); + } + + private File getArchiveFileInCache(String organisation, String module, String revision, + String artifact, String type, String ext, File cache) { + return TestHelper.getArchiveFileInCache(_fileset.getIvyInstance(), cache, organisation, + module, revision, artifact, type, ext); + } + + public void testEmptyConf() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-108.xml"); + _fileset.setSetid("emptyconf-setid"); + _fileset.setConf("empty"); + _fileset.execute(); + Object ref = _project.getReference("emptyconf-setid"); + assertNotNull(ref); + assertTrue(ref instanceof FileSet); + FileSet fs = (FileSet) ref; + DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); + assertEquals(0, directoryScanner.getIncludedFiles().length); + } + + public void testFailure() throws Exception { + try { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); + _fileset.setSetid("failure-setid"); + _fileset.execute(); + fail("failure didn't raised an exception with default haltonfailure setting"); + } catch (BuildException ex) { + // ok => should raised an exception + } + } + + public void testHaltOnFailure() throws Exception { + try { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); + _fileset.setSetid("haltfailure-setid"); + _fileset.setHaltonfailure(false); + _fileset.execute(); + } catch (BuildException ex) { + fail("failure raised an exception with haltonfailure set to false"); + } + } + + public void testWithoutPreviousResolveAndNonDefaultCache() throws Exception { + File cache2 = new File("build/cache2"); + cache2.mkdirs(); + + try { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + _fileset.setSetid("simple-setid"); + _fileset.setCache(cache2); + _fileset.execute(); + Object ref = _project.getReference("simple-setid"); + assertNotNull(ref); + assertTrue(ref instanceof FileSet); + FileSet fs = (FileSet) ref; + DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); + assertEquals(1, directoryScanner.getIncludedFiles().length); + assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", + cache2).getAbsolutePath(), new File("build/cache2/" + + directoryScanner.getIncludedFiles()[0]).getAbsolutePath()); + } finally { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(cache2); + del.execute(); + } + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyCachePathTest.java b/test/java/org/apache/ivy/ant/IvyCachePathTest.java index 6d069cd9..89245bfc 100644 --- a/test/java/org/apache/ivy/ant/IvyCachePathTest.java +++ b/test/java/org/apache/ivy/ant/IvyCachePathTest.java @@ -1,253 +1,253 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.ivy.TestHelper; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; -import org.apache.tools.ant.types.Path; - -public class IvyCachePathTest extends TestCase { - private File _cache; - - private IvyCachePath _path; - - private Project _project; - - protected void setUp() throws Exception { - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _path = new IvyCachePath(); - _path.setProject(_project); - _path.setCache(_cache); - } - - 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(); - } - - public void testSimple() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - _path.setPathid("simple-pathid"); - _path.execute(); - Object ref = _project.getReference("simple-pathid"); - assertNotNull(ref); - assertTrue(ref instanceof Path); - Path p = (Path) ref; - assertEquals(1, p.size()); - assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") - .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); - } - - public void testInline1() throws Exception { - // we first resolve another ivy file - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - - // then we resolve a dependency directly - _path.setOrganisation("org1"); - _path.setModule("mod1.2"); - _path.setRevision("2.0"); - _path.setInline(true); - _path.setPathid("simple-pathid"); - _path.execute(); - Object ref = _project.getReference("simple-pathid"); - assertNotNull(ref); - assertTrue(ref instanceof Path); - Path p = (Path) ref; - assertEquals(1, p.size()); - assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") - .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); - } - - public void testInline2() throws Exception { - // we first resolve a dependency directly - _path.setOrganisation("org1"); - _path.setModule("mod1.2"); - _path.setRevision("2.0"); - _path.setInline(true); - _path.setPathid("simple-pathid"); - _path.execute(); - Object ref = _project.getReference("simple-pathid"); - assertNotNull(ref); - assertTrue(ref instanceof Path); - Path p = (Path) ref; - assertEquals(1, p.size()); - assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") - .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); - - // we then resolve another ivy file - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testEmptyConf() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-108.xml"); - _path.setPathid("emptyconf-pathid"); - _path.setConf("empty"); - _path.execute(); - Object ref = _project.getReference("emptyconf-pathid"); - assertNotNull(ref); - assertTrue(ref instanceof Path); - Path p = (Path) ref; - assertEquals(0, p.size()); - } - - public void testFailure() throws Exception { - try { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); - _path.setPathid("failure-pathid"); - _path.execute(); - fail("failure didn't raised an exception with default haltonfailure setting"); - } catch (BuildException ex) { - // ok => should raised an exception - } - } - - public void testHaltOnFailure() throws Exception { - try { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); - _path.setPathid("haltfailure-pathid"); - _path.setHaltonfailure(false); - _path.execute(); - } catch (BuildException ex) { - fail("failure raised an exception with haltonfailure set to false"); - } - } - - public void testWithResolveId() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setResolveId("withResolveId"); - resolve.execute(); - - // resolve another ivy file - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - _path.setResolveId("withResolveId"); - _path.setPathid("withresolveid-pathid"); - _path.execute(); - - Object ref = _project.getReference("withresolveid-pathid"); - assertNotNull(ref); - assertTrue(ref instanceof Path); - Path p = (Path) ref; - assertEquals(1, p.size()); - assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") - .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); - } - - public void testWithResolveIdWithoutResolve() throws Exception { - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - IvyResolve resolve = new IvyResolve(); - resolve.setProject(project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setResolveId("withResolveId"); - resolve.execute(); - - // resolve another ivy file - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - _path.setResolveId("withResolveId"); - _path.setPathid("withresolveid-pathid"); - _path.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _path.execute(); - - Object ref = _project.getReference("withresolveid-pathid"); - assertNotNull(ref); - assertTrue(ref instanceof Path); - Path p = (Path) ref; - assertEquals(1, p.size()); - assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") - .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); - } - - public void testWithResolveIdAndMissingConfs() throws Exception { - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - IvyResolve resolve = new IvyResolve(); - resolve.setProject(project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setResolveId("testWithResolveIdAndMissingConfs"); - resolve.setConf("default"); - resolve.execute(); - - // resolve another ivy file - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml"); - - _path.setResolveId("testWithResolveIdAndMissingConfs"); - _path.setPathid("withresolveid-pathid"); - _path.setConf("default,compile"); - _path.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - _path.execute(); - } - - private File getArchiveFileInCache(String organisation, String module, String revision, - String artifact, String type, String ext) { - return TestHelper.getArchiveFileInCache(_path.getIvyInstance(), _cache, organisation, - module, revision, artifact, type, ext); - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.ivy.TestHelper; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; +import org.apache.tools.ant.types.Path; + +public class IvyCachePathTest extends TestCase { + private File _cache; + + private IvyCachePath _path; + + private Project _project; + + protected void setUp() throws Exception { + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _path = new IvyCachePath(); + _path.setProject(_project); + _path.setCache(_cache); + } + + 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(); + } + + public void testSimple() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + _path.setPathid("simple-pathid"); + _path.execute(); + Object ref = _project.getReference("simple-pathid"); + assertNotNull(ref); + assertTrue(ref instanceof Path); + Path p = (Path) ref; + assertEquals(1, p.size()); + assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") + .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); + } + + public void testInline1() throws Exception { + // we first resolve another ivy file + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + + // then we resolve a dependency directly + _path.setOrganisation("org1"); + _path.setModule("mod1.2"); + _path.setRevision("2.0"); + _path.setInline(true); + _path.setPathid("simple-pathid"); + _path.execute(); + Object ref = _project.getReference("simple-pathid"); + assertNotNull(ref); + assertTrue(ref instanceof Path); + Path p = (Path) ref; + assertEquals(1, p.size()); + assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") + .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); + } + + public void testInline2() throws Exception { + // we first resolve a dependency directly + _path.setOrganisation("org1"); + _path.setModule("mod1.2"); + _path.setRevision("2.0"); + _path.setInline(true); + _path.setPathid("simple-pathid"); + _path.execute(); + Object ref = _project.getReference("simple-pathid"); + assertNotNull(ref); + assertTrue(ref instanceof Path); + Path p = (Path) ref; + assertEquals(1, p.size()); + assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") + .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); + + // we then resolve another ivy file + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testEmptyConf() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-108.xml"); + _path.setPathid("emptyconf-pathid"); + _path.setConf("empty"); + _path.execute(); + Object ref = _project.getReference("emptyconf-pathid"); + assertNotNull(ref); + assertTrue(ref instanceof Path); + Path p = (Path) ref; + assertEquals(0, p.size()); + } + + public void testFailure() throws Exception { + try { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); + _path.setPathid("failure-pathid"); + _path.execute(); + fail("failure didn't raised an exception with default haltonfailure setting"); + } catch (BuildException ex) { + // ok => should raised an exception + } + } + + public void testHaltOnFailure() throws Exception { + try { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); + _path.setPathid("haltfailure-pathid"); + _path.setHaltonfailure(false); + _path.execute(); + } catch (BuildException ex) { + fail("failure raised an exception with haltonfailure set to false"); + } + } + + public void testWithResolveId() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setResolveId("withResolveId"); + resolve.execute(); + + // resolve another ivy file + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + _path.setResolveId("withResolveId"); + _path.setPathid("withresolveid-pathid"); + _path.execute(); + + Object ref = _project.getReference("withresolveid-pathid"); + assertNotNull(ref); + assertTrue(ref instanceof Path); + Path p = (Path) ref; + assertEquals(1, p.size()); + assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") + .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); + } + + public void testWithResolveIdWithoutResolve() throws Exception { + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + IvyResolve resolve = new IvyResolve(); + resolve.setProject(project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setResolveId("withResolveId"); + resolve.execute(); + + // resolve another ivy file + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + _path.setResolveId("withResolveId"); + _path.setPathid("withresolveid-pathid"); + _path.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _path.execute(); + + Object ref = _project.getReference("withresolveid-pathid"); + assertNotNull(ref); + assertTrue(ref instanceof Path); + Path p = (Path) ref; + assertEquals(1, p.size()); + assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar") + .getAbsolutePath(), new File(p.list()[0]).getAbsolutePath()); + } + + public void testWithResolveIdAndMissingConfs() throws Exception { + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + IvyResolve resolve = new IvyResolve(); + resolve.setProject(project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setResolveId("testWithResolveIdAndMissingConfs"); + resolve.setConf("default"); + resolve.execute(); + + // resolve another ivy file + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml"); + + _path.setResolveId("testWithResolveIdAndMissingConfs"); + _path.setPathid("withresolveid-pathid"); + _path.setConf("default,compile"); + _path.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + _path.execute(); + } + + private File getArchiveFileInCache(String organisation, String module, String revision, + String artifact, String type, String ext) { + return TestHelper.getArchiveFileInCache(_path.getIvyInstance(), _cache, organisation, + module, revision, artifact, type, ext); + } +} diff --git a/test/java/org/apache/ivy/ant/IvyConfigureTest.java b/test/java/org/apache/ivy/ant/IvyConfigureTest.java index b22a991e..657d07d4 100644 --- a/test/java/org/apache/ivy/ant/IvyConfigureTest.java +++ b/test/java/org/apache/ivy/ant/IvyConfigureTest.java @@ -1,149 +1,149 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.plugins.resolver.IBiblioResolver; -import org.apache.ivy.plugins.resolver.IvyRepResolver; -import org.apache.tools.ant.Project; - -/** - * Test the deprecated IvyConfigureTest and the underlying implementation AntIvySettings. When - * IvyConfigure will be removed, this class should be renamed AntIvySettingsTest - */ -public class IvyConfigureTest extends TestCase { - private IvyConfigure _configure; - - protected void setUp() throws Exception { - Project project = new Project(); - project.setProperty("myproperty", "myvalue"); - - _configure = new IvyConfigure(); - _configure.setProject(project); - } - - private Ivy getIvyInstance() { - return IvyAntSettings.getDefaultInstance(_configure.getProject()) - .getConfiguredIvyInstance(); - } - - public void testDefault() throws Exception { - // by default configure look in the current directory for an ivysettings.xml file... - // but Ivy itself has one, and we don't want to use it - _configure.getProject() - .setProperty("ivy.settings.file", "no/settings/will/use/default.xml"); - _configure.execute(); - - IvySettings settings = getIvyInstance().getSettings(); - assertNotNull(settings.getDefaultResolver()); - - DependencyResolver publicResolver = settings.getResolver("public"); - assertNotNull(publicResolver); - assertTrue(publicResolver instanceof IBiblioResolver); - IBiblioResolver ibiblio = (IBiblioResolver) publicResolver; - assertTrue(ibiblio.isM2compatible()); - } - - public void testDefault14() throws Exception { - // by default configure look in the current directory for an ivysettings.xml file... - // but Ivy itself has one, and we don't want to use it - _configure.getProject() - .setProperty("ivy.settings.file", "no/settings/will/use/default.xml"); - _configure.getProject().setProperty("ivy.14.compatible", "true"); - _configure.execute(); - - IvySettings settings = getIvyInstance().getSettings(); - assertNotNull(settings.getDefaultResolver()); - - DependencyResolver publicResolver = settings.getResolver("public"); - assertTrue(publicResolver instanceof IvyRepResolver); - } - - public void testFile() throws Exception { - _configure.setFile(new File("test/repositories/ivysettings.xml")); - - _configure.execute(); - - Ivy ivy = _configure.getIvyInstance(); - assertNotNull(ivy); - IvySettings settings = ivy.getSettings(); - assertNotNull(settings); - - assertEquals(new File("build/cache"), settings.getDefaultCache()); - assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings - .getVariables().get("ivy.settings.file")); - assertEquals(new File("test/repositories/ivysettings.xml").toURL().toExternalForm(), - settings.getVariables().get("ivy.settings.url")); - assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables().get( - "ivy.settings.dir")); - assertEquals("myvalue", settings.getVariables().get("myproperty")); - } - - public void testURL() throws Exception { - String confUrl = new File("test/repositories/ivysettings.xml").toURL().toExternalForm(); - String confDirUrl = new File("test/repositories").toURL().toExternalForm(); - if (confDirUrl.endsWith("/")) { - confDirUrl = confDirUrl.substring(0, confDirUrl.length() - 1); - } - _configure.setUrl(confUrl); - - _configure.execute(); - - IvySettings settings = _configure.getIvyInstance().getSettings(); - - assertEquals(new File("build/cache"), settings.getDefaultCache()); - assertEquals(confUrl, settings.getVariables().get("ivy.settings.url")); - assertEquals(confDirUrl, settings.getVariables().get("ivy.settings.dir")); - assertEquals("myvalue", settings.getVariables().get("myproperty")); - } - - public void testAntProperties() throws Exception { - String confUrl = IvyConfigureTest.class.getResource("ivysettings-test.xml") - .toExternalForm(); - _configure.setUrl(confUrl); - - _configure.execute(); - - IvySettings settings = _configure.getIvyInstance().getSettings(); - assertNotNull(settings); - - assertEquals("myvalue", settings.getVariables().get("myproperty")); - assertEquals("myvalue", settings.getDefaultCache().getName()); - } - - public void testOverrideVariables() throws Exception { - String confUrl = IvyConfigureTest.class.getResource("ivysettings-props.xml") - .toExternalForm(); - _configure.setUrl(confUrl); - - _configure.execute(); - - IvySettings settings = _configure.getIvyInstance().getSettings(); - assertNotNull(settings); - - assertEquals("lib/test/[artifact]-[revision].[ext]", settings.getVariables().get( - "ivy.retrieve.pattern")); - } - -} +/* + * 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 junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.plugins.resolver.IBiblioResolver; +import org.apache.ivy.plugins.resolver.IvyRepResolver; +import org.apache.tools.ant.Project; + +/** + * Test the deprecated IvyConfigureTest and the underlying implementation AntIvySettings. When + * IvyConfigure will be removed, this class should be renamed AntIvySettingsTest + */ +public class IvyConfigureTest extends TestCase { + private IvyConfigure _configure; + + protected void setUp() throws Exception { + Project project = new Project(); + project.setProperty("myproperty", "myvalue"); + + _configure = new IvyConfigure(); + _configure.setProject(project); + } + + private Ivy getIvyInstance() { + return IvyAntSettings.getDefaultInstance(_configure.getProject()) + .getConfiguredIvyInstance(); + } + + public void testDefault() throws Exception { + // by default configure look in the current directory for an ivysettings.xml file... + // but Ivy itself has one, and we don't want to use it + _configure.getProject() + .setProperty("ivy.settings.file", "no/settings/will/use/default.xml"); + _configure.execute(); + + IvySettings settings = getIvyInstance().getSettings(); + assertNotNull(settings.getDefaultResolver()); + + DependencyResolver publicResolver = settings.getResolver("public"); + assertNotNull(publicResolver); + assertTrue(publicResolver instanceof IBiblioResolver); + IBiblioResolver ibiblio = (IBiblioResolver) publicResolver; + assertTrue(ibiblio.isM2compatible()); + } + + public void testDefault14() throws Exception { + // by default configure look in the current directory for an ivysettings.xml file... + // but Ivy itself has one, and we don't want to use it + _configure.getProject() + .setProperty("ivy.settings.file", "no/settings/will/use/default.xml"); + _configure.getProject().setProperty("ivy.14.compatible", "true"); + _configure.execute(); + + IvySettings settings = getIvyInstance().getSettings(); + assertNotNull(settings.getDefaultResolver()); + + DependencyResolver publicResolver = settings.getResolver("public"); + assertTrue(publicResolver instanceof IvyRepResolver); + } + + public void testFile() throws Exception { + _configure.setFile(new File("test/repositories/ivysettings.xml")); + + _configure.execute(); + + Ivy ivy = _configure.getIvyInstance(); + assertNotNull(ivy); + IvySettings settings = ivy.getSettings(); + assertNotNull(settings); + + assertEquals(new File("build/cache"), settings.getDefaultCache()); + assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings + .getVariables().get("ivy.settings.file")); + assertEquals(new File("test/repositories/ivysettings.xml").toURL().toExternalForm(), + settings.getVariables().get("ivy.settings.url")); + assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables().get( + "ivy.settings.dir")); + assertEquals("myvalue", settings.getVariables().get("myproperty")); + } + + public void testURL() throws Exception { + String confUrl = new File("test/repositories/ivysettings.xml").toURL().toExternalForm(); + String confDirUrl = new File("test/repositories").toURL().toExternalForm(); + if (confDirUrl.endsWith("/")) { + confDirUrl = confDirUrl.substring(0, confDirUrl.length() - 1); + } + _configure.setUrl(confUrl); + + _configure.execute(); + + IvySettings settings = _configure.getIvyInstance().getSettings(); + + assertEquals(new File("build/cache"), settings.getDefaultCache()); + assertEquals(confUrl, settings.getVariables().get("ivy.settings.url")); + assertEquals(confDirUrl, settings.getVariables().get("ivy.settings.dir")); + assertEquals("myvalue", settings.getVariables().get("myproperty")); + } + + public void testAntProperties() throws Exception { + String confUrl = IvyConfigureTest.class.getResource("ivysettings-test.xml") + .toExternalForm(); + _configure.setUrl(confUrl); + + _configure.execute(); + + IvySettings settings = _configure.getIvyInstance().getSettings(); + assertNotNull(settings); + + assertEquals("myvalue", settings.getVariables().get("myproperty")); + assertEquals("myvalue", settings.getDefaultCache().getName()); + } + + public void testOverrideVariables() throws Exception { + String confUrl = IvyConfigureTest.class.getResource("ivysettings-props.xml") + .toExternalForm(); + _configure.setUrl(confUrl); + + _configure.execute(); + + IvySettings settings = _configure.getIvyInstance().getSettings(); + assertNotNull(settings); + + assertEquals("lib/test/[artifact]-[revision].[ext]", settings.getVariables().get( + "ivy.retrieve.pattern")); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyConvertPomTest.java b/test/java/org/apache/ivy/ant/IvyConvertPomTest.java index b68fdcf9..6b32979a 100644 --- a/test/java/org/apache/ivy/ant/IvyConvertPomTest.java +++ b/test/java/org/apache/ivy/ant/IvyConvertPomTest.java @@ -1,53 +1,53 @@ -/* - * 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.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; - -import junit.framework.TestCase; - -import org.apache.ivy.util.FileUtil; -import org.apache.tools.ant.Project; - -public class IvyConvertPomTest extends TestCase { - public void testSimple() throws Exception { - IvyConvertPom task = new IvyConvertPom(); - task.setProject(new Project()); - task.setPomFile(new File("test/java/org/apache/ivy/ant/test.pom")); - File destFile = File.createTempFile("ivy", ".xml"); - destFile.deleteOnExit(); - task.setIvyFile(destFile); - task.execute(); - - String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(destFile))); - String expected = readEntirely("test-convertpom.xml").replaceAll("\r\n", "\n").replace( - '\r', '\n'); - // do not work properly on all platform and depends on the file date - // assertEquals(expected, wrote); - } - - private String readEntirely(String resource) throws IOException { - return FileUtil.readEntirely( - new BufferedReader(new InputStreamReader(IvyConvertPomTest.class.getResource(resource) - .openStream()))).replaceAll("\r\n", "\n").replace('\r', '\n'); - } -} +/* + * 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.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import junit.framework.TestCase; + +import org.apache.ivy.util.FileUtil; +import org.apache.tools.ant.Project; + +public class IvyConvertPomTest extends TestCase { + public void testSimple() throws Exception { + IvyConvertPom task = new IvyConvertPom(); + task.setProject(new Project()); + task.setPomFile(new File("test/java/org/apache/ivy/ant/test.pom")); + File destFile = File.createTempFile("ivy", ".xml"); + destFile.deleteOnExit(); + task.setIvyFile(destFile); + task.execute(); + + String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(destFile))); + String expected = readEntirely("test-convertpom.xml").replaceAll("\r\n", "\n").replace( + '\r', '\n'); + // do not work properly on all platform and depends on the file date + // assertEquals(expected, wrote); + } + + private String readEntirely(String resource) throws IOException { + return FileUtil.readEntirely( + new BufferedReader(new InputStreamReader(IvyConvertPomTest.class.getResource(resource) + .openStream()))).replaceAll("\r\n", "\n").replace('\r', '\n'); + } +} diff --git a/test/java/org/apache/ivy/ant/IvyDeliverTest.java b/test/java/org/apache/ivy/ant/IvyDeliverTest.java index a45fd055..ff7c680b 100644 --- a/test/java/org/apache/ivy/ant/IvyDeliverTest.java +++ b/test/java/org/apache/ivy/ant/IvyDeliverTest.java @@ -1,331 +1,331 @@ -/* - * 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.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.ivy.util.FileUtil; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyDeliverTest extends TestCase { - private File _cache; - - private IvyDeliver _deliver; - - private Project _project; - - protected void setUp() throws Exception { - cleanTestDir(); - cleanRep(); - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - _project.setProperty("build", "build/test/deliver"); - - _deliver = new IvyDeliver(); - _deliver.setProject(_project); - _deliver.setCache(_cache); - } - - private void createCache() { - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - cleanCache(); - cleanTestDir(); - cleanRep(); - } - - private void cleanCache() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - private void cleanTestDir() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/deliver")); - del.execute(); - } - - private void cleanRep() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("test/repositories/1/apache")); - del.execute(); - } - - public void testSimple() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), deliveredIvyFile.toURL(), true); - assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md - .getModuleRevisionId()); - DependencyDescriptor[] dds = md.getDependencies(); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"), dds[0] - .getDependencyRevisionId()); - } - - public void testWithResolveId() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setResolveId("withResolveId"); - resolve.execute(); - - // resolve another ivy file - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - _deliver.setResolveId("withResolveId"); - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), deliveredIvyFile.toURL(), true); - assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"), md - .getModuleRevisionId()); - DependencyDescriptor[] dds = md.getDependencies(); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0] - .getDependencyRevisionId()); - } - - public void testWithResolveIdInAnotherBuild() throws Exception { - // create a new build - Project other = new Project(); - other.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - other.setProperty("build", "build/test/deliver"); - - // do a resolve in the new build - IvyResolve resolve = new IvyResolve(); - resolve.setProject(other); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setResolveId("withResolveId"); - resolve.execute(); - - // resolve another ivy file - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - _deliver.setResolveId("withResolveId"); - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), deliveredIvyFile.toURL(), true); - assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"), md - .getModuleRevisionId()); - DependencyDescriptor[] dds = md.getDependencies(); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0] - .getDependencyRevisionId()); - } - - public void testWithBranch() throws Exception { - // test case for IVY-404 - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest-branch.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), deliveredIvyFile.toURL(), true); - assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md - .getModuleRevisionId()); - DependencyDescriptor[] dds = md.getDependencies(); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "TRUNK", "2.2"), dds[0] - .getDependencyRevisionId()); - } - - public void testWithExtraAttributes() throws Exception { - // test case for IVY-415 - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest-extra.xml"); - IvyResolve res = new IvyResolve(); - res.setValidate(false); - res.setProject(_project); - res.execute(); - - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.setValidate(false); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), deliveredIvyFile.toURL(), false); - assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md - .getModuleRevisionId()); - DependencyDescriptor[] dds = md.getDependencies(); - assertEquals(1, dds.length); - Map extraAtt = new HashMap(); - extraAtt.put("myExtraAtt", "myValue"); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2", extraAtt), dds[0] - .getDependencyRevisionId()); - } - - public void testReplaceImportedConfigurations() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-import-confs.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - String deliveredFileContent = FileUtil.readEntirely(new BufferedReader(new FileReader( - deliveredIvyFile))); - assertTrue("import not replaced: import can still be found in file", deliveredFileContent - .indexOf("import") == -1); - assertTrue("import not replaced: conf1 cannot be found in file", deliveredFileContent - .indexOf("conf1") != -1); - } - - public void testReplaceVariables() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-with-variables.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - res.getIvyInstance().getSettings().setVariable("myvar", "myvalue"); - - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - String deliveredFileContent = FileUtil.readEntirely(new BufferedReader(new FileReader( - deliveredIvyFile))); - assertTrue("variable not replaced: myvar can still be found in file", deliveredFileContent - .indexOf("myvar") == -1); - assertTrue("variable not replaced: myvalue cannot be found in file", deliveredFileContent - .indexOf("myvalue") != -1); - } - - public void testNoReplaceDynamicRev() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.setReplacedynamicrev(false); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), deliveredIvyFile.toURL(), true); - assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md - .getModuleRevisionId()); - DependencyDescriptor[] dds = md.getDependencies(); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "latest.integration"), dds[0] - .getDependencyRevisionId()); - } - - public void testDifferentRevisionsForSameModule() throws Exception { - _project.setProperty("ivy.dep.file", - "test/java/org/apache/ivy/ant/ivy-different-revisions.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _deliver.setPubrevision("1.2"); - _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); - _deliver.execute(); - - // should have done the ivy delivering - File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); - assertTrue(deliveredIvyFile.exists()); - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), deliveredIvyFile.toURL(), true); - assertEquals(ModuleRevisionId.newInstance("apache", "different-revs", "1.2"), md - .getModuleRevisionId()); - DependencyDescriptor[] dds = md.getDependencies(); - assertEquals(3, dds.length); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0] - .getDependencyRevisionId()); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), dds[1] - .getDependencyRevisionId()); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"), dds[2] - .getDependencyRevisionId()); - } -} +/* + * 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.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.util.FileUtil; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyDeliverTest extends TestCase { + private File _cache; + + private IvyDeliver _deliver; + + private Project _project; + + protected void setUp() throws Exception { + cleanTestDir(); + cleanRep(); + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + _project.setProperty("build", "build/test/deliver"); + + _deliver = new IvyDeliver(); + _deliver.setProject(_project); + _deliver.setCache(_cache); + } + + private void createCache() { + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + cleanTestDir(); + cleanRep(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + private void cleanTestDir() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/deliver")); + del.execute(); + } + + private void cleanRep() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("test/repositories/1/apache")); + del.execute(); + } + + public void testSimple() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), deliveredIvyFile.toURL(), true); + assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md + .getModuleRevisionId()); + DependencyDescriptor[] dds = md.getDependencies(); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"), dds[0] + .getDependencyRevisionId()); + } + + public void testWithResolveId() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setResolveId("withResolveId"); + resolve.execute(); + + // resolve another ivy file + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + _deliver.setResolveId("withResolveId"); + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), deliveredIvyFile.toURL(), true); + assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"), md + .getModuleRevisionId()); + DependencyDescriptor[] dds = md.getDependencies(); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0] + .getDependencyRevisionId()); + } + + public void testWithResolveIdInAnotherBuild() throws Exception { + // create a new build + Project other = new Project(); + other.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + other.setProperty("build", "build/test/deliver"); + + // do a resolve in the new build + IvyResolve resolve = new IvyResolve(); + resolve.setProject(other); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setResolveId("withResolveId"); + resolve.execute(); + + // resolve another ivy file + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + _deliver.setResolveId("withResolveId"); + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), deliveredIvyFile.toURL(), true); + assertEquals(ModuleRevisionId.newInstance("apache", "resolve-simple", "1.2"), md + .getModuleRevisionId()); + DependencyDescriptor[] dds = md.getDependencies(); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0] + .getDependencyRevisionId()); + } + + public void testWithBranch() throws Exception { + // test case for IVY-404 + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest-branch.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), deliveredIvyFile.toURL(), true); + assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md + .getModuleRevisionId()); + DependencyDescriptor[] dds = md.getDependencies(); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "TRUNK", "2.2"), dds[0] + .getDependencyRevisionId()); + } + + public void testWithExtraAttributes() throws Exception { + // test case for IVY-415 + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest-extra.xml"); + IvyResolve res = new IvyResolve(); + res.setValidate(false); + res.setProject(_project); + res.execute(); + + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.setValidate(false); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), deliveredIvyFile.toURL(), false); + assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md + .getModuleRevisionId()); + DependencyDescriptor[] dds = md.getDependencies(); + assertEquals(1, dds.length); + Map extraAtt = new HashMap(); + extraAtt.put("myExtraAtt", "myValue"); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.2", extraAtt), dds[0] + .getDependencyRevisionId()); + } + + public void testReplaceImportedConfigurations() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-import-confs.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + String deliveredFileContent = FileUtil.readEntirely(new BufferedReader(new FileReader( + deliveredIvyFile))); + assertTrue("import not replaced: import can still be found in file", deliveredFileContent + .indexOf("import") == -1); + assertTrue("import not replaced: conf1 cannot be found in file", deliveredFileContent + .indexOf("conf1") != -1); + } + + public void testReplaceVariables() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-with-variables.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + res.getIvyInstance().getSettings().setVariable("myvar", "myvalue"); + + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + String deliveredFileContent = FileUtil.readEntirely(new BufferedReader(new FileReader( + deliveredIvyFile))); + assertTrue("variable not replaced: myvar can still be found in file", deliveredFileContent + .indexOf("myvar") == -1); + assertTrue("variable not replaced: myvalue cannot be found in file", deliveredFileContent + .indexOf("myvalue") != -1); + } + + public void testNoReplaceDynamicRev() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.setReplacedynamicrev(false); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), deliveredIvyFile.toURL(), true); + assertEquals(ModuleRevisionId.newInstance("apache", "resolve-latest", "1.2"), md + .getModuleRevisionId()); + DependencyDescriptor[] dds = md.getDependencies(); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "latest.integration"), dds[0] + .getDependencyRevisionId()); + } + + public void testDifferentRevisionsForSameModule() throws Exception { + _project.setProperty("ivy.dep.file", + "test/java/org/apache/ivy/ant/ivy-different-revisions.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _deliver.setPubrevision("1.2"); + _deliver.setDeliverpattern("build/test/deliver/ivy-[revision].xml"); + _deliver.execute(); + + // should have done the ivy delivering + File deliveredIvyFile = new File("build/test/deliver/ivy-1.2.xml"); + assertTrue(deliveredIvyFile.exists()); + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), deliveredIvyFile.toURL(), true); + assertEquals(ModuleRevisionId.newInstance("apache", "different-revs", "1.2"), md + .getModuleRevisionId()); + DependencyDescriptor[] dds = md.getDependencies(); + assertEquals(3, dds.length); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), dds[0] + .getDependencyRevisionId()); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), dds[1] + .getDependencyRevisionId()); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"), dds[2] + .getDependencyRevisionId()); + } +} diff --git a/test/java/org/apache/ivy/ant/IvyFindRevisionTest.java b/test/java/org/apache/ivy/ant/IvyFindRevisionTest.java index d81f5355..97332596 100644 --- a/test/java/org/apache/ivy/ant/IvyFindRevisionTest.java +++ b/test/java/org/apache/ivy/ant/IvyFindRevisionTest.java @@ -1,82 +1,82 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyFindRevisionTest extends TestCase { - private File _cache; - - private IvyFindRevision _findRevision; - - protected void setUp() throws Exception { - createCache(); - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _findRevision = new IvyFindRevision(); - _findRevision.setProject(project); - } - - 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(); - } - - public void testProperty() throws Exception { - _findRevision.setOrganisation("org1"); - _findRevision.setModule("mod1.1"); - _findRevision.setRevision("1.0"); - _findRevision.setProperty("test.revision"); - _findRevision.execute(); - assertEquals("1.0", _findRevision.getProject().getProperty("test.revision")); - } - - public void testLatest() throws Exception { - _findRevision.setOrganisation("org1"); - _findRevision.setModule("mod1.1"); - _findRevision.setRevision("latest.integration"); - _findRevision.execute(); - assertEquals("2.0", _findRevision.getProject().getProperty("ivy.revision")); - } - - public void testLatestSubversion() throws Exception { - _findRevision.setOrganisation("org1"); - _findRevision.setModule("mod1.1"); - _findRevision.setRevision("1.0+"); - _findRevision.execute(); - assertEquals("1.0.1", _findRevision.getProject().getProperty("ivy.revision")); - } - -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyFindRevisionTest extends TestCase { + private File _cache; + + private IvyFindRevision _findRevision; + + protected void setUp() throws Exception { + createCache(); + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _findRevision = new IvyFindRevision(); + _findRevision.setProject(project); + } + + 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(); + } + + public void testProperty() throws Exception { + _findRevision.setOrganisation("org1"); + _findRevision.setModule("mod1.1"); + _findRevision.setRevision("1.0"); + _findRevision.setProperty("test.revision"); + _findRevision.execute(); + assertEquals("1.0", _findRevision.getProject().getProperty("test.revision")); + } + + public void testLatest() throws Exception { + _findRevision.setOrganisation("org1"); + _findRevision.setModule("mod1.1"); + _findRevision.setRevision("latest.integration"); + _findRevision.execute(); + assertEquals("2.0", _findRevision.getProject().getProperty("ivy.revision")); + } + + public void testLatestSubversion() throws Exception { + _findRevision.setOrganisation("org1"); + _findRevision.setModule("mod1.1"); + _findRevision.setRevision("1.0+"); + _findRevision.execute(); + assertEquals("1.0.1", _findRevision.getProject().getProperty("ivy.revision")); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyInstallTest.java b/test/java/org/apache/ivy/ant/IvyInstallTest.java index cf1c62ed..7beeacd1 100644 --- a/test/java/org/apache/ivy/ant/IvyInstallTest.java +++ b/test/java/org/apache/ivy/ant/IvyInstallTest.java @@ -1,99 +1,99 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyInstallTest extends TestCase { - private File _cache; - - private IvyInstall _install; - - private Project _project; - - protected void setUp() throws Exception { - createCache(); - cleanTestLib(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _install = new IvyInstall(); - _install.setProject(_project); - _install.setCache(_cache); - } - - private void createCache() { - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - cleanCache(); - cleanTestLib(); - } - - private void cleanCache() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - private void cleanTestLib() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/lib")); - del.execute(); - } - - public void testDependencyNotFoundFailure() { - _install.setOrganisation("xxx"); - _install.setModule("yyy"); - _install.setRevision("zzz"); - _install.setFrom("test"); - _install.setTo("1"); - - try { - _install.execute(); - fail("unknown dependency, failure expected (haltunresolved=true)"); - } catch (BuildException be) { - // success - } - } - - public void testDependencyNotFoundSuccess() { - _install.setOrganisation("xxx"); - _install.setModule("yyy"); - _install.setRevision("zzz"); - _install.setFrom("test"); - _install.setTo("1"); - _install.setHaltonfailure(false); - - try { - _install.execute(); - } catch (BuildException be) { - fail("unknown dependency, failure unexepected (haltunresolved=false)"); - } - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyInstallTest extends TestCase { + private File _cache; + + private IvyInstall _install; + + private Project _project; + + protected void setUp() throws Exception { + createCache(); + cleanTestLib(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _install = new IvyInstall(); + _install.setProject(_project); + _install.setCache(_cache); + } + + private void createCache() { + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + cleanTestLib(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + private void cleanTestLib() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/lib")); + del.execute(); + } + + public void testDependencyNotFoundFailure() { + _install.setOrganisation("xxx"); + _install.setModule("yyy"); + _install.setRevision("zzz"); + _install.setFrom("test"); + _install.setTo("1"); + + try { + _install.execute(); + fail("unknown dependency, failure expected (haltunresolved=true)"); + } catch (BuildException be) { + // success + } + } + + public void testDependencyNotFoundSuccess() { + _install.setOrganisation("xxx"); + _install.setModule("yyy"); + _install.setRevision("zzz"); + _install.setFrom("test"); + _install.setTo("1"); + _install.setHaltonfailure(false); + + try { + _install.execute(); + } catch (BuildException be) { + fail("unknown dependency, failure unexepected (haltunresolved=false)"); + } + } +} diff --git a/test/java/org/apache/ivy/ant/IvyListModulesTest.java b/test/java/org/apache/ivy/ant/IvyListModulesTest.java index eaeac277..ccf36bbd 100644 --- a/test/java/org/apache/ivy/ant/IvyListModulesTest.java +++ b/test/java/org/apache/ivy/ant/IvyListModulesTest.java @@ -1,79 +1,79 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyListModulesTest extends TestCase { - private File _cache; - - private IvyListModules _findModules; - - protected void setUp() throws Exception { - createCache(); - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _findModules = new IvyListModules(); - _findModules.setProject(project); - } - - 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(); - } - - public void testExact() throws Exception { - _findModules.setOrganisation("org1"); - _findModules.setModule("mod1.1"); - _findModules.setRevision("1.0"); - _findModules.setProperty("found"); - _findModules.setValue("[organisation]/[module]/[revision]"); - _findModules.execute(); - assertEquals("org1/mod1.1/1.0", _findModules.getProject().getProperty("found")); - } - - public void testAllRevs() throws Exception { - _findModules.setOrganisation("org1"); - _findModules.setModule("mod1.1"); - _findModules.setRevision("*"); - _findModules.setProperty("found.[revision]"); - _findModules.setValue("true"); - _findModules.execute(); - assertEquals("true", _findModules.getProject().getProperty("found.1.0")); - assertEquals("true", _findModules.getProject().getProperty("found.1.1")); - assertEquals("true", _findModules.getProject().getProperty("found.2.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. + * + */ +package org.apache.ivy.ant; + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyListModulesTest extends TestCase { + private File _cache; + + private IvyListModules _findModules; + + protected void setUp() throws Exception { + createCache(); + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _findModules = new IvyListModules(); + _findModules.setProject(project); + } + + 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(); + } + + public void testExact() throws Exception { + _findModules.setOrganisation("org1"); + _findModules.setModule("mod1.1"); + _findModules.setRevision("1.0"); + _findModules.setProperty("found"); + _findModules.setValue("[organisation]/[module]/[revision]"); + _findModules.execute(); + assertEquals("org1/mod1.1/1.0", _findModules.getProject().getProperty("found")); + } + + public void testAllRevs() throws Exception { + _findModules.setOrganisation("org1"); + _findModules.setModule("mod1.1"); + _findModules.setRevision("*"); + _findModules.setProperty("found.[revision]"); + _findModules.setValue("true"); + _findModules.execute(); + assertEquals("true", _findModules.getProject().getProperty("found.1.0")); + assertEquals("true", _findModules.getProject().getProperty("found.1.1")); + assertEquals("true", _findModules.getProject().getProperty("found.2.0")); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyPostResolveTaskTest.java b/test/java/org/apache/ivy/ant/IvyPostResolveTaskTest.java index ce9b6d0e..d0d70e54 100644 --- a/test/java/org/apache/ivy/ant/IvyPostResolveTaskTest.java +++ b/test/java/org/apache/ivy/ant/IvyPostResolveTaskTest.java @@ -1,411 +1,411 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.ivy.TestHelper; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.util.DefaultMessageImpl; -import org.apache.ivy.util.Message; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyPostResolveTaskTest extends TestCase { - private File _cache; - - private IvyPostResolveTask _task; - - private Project _project; - - protected void setUp() throws Exception { - Message.init(new DefaultMessageImpl(10)); - - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _task = new IvyPostResolveTask() { - public void doExecute() throws BuildException { - prepareAndCheck(); - } - }; - _task.setProject(_project); - _task.setCache(_cache); - } - - 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(); - } - - public void testWithPreviousResolveInSameBuildAndLessConfs() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("default,compile"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("default"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - } - - public void testWithPreviousResolveInSameBuildAndSameConfs() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("default"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("default"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - } - - public void testWithPreviousResolveInSameBuildAndWildcard() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("*"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("default"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - } - - public void testWithPreviousResolveInSameBuildAndBothWildcard() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("*"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("*"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - } - - public void testWithPreviousResolveInSameBuildAndMoreConfs() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("compile"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0", "mod1.1", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - _task.setConf("*"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertNotSame("IvyPostResolveTask hasn't performed a resolve where it should have", - reportBefore, reportAfter); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testWithoutKeep() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("compile"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0", "mod1.1", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - _task.setConf("*"); // will trigger a resolve - _task.setKeep(false); // don't keep the resolve results - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertSame("IvyPostResolveTask has kept the resolve report where it should have", - reportBefore, reportAfter); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testInlineWithoutKeep() throws Exception { - _task.setOrganisation("org1"); - _task.setModule("mod1.1"); - _task.setRevision("2.0"); - _task.setInline(true); - _task.setConf("*"); // will trigger a resolve - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertNull("IvyPostResolveTask has kept the resolve report where it should have", - reportAfter); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testInlineWithKeep() throws Exception { - _task.setOrganisation("org1"); - _task.setModule("mod1.1"); - _task.setRevision("2.0"); - _task.setInline(true); - _task.setKeep(true); - _task.setConf("*"); // will trigger a resolve - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - - assertNotNull("IvyPostResolveTask has kept the resolve report where it should have", - reportAfter); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testWithResolveIdAndPreviousResolveInSameBuildAndLessConfs() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("default,compile"); - resolve.setResolveId("testResolveId"); - resolve.execute(); - - ResolveReport report1 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - // perform another resolve - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setConf("*"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("default"); - _task.setResolveId("testResolveId"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - ResolveReport report2 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, - report2); - } - - public void testWithResolveIdAndPreviousResolveInSameBuildAndSameConfs() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("default"); - resolve.setResolveId("testResolveId"); - resolve.execute(); - - ResolveReport report1 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - // perform another resolve - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setConf("*"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("default"); - _task.setResolveId("testResolveId"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - ResolveReport report2 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, - report2); - } - - public void testWithResolveIdAndPreviousResolveInSameBuildAndWildcard() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("*"); - resolve.setResolveId("testResolveId"); - resolve.execute(); - - ResolveReport report1 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - // perform another resolve - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setConf("*"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("default"); - _task.setResolveId("testResolveId"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - ResolveReport report2 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, - report2); - } - - public void testWithResolveIdAndPreviousResolveInSameBuildAndBothWildcard() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("*"); - resolve.setResolveId("testResolveId"); - resolve.execute(); - - ResolveReport report1 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - // perform another resolve - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setConf("*"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("*"); - _task.setResolveId("testResolveId"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - ResolveReport report2 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, - reportAfter); - assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, - report2); - } - - public void testWithResolveIdAndPreviousResolveInSameBuildAndMoreConfs() throws Exception { - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); - resolve.setConf("compile"); - resolve.setResolveId("testResolveId"); - resolve.execute(); - - ResolveReport report1 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0", "mod1.1", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // perform another resolve - resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setCache(_cache); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - resolve.setConf("*"); - resolve.execute(); - - ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); - - _task.setConf("*"); - _task.setResolveId("testResolveId"); - _task.execute(); - - ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); - ResolveReport report2 = (ResolveReport) _project - .getReference("ivy.resolved.report.testResolveId"); - - assertNotSame("IvyPostResolveTask hasn't performed a resolve where it should have", - reportBefore, reportAfter); - assertNotSame("IvyPostResolveTask hasn't performed a resolve where it should have", - report1, report2); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - private File getArchiveFileInCache(String organisation, String module, String revision, - String artifact, String type, String ext) { - return TestHelper.getArchiveFileInCache(_task.getIvyInstance(), _cache, organisation, - module, revision, artifact, type, ext); - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.ivy.TestHelper; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.util.DefaultMessageImpl; +import org.apache.ivy.util.Message; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyPostResolveTaskTest extends TestCase { + private File _cache; + + private IvyPostResolveTask _task; + + private Project _project; + + protected void setUp() throws Exception { + Message.init(new DefaultMessageImpl(10)); + + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _task = new IvyPostResolveTask() { + public void doExecute() throws BuildException { + prepareAndCheck(); + } + }; + _task.setProject(_project); + _task.setCache(_cache); + } + + 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(); + } + + public void testWithPreviousResolveInSameBuildAndLessConfs() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("default,compile"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("default"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + } + + public void testWithPreviousResolveInSameBuildAndSameConfs() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("default"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("default"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + } + + public void testWithPreviousResolveInSameBuildAndWildcard() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("*"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("default"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + } + + public void testWithPreviousResolveInSameBuildAndBothWildcard() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("*"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("*"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + } + + public void testWithPreviousResolveInSameBuildAndMoreConfs() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("compile"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0", "mod1.1", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + _task.setConf("*"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertNotSame("IvyPostResolveTask hasn't performed a resolve where it should have", + reportBefore, reportAfter); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testWithoutKeep() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("compile"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0", "mod1.1", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + _task.setConf("*"); // will trigger a resolve + _task.setKeep(false); // don't keep the resolve results + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertSame("IvyPostResolveTask has kept the resolve report where it should have", + reportBefore, reportAfter); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testInlineWithoutKeep() throws Exception { + _task.setOrganisation("org1"); + _task.setModule("mod1.1"); + _task.setRevision("2.0"); + _task.setInline(true); + _task.setConf("*"); // will trigger a resolve + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertNull("IvyPostResolveTask has kept the resolve report where it should have", + reportAfter); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testInlineWithKeep() throws Exception { + _task.setOrganisation("org1"); + _task.setModule("mod1.1"); + _task.setRevision("2.0"); + _task.setInline(true); + _task.setKeep(true); + _task.setConf("*"); // will trigger a resolve + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + + assertNotNull("IvyPostResolveTask has kept the resolve report where it should have", + reportAfter); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testWithResolveIdAndPreviousResolveInSameBuildAndLessConfs() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("default,compile"); + resolve.setResolveId("testResolveId"); + resolve.execute(); + + ResolveReport report1 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + // perform another resolve + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setConf("*"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("default"); + _task.setResolveId("testResolveId"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + ResolveReport report2 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, + report2); + } + + public void testWithResolveIdAndPreviousResolveInSameBuildAndSameConfs() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("default"); + resolve.setResolveId("testResolveId"); + resolve.execute(); + + ResolveReport report1 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + // perform another resolve + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setConf("*"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("default"); + _task.setResolveId("testResolveId"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + ResolveReport report2 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, + report2); + } + + public void testWithResolveIdAndPreviousResolveInSameBuildAndWildcard() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("*"); + resolve.setResolveId("testResolveId"); + resolve.execute(); + + ResolveReport report1 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + // perform another resolve + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setConf("*"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("default"); + _task.setResolveId("testResolveId"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + ResolveReport report2 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, + report2); + } + + public void testWithResolveIdAndPreviousResolveInSameBuildAndBothWildcard() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("*"); + resolve.setResolveId("testResolveId"); + resolve.execute(); + + ResolveReport report1 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + // perform another resolve + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setConf("*"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("*"); + _task.setResolveId("testResolveId"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + ResolveReport report2 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, + reportAfter); + assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, + report2); + } + + public void testWithResolveIdAndPreviousResolveInSameBuildAndMoreConfs() throws Exception { + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml")); + resolve.setConf("compile"); + resolve.setResolveId("testResolveId"); + resolve.execute(); + + ResolveReport report1 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "2.0", "mod1.1", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // perform another resolve + resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setCache(_cache); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + resolve.setConf("*"); + resolve.execute(); + + ResolveReport reportBefore = (ResolveReport) _project.getReference("ivy.resolved.report"); + + _task.setConf("*"); + _task.setResolveId("testResolveId"); + _task.execute(); + + ResolveReport reportAfter = (ResolveReport) _project.getReference("ivy.resolved.report"); + ResolveReport report2 = (ResolveReport) _project + .getReference("ivy.resolved.report.testResolveId"); + + assertNotSame("IvyPostResolveTask hasn't performed a resolve where it should have", + reportBefore, reportAfter); + assertNotSame("IvyPostResolveTask hasn't performed a resolve where it should have", + report1, report2); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + private File getArchiveFileInCache(String organisation, String module, String revision, + String artifact, String type, String ext) { + return TestHelper.getArchiveFileInCache(_task.getIvyInstance(), _cache, organisation, + module, revision, artifact, type, ext); + } +} diff --git a/test/java/org/apache/ivy/ant/IvyPublishTest.java b/test/java/org/apache/ivy/ant/IvyPublishTest.java index 81ab5d69..9d862b9a 100644 --- a/test/java/org/apache/ivy/ant/IvyPublishTest.java +++ b/test/java/org/apache/ivy/ant/IvyPublishTest.java @@ -1,418 +1,418 @@ -/* - * 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.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.InputStreamReader; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; -import org.apache.ivy.util.DefaultMessageImpl; -import org.apache.ivy.util.FileUtil; -import org.apache.ivy.util.Message; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; -import org.apache.tools.ant.taskdefs.Echo; - -public class IvyPublishTest extends TestCase { - private File _cache; - - private IvyPublish _publish; - - private Project _project; - - protected void setUp() throws Exception { - cleanTestDir(); - cleanRep(); - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - _project.setProperty("build", "build/test/publish"); - - _publish = new IvyPublish(); - _publish.setProject(_project); - _publish.setCache(_cache); - - Message.init(new DefaultMessageImpl(10)); - } - - private void createCache() { - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - cleanCache(); - cleanTestDir(); - cleanRep(); - } - - private void cleanCache() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - private void cleanTestDir() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/publish")); - del.execute(); - } - - private void cleanRep() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("test/repositories/1/apache")); - del.execute(); - } - - public void testSimple() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.2"); - _publish.setResolver("1"); - File art = new File("build/test/publish/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - _publish.execute(); - - // should have do the ivy delivering - assertTrue(new File("build/test/publish/ivy-1.2.xml").exists()); - - // should have published the files with "1" resolver - assertTrue(new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").exists()); - assertTrue(new File("test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar") - .exists()); - - // should have updated published ivy version - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), - new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").toURL(), false); - assertEquals("1.2", md.getModuleRevisionId().getRevision()); - } - - public void testPublishNotAllConfigs() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.2"); - _publish.setResolver("1"); - _publish.setConf("compile"); - _publish.setUpdate(true); - File art = new File("build/test/publish/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - _publish.execute(); - - // should have do the ivy delivering - assertTrue(new File("build/test/publish/ivy-1.2.xml").exists()); - - // should have published the files with "1" resolver - assertTrue(new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").exists()); - assertTrue(new File("test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar") - .exists()); - - // should have updated published ivy version - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), - new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").toURL(), false); - assertEquals("1.2", md.getModuleRevisionId().getRevision()); - - // should only contain the default configuration - String[] configs = md.getConfigurationsNames(); - assertEquals("Number of configurations not correct", 1, configs.length); - assertEquals("Compile configuration not present", "compile", configs[0]); - } - - public void testMultiPatterns() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-publish-multi.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.2"); - _publish.setResolver("1"); - File art = new File("build/test/publish/1/multi1-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - art = new File("build/test/publish/2/multi2-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - _publish.addArtifactspattern("build/test/publish/1/[artifact]-[revision].[ext]"); - _publish.addArtifactspattern("build/test/publish/2/[artifact]-[revision].[ext]"); - _publish.execute(); - - // should have do the ivy delivering - assertTrue(new File("build/test/publish/1/ivy-1.2.xml").exists()); - - // should have published the files with "1" resolver - assertTrue(new File("test/repositories/1/apache/multi/ivys/ivy-1.2.xml").exists()); - assertTrue(new File("test/repositories/1/apache/multi/jars/multi1-1.2.jar").exists()); - assertTrue(new File("test/repositories/1/apache/multi/jars/multi2-1.2.jar").exists()); - } - - public void testCustom() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-custom.xml"); - IvyResolve res = new IvyResolve(); - res.setValidate(false); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.2"); - _publish.setPubdate("20060906141243"); - _publish.setResolver("1"); - _publish.setValidate(false); - File art = new File("build/test/publish/resolve-custom-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - _publish.execute(); - - // should have do the ivy delivering - assertTrue(new File("build/test/publish/ivy-1.2.xml").exists()); - - File dest = new File("test/repositories/1/apache/resolve-custom/ivys/ivy-1.2.xml"); - // should have published the files with "1" resolver - assertTrue(dest.exists()); - assertTrue(new File("test/repositories/1/apache/resolve-custom/jars/resolve-custom-1.2.jar") - .exists()); - - // should have updated published ivy version - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), dest.toURL(), false); - assertEquals("1.2", md.getModuleRevisionId().getRevision()); - - // should have kept custom attributes - assertEquals("cval1", md.getModuleRevisionId().getAttribute("custom-info")); - assertEquals("cval2", md.getConfiguration("default").getAttribute("custom-conf")); - assertEquals("cval3", md.getDependencies()[0].getAttribute("custom-dep")); - - // should respect the ivy file, with descriptions, ... - String expected = FileUtil.readEntirely(new BufferedReader(new InputStreamReader( - IvyPublishTest.class.getResourceAsStream("published-ivy-custom.xml")))); - String updated = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))); - assertEquals(expected, updated); - - } - - public void testNoDeliver() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.3"); - _publish.setResolver("1"); - _publish.setSrcivypattern("build/test/publish/ivy-1.3.xml"); - - FileUtil.copy(new File("test/java/org/apache/ivy/ant/ivy-publish.xml"), new File( - "build/test/publish/ivy-1.3.xml"), null); - - File art = new File("build/test/publish/resolve-latest-1.3.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - _publish.execute(); - - // should have published the files with "1" resolver - assertTrue(new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").exists()); - assertTrue(new File("test/repositories/1/apache/resolve-latest/jars/resolve-latest-1.3.jar") - .exists()); - - // the published ivy version should be ok (ok in ivy-publish file) - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), - new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").toURL(), false); - assertEquals("1.3", md.getModuleRevisionId().getRevision()); - - // should not have done delivery (replace dynamic revisions with static ones) - assertEquals("latest.integration", md.getDependencies()[0].getDependencyRevisionId() - .getRevision()); - } - - public void testForceDeliver() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.3"); - _publish.setResolver("1"); - _publish.setSrcivypattern("build/test/publish/ivy-1.3.xml"); - _publish.setForcedeliver(true); - - FileUtil.copy(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"), new File( - "build/test/publish/ivy-1.3.xml"), null); - - File art = new File("build/test/publish/resolve-latest-1.3.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - _publish.execute(); - - // should have published the files with "1" resolver - assertTrue(new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").exists()); - assertTrue(new File("test/repositories/1/apache/resolve-latest/jars/resolve-latest-1.3.jar") - .exists()); - - // should have updated published ivy version - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), - new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").toURL(), false); - assertEquals("1.3", md.getModuleRevisionId().getRevision()); - } - - public void testBadNoDeliver() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.3"); - _publish.setResolver("1"); - _publish.setSrcivypattern("build/test/publish/ivy-1.3.xml"); - - FileUtil.copy(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"), new File( - "build/test/publish/ivy-1.3.xml"), null); - - File art = new File("build/test/publish/resolve-latest-1.3.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - try { - _publish.execute(); - fail("shouldn't publish ivy file with bad revision"); - } catch (BuildException ex) { - - } - } - - public void testReadonly() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.2"); - _publish.setResolver("1"); - File art = new File("build/test/publish/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - - Echo echo = new Echo(); - echo.setProject(_project); - echo.setMessage("new version"); - echo.setFile(art); - echo.execute(); - - File dest = new File( - "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), dest, null); - - echo = new Echo(); - echo.setProject(_project); - echo.setMessage("old version"); - echo.setFile(dest); - echo.execute(); - - dest.setReadOnly(); - - try { - _publish.execute(); - fail("by default, publish should fail when a readonly artifact already exist"); - } catch (Exception ex) { - assertTrue(dest.exists()); - BufferedReader reader = new BufferedReader(new FileReader(dest)); - assertEquals("old version", reader.readLine()); - reader.close(); - } - } - - public void testOverwrite() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.2"); - _publish.setResolver("1"); - File art = new File("build/test/publish/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - - Echo echo = new Echo(); - echo.setProject(_project); - echo.setMessage("new version"); - echo.setFile(art); - echo.execute(); - - File dest = new File( - "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), dest, null); - - echo = new Echo(); - echo.setProject(_project); - echo.setMessage("old version"); - echo.setFile(dest); - echo.execute(); - - _publish.setOverwrite(true); - _publish.execute(); - assertTrue(dest.exists()); - BufferedReader reader = new BufferedReader(new FileReader(dest)); - assertEquals("new version", reader.readLine()); - reader.close(); - } - - public void testOverwriteReadOnly() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _publish.setPubrevision("1.2"); - _publish.setResolver("1"); - File art = new File("build/test/publish/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); - - Echo echo = new Echo(); - echo.setProject(_project); - echo.setMessage("new version"); - echo.setFile(art); - echo.execute(); - - File dest = new File( - "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), dest, null); - - echo = new Echo(); - echo.setProject(_project); - echo.setMessage("old version"); - echo.setFile(dest); - echo.execute(); - - dest.setReadOnly(); - - _publish.setOverwrite(true); - _publish.execute(); - assertTrue(dest.exists()); - BufferedReader reader = new BufferedReader(new FileReader(dest)); - assertEquals("new version", reader.readLine()); - reader.close(); - } - -} +/* + * 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.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.InputStreamReader; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser; +import org.apache.ivy.util.DefaultMessageImpl; +import org.apache.ivy.util.FileUtil; +import org.apache.ivy.util.Message; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; +import org.apache.tools.ant.taskdefs.Echo; + +public class IvyPublishTest extends TestCase { + private File _cache; + + private IvyPublish _publish; + + private Project _project; + + protected void setUp() throws Exception { + cleanTestDir(); + cleanRep(); + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + _project.setProperty("build", "build/test/publish"); + + _publish = new IvyPublish(); + _publish.setProject(_project); + _publish.setCache(_cache); + + Message.init(new DefaultMessageImpl(10)); + } + + private void createCache() { + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + cleanTestDir(); + cleanRep(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + private void cleanTestDir() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/publish")); + del.execute(); + } + + private void cleanRep() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("test/repositories/1/apache")); + del.execute(); + } + + public void testSimple() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.2"); + _publish.setResolver("1"); + File art = new File("build/test/publish/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + _publish.execute(); + + // should have do the ivy delivering + assertTrue(new File("build/test/publish/ivy-1.2.xml").exists()); + + // should have published the files with "1" resolver + assertTrue(new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").exists()); + assertTrue(new File("test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar") + .exists()); + + // should have updated published ivy version + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), + new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").toURL(), false); + assertEquals("1.2", md.getModuleRevisionId().getRevision()); + } + + public void testPublishNotAllConfigs() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.2"); + _publish.setResolver("1"); + _publish.setConf("compile"); + _publish.setUpdate(true); + File art = new File("build/test/publish/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + _publish.execute(); + + // should have do the ivy delivering + assertTrue(new File("build/test/publish/ivy-1.2.xml").exists()); + + // should have published the files with "1" resolver + assertTrue(new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").exists()); + assertTrue(new File("test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar") + .exists()); + + // should have updated published ivy version + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), + new File("test/repositories/1/apache/resolve-simple/ivys/ivy-1.2.xml").toURL(), false); + assertEquals("1.2", md.getModuleRevisionId().getRevision()); + + // should only contain the default configuration + String[] configs = md.getConfigurationsNames(); + assertEquals("Number of configurations not correct", 1, configs.length); + assertEquals("Compile configuration not present", "compile", configs[0]); + } + + public void testMultiPatterns() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-publish-multi.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.2"); + _publish.setResolver("1"); + File art = new File("build/test/publish/1/multi1-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + art = new File("build/test/publish/2/multi2-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + _publish.addArtifactspattern("build/test/publish/1/[artifact]-[revision].[ext]"); + _publish.addArtifactspattern("build/test/publish/2/[artifact]-[revision].[ext]"); + _publish.execute(); + + // should have do the ivy delivering + assertTrue(new File("build/test/publish/1/ivy-1.2.xml").exists()); + + // should have published the files with "1" resolver + assertTrue(new File("test/repositories/1/apache/multi/ivys/ivy-1.2.xml").exists()); + assertTrue(new File("test/repositories/1/apache/multi/jars/multi1-1.2.jar").exists()); + assertTrue(new File("test/repositories/1/apache/multi/jars/multi2-1.2.jar").exists()); + } + + public void testCustom() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-custom.xml"); + IvyResolve res = new IvyResolve(); + res.setValidate(false); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.2"); + _publish.setPubdate("20060906141243"); + _publish.setResolver("1"); + _publish.setValidate(false); + File art = new File("build/test/publish/resolve-custom-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + _publish.execute(); + + // should have do the ivy delivering + assertTrue(new File("build/test/publish/ivy-1.2.xml").exists()); + + File dest = new File("test/repositories/1/apache/resolve-custom/ivys/ivy-1.2.xml"); + // should have published the files with "1" resolver + assertTrue(dest.exists()); + assertTrue(new File("test/repositories/1/apache/resolve-custom/jars/resolve-custom-1.2.jar") + .exists()); + + // should have updated published ivy version + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), dest.toURL(), false); + assertEquals("1.2", md.getModuleRevisionId().getRevision()); + + // should have kept custom attributes + assertEquals("cval1", md.getModuleRevisionId().getAttribute("custom-info")); + assertEquals("cval2", md.getConfiguration("default").getAttribute("custom-conf")); + assertEquals("cval3", md.getDependencies()[0].getAttribute("custom-dep")); + + // should respect the ivy file, with descriptions, ... + String expected = FileUtil.readEntirely(new BufferedReader(new InputStreamReader( + IvyPublishTest.class.getResourceAsStream("published-ivy-custom.xml")))); + String updated = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))); + assertEquals(expected, updated); + + } + + public void testNoDeliver() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.3"); + _publish.setResolver("1"); + _publish.setSrcivypattern("build/test/publish/ivy-1.3.xml"); + + FileUtil.copy(new File("test/java/org/apache/ivy/ant/ivy-publish.xml"), new File( + "build/test/publish/ivy-1.3.xml"), null); + + File art = new File("build/test/publish/resolve-latest-1.3.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + _publish.execute(); + + // should have published the files with "1" resolver + assertTrue(new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").exists()); + assertTrue(new File("test/repositories/1/apache/resolve-latest/jars/resolve-latest-1.3.jar") + .exists()); + + // the published ivy version should be ok (ok in ivy-publish file) + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), + new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").toURL(), false); + assertEquals("1.3", md.getModuleRevisionId().getRevision()); + + // should not have done delivery (replace dynamic revisions with static ones) + assertEquals("latest.integration", md.getDependencies()[0].getDependencyRevisionId() + .getRevision()); + } + + public void testForceDeliver() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.3"); + _publish.setResolver("1"); + _publish.setSrcivypattern("build/test/publish/ivy-1.3.xml"); + _publish.setForcedeliver(true); + + FileUtil.copy(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"), new File( + "build/test/publish/ivy-1.3.xml"), null); + + File art = new File("build/test/publish/resolve-latest-1.3.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + _publish.execute(); + + // should have published the files with "1" resolver + assertTrue(new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").exists()); + assertTrue(new File("test/repositories/1/apache/resolve-latest/jars/resolve-latest-1.3.jar") + .exists()); + + // should have updated published ivy version + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), + new File("test/repositories/1/apache/resolve-latest/ivys/ivy-1.3.xml").toURL(), false); + assertEquals("1.3", md.getModuleRevisionId().getRevision()); + } + + public void testBadNoDeliver() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-latest.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.3"); + _publish.setResolver("1"); + _publish.setSrcivypattern("build/test/publish/ivy-1.3.xml"); + + FileUtil.copy(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"), new File( + "build/test/publish/ivy-1.3.xml"), null); + + File art = new File("build/test/publish/resolve-latest-1.3.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + try { + _publish.execute(); + fail("shouldn't publish ivy file with bad revision"); + } catch (BuildException ex) { + + } + } + + public void testReadonly() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.2"); + _publish.setResolver("1"); + File art = new File("build/test/publish/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + + Echo echo = new Echo(); + echo.setProject(_project); + echo.setMessage("new version"); + echo.setFile(art); + echo.execute(); + + File dest = new File( + "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), dest, null); + + echo = new Echo(); + echo.setProject(_project); + echo.setMessage("old version"); + echo.setFile(dest); + echo.execute(); + + dest.setReadOnly(); + + try { + _publish.execute(); + fail("by default, publish should fail when a readonly artifact already exist"); + } catch (Exception ex) { + assertTrue(dest.exists()); + BufferedReader reader = new BufferedReader(new FileReader(dest)); + assertEquals("old version", reader.readLine()); + reader.close(); + } + } + + public void testOverwrite() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.2"); + _publish.setResolver("1"); + File art = new File("build/test/publish/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + + Echo echo = new Echo(); + echo.setProject(_project); + echo.setMessage("new version"); + echo.setFile(art); + echo.execute(); + + File dest = new File( + "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), dest, null); + + echo = new Echo(); + echo.setProject(_project); + echo.setMessage("old version"); + echo.setFile(dest); + echo.execute(); + + _publish.setOverwrite(true); + _publish.execute(); + assertTrue(dest.exists()); + BufferedReader reader = new BufferedReader(new FileReader(dest)); + assertEquals("new version", reader.readLine()); + reader.close(); + } + + public void testOverwriteReadOnly() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _publish.setPubrevision("1.2"); + _publish.setResolver("1"); + File art = new File("build/test/publish/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art, null); + + Echo echo = new Echo(); + echo.setProject(_project); + echo.setMessage("new version"); + echo.setFile(art); + echo.execute(); + + File dest = new File( + "test/repositories/1/apache/resolve-simple/jars/resolve-simple-1.2.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), dest, null); + + echo = new Echo(); + echo.setProject(_project); + echo.setMessage("old version"); + echo.setFile(dest); + echo.execute(); + + dest.setReadOnly(); + + _publish.setOverwrite(true); + _publish.execute(); + assertTrue(dest.exists()); + BufferedReader reader = new BufferedReader(new FileReader(dest)); + assertEquals("new version", reader.readLine()); + reader.close(); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyReportTest.java b/test/java/org/apache/ivy/ant/IvyReportTest.java index 44cd69fc..c5b52a11 100644 --- a/test/java/org/apache/ivy/ant/IvyReportTest.java +++ b/test/java/org/apache/ivy/ant/IvyReportTest.java @@ -1,79 +1,79 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyReportTest extends TestCase { - private File _cache; - - private IvyReport _report; - - private Project _project; - - protected void setUp() throws Exception { - createCache(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _report = new IvyReport(); - _report.setTaskName("report"); - _report.setProject(_project); - _report.setCache(_cache); - } - - 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(); - } - - public void testRegularCircular() throws Exception { - _project.setProperty("ivy.dep.file", "test/repositories/2/mod11.1/ivy-1.0.xml"); - IvyResolve res = new IvyResolve(); - res.setProject(_project); - res.execute(); - - _report.setTodir(new File(_cache, "report")); - _report.setXml(true); - - // do not test any xsl transformation here, because of problems of build in our continuous - // integration server - _report.setXsl(false); - _report.setGraph(false); - - _report.execute(); - - assertTrue(new File(_cache, "report/org11-mod11.1-compile.xml").exists()); - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyReportTest extends TestCase { + private File _cache; + + private IvyReport _report; + + private Project _project; + + protected void setUp() throws Exception { + createCache(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _report = new IvyReport(); + _report.setTaskName("report"); + _report.setProject(_project); + _report.setCache(_cache); + } + + 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(); + } + + public void testRegularCircular() throws Exception { + _project.setProperty("ivy.dep.file", "test/repositories/2/mod11.1/ivy-1.0.xml"); + IvyResolve res = new IvyResolve(); + res.setProject(_project); + res.execute(); + + _report.setTodir(new File(_cache, "report")); + _report.setXml(true); + + // do not test any xsl transformation here, because of problems of build in our continuous + // integration server + _report.setXsl(false); + _report.setGraph(false); + + _report.execute(); + + assertTrue(new File(_cache, "report/org11-mod11.1-compile.xml").exists()); + } +} diff --git a/test/java/org/apache/ivy/ant/IvyRepositoryReportTest.java b/test/java/org/apache/ivy/ant/IvyRepositoryReportTest.java index 451c79f0..00c7e869 100644 --- a/test/java/org/apache/ivy/ant/IvyRepositoryReportTest.java +++ b/test/java/org/apache/ivy/ant/IvyRepositoryReportTest.java @@ -1,90 +1,90 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyRepositoryReportTest extends TestCase { - private File _cache; - - private IvyRepositoryReport _report; - - protected void setUp() throws Exception { - createCache(); - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings-1.xml"); - - _report = new IvyRepositoryReport(); - _report.setProject(project); - _report.setCache(_cache); - } - - 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(); - } - - public void test() { - } - - // no xslt transformation is possible in the junit test on our continuous integration server for - // the moment... - // public void testGraph() throws Exception { - // _report.setOrganisation("org1"); - // _report.setXml(false); - // _report.setGraph(true); - // _report.setTodir(_cache); - // _report.setOutputname("test-graph"); - // _report.execute(); - // File graphml = new File(_cache, "test-graph.graphml"); - // assertTrue(graphml.exists()); - // String g = FileUtil.readEntirely(new BufferedReader(new FileReader(graphml))); - // assertFalse(g.indexOf("caller") != -1); - // assertTrue(g.indexOf("mod1.1") != -1); - // } - // - // public void testDot() throws Exception { - // _report.setOrganisation("org1"); - // _report.setXml(false); - // _report.setDot(true); - // _report.setTodir(_cache); - // _report.setOutputname("test-graph"); - // _report.execute(); - // File dot = new File(_cache, "test-graph.dot"); - // assertTrue(dot.exists()); - // String g = FileUtil.readEntirely(new BufferedReader(new FileReader(dot))); - // assertFalse(g.indexOf("caller") != -1); - // assertTrue(g.indexOf("mod1.1") != -1); - // } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyRepositoryReportTest extends TestCase { + private File _cache; + + private IvyRepositoryReport _report; + + protected void setUp() throws Exception { + createCache(); + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings-1.xml"); + + _report = new IvyRepositoryReport(); + _report.setProject(project); + _report.setCache(_cache); + } + + 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(); + } + + public void test() { + } + + // no xslt transformation is possible in the junit test on our continuous integration server for + // the moment... + // public void testGraph() throws Exception { + // _report.setOrganisation("org1"); + // _report.setXml(false); + // _report.setGraph(true); + // _report.setTodir(_cache); + // _report.setOutputname("test-graph"); + // _report.execute(); + // File graphml = new File(_cache, "test-graph.graphml"); + // assertTrue(graphml.exists()); + // String g = FileUtil.readEntirely(new BufferedReader(new FileReader(graphml))); + // assertFalse(g.indexOf("caller") != -1); + // assertTrue(g.indexOf("mod1.1") != -1); + // } + // + // public void testDot() throws Exception { + // _report.setOrganisation("org1"); + // _report.setXml(false); + // _report.setDot(true); + // _report.setTodir(_cache); + // _report.setOutputname("test-graph"); + // _report.execute(); + // File dot = new File(_cache, "test-graph.dot"); + // assertTrue(dot.exists()); + // String g = FileUtil.readEntirely(new BufferedReader(new FileReader(dot))); + // assertFalse(g.indexOf("caller") != -1); + // assertTrue(g.indexOf("mod1.1") != -1); + // } +} diff --git a/test/java/org/apache/ivy/ant/IvyResolveTest.java b/test/java/org/apache/ivy/ant/IvyResolveTest.java index 112bf813..d61e2974 100644 --- a/test/java/org/apache/ivy/ant/IvyResolveTest.java +++ b/test/java/org/apache/ivy/ant/IvyResolveTest.java @@ -1,329 +1,329 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.TestHelper; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyResolveTest extends TestCase { - private File _cache; - - private IvyResolve _resolve; - - protected void setUp() throws Exception { - createCache(); - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _resolve = new IvyResolve(); - _resolve.setProject(project); - _resolve.setCache(_cache); - } - - 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(); - } - - public void testSimple() throws Exception { - // depends on org="org1" name="mod1.2" rev="2.0" - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _resolve.execute(); - - assertTrue(getResolvedIvyFileInCache( - ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); - - // dependencies - assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) - .exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - private File getArchiveFileInCache(String organisation, String module, String revision, - String artifact, String type, String ext) { - return TestHelper.getArchiveFileInCache(getIvy(), _cache, organisation, module, revision, - artifact, type, ext); - } - - private File getIvyFileInCache(ModuleRevisionId id) { - return getIvy().getCacheManager(_cache).getIvyFileInCache(id); - } - - private File getResolvedIvyFileInCache(ModuleRevisionId id) { - return getIvy().getCacheManager(_cache).getResolvedIvyFileInCache(id); - } - - public void testInline() throws Exception { - // same as before, but expressing dependency directly without ivy file - _resolve.setOrganisation("org1"); - _resolve.setModule("mod1.2"); - _resolve.setRevision("2.0"); - _resolve.setInline(true); - _resolve.execute(); - - // dependencies - assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) - .exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testWithSlashes() throws Exception { - _resolve.setFile(new File("test/java/org/apache/ivy/core/resolve/ivy-198.xml")); - _resolve.execute(); - - File resolvedIvyFileInCache = getResolvedIvyFileInCache(ModuleRevisionId.newInstance( - "myorg/mydep", "system/module", "1.0")); - assertTrue(resolvedIvyFileInCache.exists()); - - // dependencies - assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) - .exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(getIvyFileInCache( - ModuleRevisionId.newInstance("yourorg/yourdep", "yoursys/yourmod", "1.0")).exists()); - assertTrue(getArchiveFileInCache("yourorg/yourdep", "yoursys/yourmod", "1.0", "yourmod", - "jar", "jar").exists()); - } - - public void testDepsChanged() throws Exception { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _resolve.execute(); - - assertEquals("true", getIvy().getVariable("ivy.deps.changed")); - - _resolve.execute(); - - assertEquals("false", getIvy().getVariable("ivy.deps.changed")); - } - - public void testConflictingDepsChanged() throws Exception { - _resolve.setFile(new File("test/repositories/2/mod4.1/ivy-4.1.xml")); - _resolve.execute(); - - assertEquals("true", getIvy().getVariable("ivy.deps.changed")); - - _resolve.execute(); - - assertEquals("false", getIvy().getVariable("ivy.deps.changed")); - } - - public void testDouble() throws Exception { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _resolve.execute(); - - assertEquals("resolve-simple", getIvy().getVariable("ivy.module")); - assertEquals("1.0", getIvy().getVariable("ivy.revision")); - - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-double.xml")); - _resolve.execute(); - - assertEquals("resolve-double", getIvy().getVariable("ivy.module")); - assertEquals("1.1", getIvy().getVariable("ivy.revision")); - } - - public void testFailure() throws Exception { - try { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure.xml")); - _resolve.execute(); - fail("failure didn't raised an exception with default haltonfailure setting"); - } catch (BuildException ex) { - // ok => should raise an exception - } - } - - public void testFailureOnBadDependencyIvyFile() throws Exception { - try { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure2.xml")); - _resolve.execute(); - fail("failure didn't raised an exception with default haltonfailure setting"); - } catch (BuildException ex) { - // ok => should raise an exception - } - } - - public void testFailureOnBadStatusInDependencyIvyFile() throws Exception { - try { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure3.xml")); - _resolve.execute(); - fail("failure didn't raised an exception with default haltonfailure setting"); - } catch (BuildException ex) { - // ok => should raise an exception - } - } - - public void testHaltOnFailure() throws Exception { - try { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure.xml")); - _resolve.setHaltonfailure(false); - _resolve.execute(); - } catch (BuildException ex) { - ex.printStackTrace(); - fail("failure raised an exception with haltonfailure set to false"); - } - } - - public void testWithResolveId() throws Exception { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _resolve.setResolveId("testWithResolveId"); - _resolve.execute(); - - assertTrue(getResolvedIvyFileInCache( - ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); - assertTrue(getIvy().getCacheManager(_cache).getConfigurationResolveReportInCache( - "testWithResolveId", "default").exists()); - - // dependencies - assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) - .exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // test the properties - Project project = _resolve.getProject(); - assertEquals("apache", project.getProperty("ivy.organisation")); - assertEquals("apache", project.getProperty("ivy.organisation.testWithResolveId")); - assertEquals("resolve-simple", project.getProperty("ivy.module")); - assertEquals("resolve-simple", project.getProperty("ivy.module.testWithResolveId")); - assertEquals("1.0", project.getProperty("ivy.revision")); - assertEquals("1.0", project.getProperty("ivy.revision.testWithResolveId")); - assertEquals("true", project.getProperty("ivy.deps.changed")); - assertEquals("true", project.getProperty("ivy.deps.changed.testWithResolveId")); - assertEquals("default", project.getProperty("ivy.resolved.configurations")); - assertEquals("default", project - .getProperty("ivy.resolved.configurations.testWithResolveId")); - - // test the references - assertNotNull(project.getReference("ivy.resolved.report")); - assertNotNull(project.getReference("ivy.resolved.report.testWithResolveId")); - assertNotNull(project.getReference("ivy.resolved.descriptor")); - assertNotNull(project.getReference("ivy.resolved.descriptor.testWithResolveId")); - assertNotNull(project.getReference("ivy.resolved.configurations.ref")); - assertNotNull(project.getReference("ivy.resolved.configurations.ref.testWithResolveId")); - } - - public void testDoubleResolveWithResolveId() throws Exception { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _resolve.setResolveId("testWithResolveId"); - _resolve.execute(); - - IvyResolve newResolve = new IvyResolve(); - newResolve.setProject(_resolve.getProject()); - newResolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple2.xml")); - newResolve.execute(); - - // test the properties - Project project = _resolve.getProject(); - assertEquals("apache2", project.getProperty("ivy.organisation")); - assertEquals("apache", project.getProperty("ivy.organisation.testWithResolveId")); - assertEquals("resolve-simple2", project.getProperty("ivy.module")); - assertEquals("resolve-simple", project.getProperty("ivy.module.testWithResolveId")); - assertEquals("1.1", project.getProperty("ivy.revision")); - assertEquals("1.0", project.getProperty("ivy.revision.testWithResolveId")); - assertEquals("true", project.getProperty("ivy.deps.changed")); - assertEquals("true", project.getProperty("ivy.deps.changed.testWithResolveId")); - assertEquals("default", project.getProperty("ivy.resolved.configurations")); - assertEquals("default", project - .getProperty("ivy.resolved.configurations.testWithResolveId")); - - // test the references - assertNotNull(project.getReference("ivy.resolved.report")); - assertNotNull(project.getReference("ivy.resolved.report.testWithResolveId")); - assertNotNull(project.getReference("ivy.resolved.descriptor")); - assertNotNull(project.getReference("ivy.resolved.descriptor.testWithResolveId")); - assertNotNull(project.getReference("ivy.resolved.configurations.ref")); - assertNotNull(project.getReference("ivy.resolved.configurations.ref.testWithResolveId")); - } - - public void testDifferentResolveWithSameResolveId() throws Exception { - _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); - _resolve.setResolveId("testWithResolveId"); - _resolve.execute(); - - IvyResolve newResolve = new IvyResolve(); - newResolve.setProject(_resolve.getProject()); - newResolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple2.xml")); - newResolve.setResolveId("testWithResolveId"); - newResolve.execute(); - - // test the properties - Project project = _resolve.getProject(); - assertEquals("apache2", project.getProperty("ivy.organisation")); - assertEquals("apache2", project.getProperty("ivy.organisation.testWithResolveId")); - assertEquals("resolve-simple2", project.getProperty("ivy.module")); - assertEquals("resolve-simple2", project.getProperty("ivy.module.testWithResolveId")); - assertEquals("1.1", project.getProperty("ivy.revision")); - assertEquals("1.1", project.getProperty("ivy.revision.testWithResolveId")); - assertEquals("true", project.getProperty("ivy.deps.changed")); - assertEquals("true", project.getProperty("ivy.deps.changed.testWithResolveId")); - assertEquals("default", project.getProperty("ivy.resolved.configurations")); - assertEquals("default", project - .getProperty("ivy.resolved.configurations.testWithResolveId")); - - // test the references - assertNotNull(project.getReference("ivy.resolved.report")); - assertNotNull(project.getReference("ivy.resolved.report.testWithResolveId")); - assertNotNull(project.getReference("ivy.resolved.descriptor")); - assertNotNull(project.getReference("ivy.resolved.descriptor.testWithResolveId")); - assertNotNull(project.getReference("ivy.resolved.configurations.ref")); - assertNotNull(project.getReference("ivy.resolved.configurations.ref.testWithResolveId")); - } - - public void testResolveWithAbsoluteFile() { - // IVY-396 - File ivyFile = new File("test/java/org/apache/ivy/ant/ivy-simple.xml"); - _resolve.getProject().setProperty("ivy.dep.file", ivyFile.getAbsolutePath()); - _resolve.execute(); - - assertTrue(getResolvedIvyFileInCache( - ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); - } - - public void testResolveWithRelativeFile() { - // IVY-396 - _resolve.getProject().setProperty("ivy.dep.file", - "test/java/org/apache/ivy/ant/ivy-simple.xml"); - _resolve.execute(); - - assertTrue(getResolvedIvyFileInCache( - ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); - } - - private Ivy getIvy() { - return _resolve.getIvyInstance(); - } - -} +/* + * 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 junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.TestHelper; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyResolveTest extends TestCase { + private File _cache; + + private IvyResolve _resolve; + + protected void setUp() throws Exception { + createCache(); + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _resolve = new IvyResolve(); + _resolve.setProject(project); + _resolve.setCache(_cache); + } + + 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(); + } + + public void testSimple() throws Exception { + // depends on org="org1" name="mod1.2" rev="2.0" + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _resolve.execute(); + + assertTrue(getResolvedIvyFileInCache( + ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); + + // dependencies + assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) + .exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + private File getArchiveFileInCache(String organisation, String module, String revision, + String artifact, String type, String ext) { + return TestHelper.getArchiveFileInCache(getIvy(), _cache, organisation, module, revision, + artifact, type, ext); + } + + private File getIvyFileInCache(ModuleRevisionId id) { + return getIvy().getCacheManager(_cache).getIvyFileInCache(id); + } + + private File getResolvedIvyFileInCache(ModuleRevisionId id) { + return getIvy().getCacheManager(_cache).getResolvedIvyFileInCache(id); + } + + public void testInline() throws Exception { + // same as before, but expressing dependency directly without ivy file + _resolve.setOrganisation("org1"); + _resolve.setModule("mod1.2"); + _resolve.setRevision("2.0"); + _resolve.setInline(true); + _resolve.execute(); + + // dependencies + assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) + .exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testWithSlashes() throws Exception { + _resolve.setFile(new File("test/java/org/apache/ivy/core/resolve/ivy-198.xml")); + _resolve.execute(); + + File resolvedIvyFileInCache = getResolvedIvyFileInCache(ModuleRevisionId.newInstance( + "myorg/mydep", "system/module", "1.0")); + assertTrue(resolvedIvyFileInCache.exists()); + + // dependencies + assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) + .exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(getIvyFileInCache( + ModuleRevisionId.newInstance("yourorg/yourdep", "yoursys/yourmod", "1.0")).exists()); + assertTrue(getArchiveFileInCache("yourorg/yourdep", "yoursys/yourmod", "1.0", "yourmod", + "jar", "jar").exists()); + } + + public void testDepsChanged() throws Exception { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _resolve.execute(); + + assertEquals("true", getIvy().getVariable("ivy.deps.changed")); + + _resolve.execute(); + + assertEquals("false", getIvy().getVariable("ivy.deps.changed")); + } + + public void testConflictingDepsChanged() throws Exception { + _resolve.setFile(new File("test/repositories/2/mod4.1/ivy-4.1.xml")); + _resolve.execute(); + + assertEquals("true", getIvy().getVariable("ivy.deps.changed")); + + _resolve.execute(); + + assertEquals("false", getIvy().getVariable("ivy.deps.changed")); + } + + public void testDouble() throws Exception { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _resolve.execute(); + + assertEquals("resolve-simple", getIvy().getVariable("ivy.module")); + assertEquals("1.0", getIvy().getVariable("ivy.revision")); + + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-double.xml")); + _resolve.execute(); + + assertEquals("resolve-double", getIvy().getVariable("ivy.module")); + assertEquals("1.1", getIvy().getVariable("ivy.revision")); + } + + public void testFailure() throws Exception { + try { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure.xml")); + _resolve.execute(); + fail("failure didn't raised an exception with default haltonfailure setting"); + } catch (BuildException ex) { + // ok => should raise an exception + } + } + + public void testFailureOnBadDependencyIvyFile() throws Exception { + try { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure2.xml")); + _resolve.execute(); + fail("failure didn't raised an exception with default haltonfailure setting"); + } catch (BuildException ex) { + // ok => should raise an exception + } + } + + public void testFailureOnBadStatusInDependencyIvyFile() throws Exception { + try { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure3.xml")); + _resolve.execute(); + fail("failure didn't raised an exception with default haltonfailure setting"); + } catch (BuildException ex) { + // ok => should raise an exception + } + } + + public void testHaltOnFailure() throws Exception { + try { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-failure.xml")); + _resolve.setHaltonfailure(false); + _resolve.execute(); + } catch (BuildException ex) { + ex.printStackTrace(); + fail("failure raised an exception with haltonfailure set to false"); + } + } + + public void testWithResolveId() throws Exception { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _resolve.setResolveId("testWithResolveId"); + _resolve.execute(); + + assertTrue(getResolvedIvyFileInCache( + ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); + assertTrue(getIvy().getCacheManager(_cache).getConfigurationResolveReportInCache( + "testWithResolveId", "default").exists()); + + // dependencies + assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")) + .exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // test the properties + Project project = _resolve.getProject(); + assertEquals("apache", project.getProperty("ivy.organisation")); + assertEquals("apache", project.getProperty("ivy.organisation.testWithResolveId")); + assertEquals("resolve-simple", project.getProperty("ivy.module")); + assertEquals("resolve-simple", project.getProperty("ivy.module.testWithResolveId")); + assertEquals("1.0", project.getProperty("ivy.revision")); + assertEquals("1.0", project.getProperty("ivy.revision.testWithResolveId")); + assertEquals("true", project.getProperty("ivy.deps.changed")); + assertEquals("true", project.getProperty("ivy.deps.changed.testWithResolveId")); + assertEquals("default", project.getProperty("ivy.resolved.configurations")); + assertEquals("default", project + .getProperty("ivy.resolved.configurations.testWithResolveId")); + + // test the references + assertNotNull(project.getReference("ivy.resolved.report")); + assertNotNull(project.getReference("ivy.resolved.report.testWithResolveId")); + assertNotNull(project.getReference("ivy.resolved.descriptor")); + assertNotNull(project.getReference("ivy.resolved.descriptor.testWithResolveId")); + assertNotNull(project.getReference("ivy.resolved.configurations.ref")); + assertNotNull(project.getReference("ivy.resolved.configurations.ref.testWithResolveId")); + } + + public void testDoubleResolveWithResolveId() throws Exception { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _resolve.setResolveId("testWithResolveId"); + _resolve.execute(); + + IvyResolve newResolve = new IvyResolve(); + newResolve.setProject(_resolve.getProject()); + newResolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple2.xml")); + newResolve.execute(); + + // test the properties + Project project = _resolve.getProject(); + assertEquals("apache2", project.getProperty("ivy.organisation")); + assertEquals("apache", project.getProperty("ivy.organisation.testWithResolveId")); + assertEquals("resolve-simple2", project.getProperty("ivy.module")); + assertEquals("resolve-simple", project.getProperty("ivy.module.testWithResolveId")); + assertEquals("1.1", project.getProperty("ivy.revision")); + assertEquals("1.0", project.getProperty("ivy.revision.testWithResolveId")); + assertEquals("true", project.getProperty("ivy.deps.changed")); + assertEquals("true", project.getProperty("ivy.deps.changed.testWithResolveId")); + assertEquals("default", project.getProperty("ivy.resolved.configurations")); + assertEquals("default", project + .getProperty("ivy.resolved.configurations.testWithResolveId")); + + // test the references + assertNotNull(project.getReference("ivy.resolved.report")); + assertNotNull(project.getReference("ivy.resolved.report.testWithResolveId")); + assertNotNull(project.getReference("ivy.resolved.descriptor")); + assertNotNull(project.getReference("ivy.resolved.descriptor.testWithResolveId")); + assertNotNull(project.getReference("ivy.resolved.configurations.ref")); + assertNotNull(project.getReference("ivy.resolved.configurations.ref.testWithResolveId")); + } + + public void testDifferentResolveWithSameResolveId() throws Exception { + _resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml")); + _resolve.setResolveId("testWithResolveId"); + _resolve.execute(); + + IvyResolve newResolve = new IvyResolve(); + newResolve.setProject(_resolve.getProject()); + newResolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple2.xml")); + newResolve.setResolveId("testWithResolveId"); + newResolve.execute(); + + // test the properties + Project project = _resolve.getProject(); + assertEquals("apache2", project.getProperty("ivy.organisation")); + assertEquals("apache2", project.getProperty("ivy.organisation.testWithResolveId")); + assertEquals("resolve-simple2", project.getProperty("ivy.module")); + assertEquals("resolve-simple2", project.getProperty("ivy.module.testWithResolveId")); + assertEquals("1.1", project.getProperty("ivy.revision")); + assertEquals("1.1", project.getProperty("ivy.revision.testWithResolveId")); + assertEquals("true", project.getProperty("ivy.deps.changed")); + assertEquals("true", project.getProperty("ivy.deps.changed.testWithResolveId")); + assertEquals("default", project.getProperty("ivy.resolved.configurations")); + assertEquals("default", project + .getProperty("ivy.resolved.configurations.testWithResolveId")); + + // test the references + assertNotNull(project.getReference("ivy.resolved.report")); + assertNotNull(project.getReference("ivy.resolved.report.testWithResolveId")); + assertNotNull(project.getReference("ivy.resolved.descriptor")); + assertNotNull(project.getReference("ivy.resolved.descriptor.testWithResolveId")); + assertNotNull(project.getReference("ivy.resolved.configurations.ref")); + assertNotNull(project.getReference("ivy.resolved.configurations.ref.testWithResolveId")); + } + + public void testResolveWithAbsoluteFile() { + // IVY-396 + File ivyFile = new File("test/java/org/apache/ivy/ant/ivy-simple.xml"); + _resolve.getProject().setProperty("ivy.dep.file", ivyFile.getAbsolutePath()); + _resolve.execute(); + + assertTrue(getResolvedIvyFileInCache( + ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); + } + + public void testResolveWithRelativeFile() { + // IVY-396 + _resolve.getProject().setProperty("ivy.dep.file", + "test/java/org/apache/ivy/ant/ivy-simple.xml"); + _resolve.execute(); + + assertTrue(getResolvedIvyFileInCache( + ModuleRevisionId.newInstance("apache", "resolve-simple", "1.0")).exists()); + } + + private Ivy getIvy() { + return _resolve.getIvyInstance(); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyRetrieveTest.java b/test/java/org/apache/ivy/ant/IvyRetrieveTest.java index 9d73737b..452cbca3 100644 --- a/test/java/org/apache/ivy/ant/IvyRetrieveTest.java +++ b/test/java/org/apache/ivy/ant/IvyRetrieveTest.java @@ -1,339 +1,339 @@ -/* - * 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.IOException; - -import junit.framework.TestCase; - -import org.apache.ivy.TestHelper; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class IvyRetrieveTest extends TestCase { - private static final String IVY_RETRIEVE_PATTERN = "build/test/lib/[organisation]/[module]/ivy-[revision].xml"; - - private static final String RETRIEVE_PATTERN = "build/test/lib/[conf]/[artifact]-[revision].[type]"; - - private File _cache; - - private IvyRetrieve _retrieve; - - private Project _project; - - protected void setUp() throws Exception { - createCache(); - cleanTestLib(); - _project = new Project(); - _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - - _retrieve = new IvyRetrieve(); - _retrieve.setProject(_project); - _retrieve.setCache(_cache); - _retrieve.setPattern(RETRIEVE_PATTERN); - } - - private void createCache() { - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - cleanCache(); - cleanTestLib(); - } - - private void cleanCache() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - private void cleanTestLib() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/lib")); - del.execute(); - } - - public void testSimple() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - _retrieve.execute(); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", - "mod1.2", "jar", "jar")).exists()); - } - - public void testRetrievePrivateWithWildcard() throws Exception { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-381.xml"); - _retrieve.setConf("*"); - _retrieve.execute(); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "1.1", - "mod1.2", "jar", "jar", "public")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org3", "mod3.2", "1.4", - "mod3.2", "jar", "jar", "private")).exists()); - } - - public void testInline() throws Exception { - // we first resolve another ivy file - IvyResolve resolve = new IvyResolve(); - resolve.setProject(_project); - resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); - resolve.execute(); - - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - - // then we resolve a dependency directly - _retrieve.setOrganisation("org1"); - _retrieve.setModule("mod1.2"); - _retrieve.setRevision("2.0"); - _retrieve.setInline(true); - _retrieve.execute(); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", - "mod1.2", "jar", "jar")).exists()); - } - - public void testWithConf() throws Exception { - _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); - _retrieve.execute(); - - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "jar", "jar", "default")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "jar", "jar", "extension")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.1", - "mod1.2", "jar", "jar", "extension")).exists()); - } - - public void testSync() throws Exception { - _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); - _retrieve.setSync(true); - - File[] old = new File[] { - new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "jar", "jar", "unknown")), // unknown configuration - new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "unknown", "unknown", "default")), // unknown type - new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "unknown", "jar", "jar", "default")), // unknown artifact - new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "unknown", - "mod6.1", "jar", "jar", "default")), // unknown revision - }; - for (int i = 0; i < old.length; i++) { - touch(old[i]); - } - _retrieve.execute(); - - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "jar", "jar", "default")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "jar", "jar", "extension")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.1", - "mod1.2", "jar", "jar", "extension")).exists()); - for (int i = 0; i < old.length; i++) { - assertFalse(old[i] + " should have been deleted by sync", old[i].exists()); - } - assertFalse(new File("build/test/lib/unknown").exists()); // even conf directory should - // have been deleted - } - - public void testWithAPreviousResolve() throws Exception { - // first we do a resolve in another project - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - IvyResolve resolve = new IvyResolve(); - resolve.setProject(project); - resolve.setCache(_cache); - resolve.execute(); - - // then we do a retrieve with the correct module information - _retrieve.setOrganisation("apache"); - _retrieve.setModule("resolve-simple"); - _retrieve.setConf("default"); - _retrieve.execute(); - - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", - "mod1.2", "jar", "jar")).exists()); - } - - public void testUseOrigin() throws Exception { - // test case for IVY-304 - // first we do a resolve with useOrigin=true in another project - Project project = new Project(); - project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); - project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); - IvyResolve resolve = new IvyResolve(); - resolve.setProject(project); - resolve.setCache(_cache); - resolve.setUseOrigin(true); - resolve.execute(); - - // then we do a retrieve with the correct module information and useOrigin=false - _retrieve.setOrganisation("apache"); - _retrieve.setModule("resolve-simple"); - _retrieve.setConf("default"); - _retrieve.setUseOrigin(false); - _retrieve.execute(); - - assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", - "mod1.2", "jar", "jar")).exists()); - } - - public void testFailureWithoutAPreviousResolve() throws Exception { - // we do a retrieve with the module information whereas no resolve has been previously done - try { - _retrieve.setOrganisation("apache"); - _retrieve.setModule("resolve-simple"); - _retrieve.setConf("default"); - _retrieve.execute(); - fail("retrieve without previous resolve should have thrown an exception"); - } catch (Exception ex) { - // OK - } - } - - public void testFailure() throws Exception { - try { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); - _retrieve.execute(); - fail("failure didn't raised an exception with default haltonfailure setting"); - } catch (BuildException ex) { - // ok => should raised an exception - } - } - - public void testHaltOnFailure() throws Exception { - try { - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); - _retrieve.setHaltonfailure(false); - _retrieve.execute(); - - } catch (BuildException ex) { - fail("failure raised an exception with haltonfailure set to false"); - } - } - - public void testCustomIvyPattern() throws Exception { - // mod2.5 depends on virtual mod2.3 which depends on mod2.1 which depends on mod1.1 which - // depends on mod1.2 - _project.setProperty("ivy.dep.file", "test/repositories/1/org2/mod2.5/ivys/ivy-0.6.1.xml"); - - String ivyPattern = IVY_RETRIEVE_PATTERN; - - _retrieve.setIvypattern(ivyPattern); - _retrieve.execute(); - - assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org2", "mod2.3", "0.4.1", - "ivy", "ivy", "xml")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org2", "mod2.1", "0.3", "ivy", - "ivy", "xml")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.1", "1.0", "ivy", - "ivy", "xml")).exists()); - assertFalse(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.2", "2.0", - "ivy", "ivy", "xml")).exists()); - } - - public void testCustomIvyPatternWithConf() throws Exception { - _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); - - String ivyPattern = "build/test/lib/[conf]/[organisation]/[module]/ivy-[revision].xml"; - - _retrieve.setIvypattern(ivyPattern); - _retrieve.execute(); - - assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", - "ivy", "xml", "default")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", - "ivy", "xml", "extension")).exists()); - assertFalse(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.2", "2.1", - "ivy", "ivy", "xml", "extension")).exists()); - } - - public void testSyncWithIvyPattern() throws Exception { - _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); - - String ivyPattern = "build/test/lib/[conf]/[organisation]/[module]/ivy-[revision].xml"; - - _retrieve.setIvypattern(ivyPattern); - - _retrieve.setSync(true); - - File[] old = new File[] { - new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "jar", "jar", "unknown")), // unknown configuration - new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", - "mod6.1", "unknown", "unknown", "default")), // unknown type - new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", - "ivy", "xml", "unk")), // unknown conf for ivy - new File(IvyPatternHelper.substitute(ivyPattern, "unknown", "mod6.1", "0.4", "ivy", - "ivy", "xml", "default")), // unknown organisation for ivy - }; - for (int i = 0; i < old.length; i++) { - touch(old[i]); - } - - _retrieve.execute(); - - assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", - "ivy", "xml", "default")).exists()); - assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", - "ivy", "xml", "extension")).exists()); - assertFalse(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.2", "2.1", - "ivy", "ivy", "xml", "extension")).exists()); - for (int i = 0; i < old.length; i++) { - assertFalse(old[i] + " should have been deleted by sync", old[i].exists()); - } - assertFalse(new File("build/test/lib/unknown").exists()); - assertFalse(new File("build/test/lib/unk").exists()); - assertFalse(new File("build/test/lib/default/unknown").exists()); - } - - public void testDoubleRetrieveWithDifferentConfigurations() { - // IVY-315 - _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-doubleretrieve.xml"); - - _retrieve.setConf("compile"); - _retrieve.execute(); - - _retrieve = new IvyRetrieve(); - _retrieve.setProject(_project); - _retrieve.setCache(_cache); - _retrieve.setPattern(RETRIEVE_PATTERN); - _retrieve.setConf("compile,unittest"); - _retrieve.execute(); - } - - // creates an empty file, creating parent directories if necessary - private void touch(File file) throws IOException { - if (file.getParentFile() != null) { - file.getParentFile().mkdirs(); - } - file.createNewFile(); - } - - private File getArchiveFileInCache(String organisation, String module, String revision, - String artifact, String type, String ext) { - return TestHelper.getArchiveFileInCache(_retrieve.getIvyInstance(), _cache, organisation, - module, revision, artifact, type, ext); - } - -} +/* + * 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.IOException; + +import junit.framework.TestCase; + +import org.apache.ivy.TestHelper; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class IvyRetrieveTest extends TestCase { + private static final String IVY_RETRIEVE_PATTERN = "build/test/lib/[organisation]/[module]/ivy-[revision].xml"; + + private static final String RETRIEVE_PATTERN = "build/test/lib/[conf]/[artifact]-[revision].[type]"; + + private File _cache; + + private IvyRetrieve _retrieve; + + private Project _project; + + protected void setUp() throws Exception { + createCache(); + cleanTestLib(); + _project = new Project(); + _project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + + _retrieve = new IvyRetrieve(); + _retrieve.setProject(_project); + _retrieve.setCache(_cache); + _retrieve.setPattern(RETRIEVE_PATTERN); + } + + private void createCache() { + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + cleanTestLib(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + private void cleanTestLib() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/lib")); + del.execute(); + } + + public void testSimple() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + _retrieve.execute(); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", + "mod1.2", "jar", "jar")).exists()); + } + + public void testRetrievePrivateWithWildcard() throws Exception { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-381.xml"); + _retrieve.setConf("*"); + _retrieve.execute(); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "1.1", + "mod1.2", "jar", "jar", "public")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org3", "mod3.2", "1.4", + "mod3.2", "jar", "jar", "private")).exists()); + } + + public void testInline() throws Exception { + // we first resolve another ivy file + IvyResolve resolve = new IvyResolve(); + resolve.setProject(_project); + resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml")); + resolve.execute(); + + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + + // then we resolve a dependency directly + _retrieve.setOrganisation("org1"); + _retrieve.setModule("mod1.2"); + _retrieve.setRevision("2.0"); + _retrieve.setInline(true); + _retrieve.execute(); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", + "mod1.2", "jar", "jar")).exists()); + } + + public void testWithConf() throws Exception { + _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); + _retrieve.execute(); + + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "jar", "jar", "default")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "jar", "jar", "extension")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.1", + "mod1.2", "jar", "jar", "extension")).exists()); + } + + public void testSync() throws Exception { + _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); + _retrieve.setSync(true); + + File[] old = new File[] { + new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "jar", "jar", "unknown")), // unknown configuration + new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "unknown", "unknown", "default")), // unknown type + new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "unknown", "jar", "jar", "default")), // unknown artifact + new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "unknown", + "mod6.1", "jar", "jar", "default")), // unknown revision + }; + for (int i = 0; i < old.length; i++) { + touch(old[i]); + } + _retrieve.execute(); + + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "jar", "jar", "default")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "jar", "jar", "extension")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.1", + "mod1.2", "jar", "jar", "extension")).exists()); + for (int i = 0; i < old.length; i++) { + assertFalse(old[i] + " should have been deleted by sync", old[i].exists()); + } + assertFalse(new File("build/test/lib/unknown").exists()); // even conf directory should + // have been deleted + } + + public void testWithAPreviousResolve() throws Exception { + // first we do a resolve in another project + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + IvyResolve resolve = new IvyResolve(); + resolve.setProject(project); + resolve.setCache(_cache); + resolve.execute(); + + // then we do a retrieve with the correct module information + _retrieve.setOrganisation("apache"); + _retrieve.setModule("resolve-simple"); + _retrieve.setConf("default"); + _retrieve.execute(); + + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", + "mod1.2", "jar", "jar")).exists()); + } + + public void testUseOrigin() throws Exception { + // test case for IVY-304 + // first we do a resolve with useOrigin=true in another project + Project project = new Project(); + project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); + project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-simple.xml"); + IvyResolve resolve = new IvyResolve(); + resolve.setProject(project); + resolve.setCache(_cache); + resolve.setUseOrigin(true); + resolve.execute(); + + // then we do a retrieve with the correct module information and useOrigin=false + _retrieve.setOrganisation("apache"); + _retrieve.setModule("resolve-simple"); + _retrieve.setConf("default"); + _retrieve.setUseOrigin(false); + _retrieve.execute(); + + assertTrue(new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org1", "mod1.2", "2.0", + "mod1.2", "jar", "jar")).exists()); + } + + public void testFailureWithoutAPreviousResolve() throws Exception { + // we do a retrieve with the module information whereas no resolve has been previously done + try { + _retrieve.setOrganisation("apache"); + _retrieve.setModule("resolve-simple"); + _retrieve.setConf("default"); + _retrieve.execute(); + fail("retrieve without previous resolve should have thrown an exception"); + } catch (Exception ex) { + // OK + } + } + + public void testFailure() throws Exception { + try { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); + _retrieve.execute(); + fail("failure didn't raised an exception with default haltonfailure setting"); + } catch (BuildException ex) { + // ok => should raised an exception + } + } + + public void testHaltOnFailure() throws Exception { + try { + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-failure.xml"); + _retrieve.setHaltonfailure(false); + _retrieve.execute(); + + } catch (BuildException ex) { + fail("failure raised an exception with haltonfailure set to false"); + } + } + + public void testCustomIvyPattern() throws Exception { + // mod2.5 depends on virtual mod2.3 which depends on mod2.1 which depends on mod1.1 which + // depends on mod1.2 + _project.setProperty("ivy.dep.file", "test/repositories/1/org2/mod2.5/ivys/ivy-0.6.1.xml"); + + String ivyPattern = IVY_RETRIEVE_PATTERN; + + _retrieve.setIvypattern(ivyPattern); + _retrieve.execute(); + + assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org2", "mod2.3", "0.4.1", + "ivy", "ivy", "xml")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org2", "mod2.1", "0.3", "ivy", + "ivy", "xml")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.1", "1.0", "ivy", + "ivy", "xml")).exists()); + assertFalse(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.2", "2.0", + "ivy", "ivy", "xml")).exists()); + } + + public void testCustomIvyPatternWithConf() throws Exception { + _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); + + String ivyPattern = "build/test/lib/[conf]/[organisation]/[module]/ivy-[revision].xml"; + + _retrieve.setIvypattern(ivyPattern); + _retrieve.execute(); + + assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", + "ivy", "xml", "default")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", + "ivy", "xml", "extension")).exists()); + assertFalse(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.2", "2.1", + "ivy", "ivy", "xml", "extension")).exists()); + } + + public void testSyncWithIvyPattern() throws Exception { + _project.setProperty("ivy.dep.file", "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml"); + + String ivyPattern = "build/test/lib/[conf]/[organisation]/[module]/ivy-[revision].xml"; + + _retrieve.setIvypattern(ivyPattern); + + _retrieve.setSync(true); + + File[] old = new File[] { + new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "jar", "jar", "unknown")), // unknown configuration + new File(IvyPatternHelper.substitute(RETRIEVE_PATTERN, "org6", "mod6.1", "0.4", + "mod6.1", "unknown", "unknown", "default")), // unknown type + new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", + "ivy", "xml", "unk")), // unknown conf for ivy + new File(IvyPatternHelper.substitute(ivyPattern, "unknown", "mod6.1", "0.4", "ivy", + "ivy", "xml", "default")), // unknown organisation for ivy + }; + for (int i = 0; i < old.length; i++) { + touch(old[i]); + } + + _retrieve.execute(); + + assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", + "ivy", "xml", "default")).exists()); + assertTrue(new File(IvyPatternHelper.substitute(ivyPattern, "org6", "mod6.1", "0.4", "ivy", + "ivy", "xml", "extension")).exists()); + assertFalse(new File(IvyPatternHelper.substitute(ivyPattern, "org1", "mod1.2", "2.1", + "ivy", "ivy", "xml", "extension")).exists()); + for (int i = 0; i < old.length; i++) { + assertFalse(old[i] + " should have been deleted by sync", old[i].exists()); + } + assertFalse(new File("build/test/lib/unknown").exists()); + assertFalse(new File("build/test/lib/unk").exists()); + assertFalse(new File("build/test/lib/default/unknown").exists()); + } + + public void testDoubleRetrieveWithDifferentConfigurations() { + // IVY-315 + _project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-doubleretrieve.xml"); + + _retrieve.setConf("compile"); + _retrieve.execute(); + + _retrieve = new IvyRetrieve(); + _retrieve.setProject(_project); + _retrieve.setCache(_cache); + _retrieve.setPattern(RETRIEVE_PATTERN); + _retrieve.setConf("compile,unittest"); + _retrieve.execute(); + } + + // creates an empty file, creating parent directories if necessary + private void touch(File file) throws IOException { + if (file.getParentFile() != null) { + file.getParentFile().mkdirs(); + } + file.createNewFile(); + } + + private File getArchiveFileInCache(String organisation, String module, String revision, + String artifact, String type, String ext) { + return TestHelper.getArchiveFileInCache(_retrieve.getIvyInstance(), _cache, organisation, + module, revision, artifact, type, ext); + } + +} diff --git a/test/java/org/apache/ivy/ant/IvyVarTest.java b/test/java/org/apache/ivy/ant/IvyVarTest.java index 9de2a9a1..e365bdf0 100644 --- a/test/java/org/apache/ivy/ant/IvyVarTest.java +++ b/test/java/org/apache/ivy/ant/IvyVarTest.java @@ -1,71 +1,71 @@ -/* - * 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 junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.tools.ant.Project; - -public class IvyVarTest extends TestCase { - public void testSimple() { - IvyVar task = new IvyVar(); - task.setProject(new Project()); - task.setName("mytest"); - task.setValue("myvalue"); - task.execute(); - Ivy ivy = task.getIvyInstance(); - assertNotNull(ivy); - assertEquals("myvalue", ivy.getVariable("mytest")); - } - - public void testPrefix() { - IvyVar task = new IvyVar(); - task.setProject(new Project()); - task.setName("mytest"); - task.setValue("myvalue"); - task.setPrefix("myprefix"); - task.execute(); - Ivy ivy = task.getIvyInstance(); - assertNotNull(ivy); - assertEquals("myvalue", ivy.getVariable("myprefix.mytest")); - } - - public void testURL() { - IvyVar task = new IvyVar(); - task.setProject(new Project()); - task.setUrl(IvyVarTest.class.getResource("vartest.properties").toExternalForm()); - task.execute(); - Ivy ivy = task.getIvyInstance(); - assertNotNull(ivy); - assertEquals("myvalue1", ivy.getVariable("mytest1")); - assertEquals("myvalue2", ivy.getVariable("mytest2")); - } - - public void testURLPrefix() { - IvyVar task = new IvyVar(); - task.setProject(new Project()); - task.setUrl(IvyVarTest.class.getResource("vartest.properties").toExternalForm()); - task.setPrefix("myprefix."); - task.execute(); - Ivy ivy = task.getIvyInstance(); - assertNotNull(ivy); - assertEquals("myvalue1", ivy.getVariable("myprefix.mytest1")); - assertEquals("myvalue2", ivy.getVariable("myprefix.mytest2")); - } -} +/* + * 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 junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.tools.ant.Project; + +public class IvyVarTest extends TestCase { + public void testSimple() { + IvyVar task = new IvyVar(); + task.setProject(new Project()); + task.setName("mytest"); + task.setValue("myvalue"); + task.execute(); + Ivy ivy = task.getIvyInstance(); + assertNotNull(ivy); + assertEquals("myvalue", ivy.getVariable("mytest")); + } + + public void testPrefix() { + IvyVar task = new IvyVar(); + task.setProject(new Project()); + task.setName("mytest"); + task.setValue("myvalue"); + task.setPrefix("myprefix"); + task.execute(); + Ivy ivy = task.getIvyInstance(); + assertNotNull(ivy); + assertEquals("myvalue", ivy.getVariable("myprefix.mytest")); + } + + public void testURL() { + IvyVar task = new IvyVar(); + task.setProject(new Project()); + task.setUrl(IvyVarTest.class.getResource("vartest.properties").toExternalForm()); + task.execute(); + Ivy ivy = task.getIvyInstance(); + assertNotNull(ivy); + assertEquals("myvalue1", ivy.getVariable("mytest1")); + assertEquals("myvalue2", ivy.getVariable("mytest2")); + } + + public void testURLPrefix() { + IvyVar task = new IvyVar(); + task.setProject(new Project()); + task.setUrl(IvyVarTest.class.getResource("vartest.properties").toExternalForm()); + task.setPrefix("myprefix."); + task.execute(); + Ivy ivy = task.getIvyInstance(); + assertNotNull(ivy); + assertEquals("myvalue1", ivy.getVariable("myprefix.mytest1")); + assertEquals("myvalue2", ivy.getVariable("myprefix.mytest2")); + } +} diff --git a/test/java/org/apache/ivy/ant/imported-configurations.xml b/test/java/org/apache/ivy/ant/imported-configurations.xml index 4f7785c1..9ca58549 100644 --- a/test/java/org/apache/ivy/ant/imported-configurations.xml +++ b/test/java/org/apache/ivy/ant/imported-configurations.xml @@ -1,22 +1,22 @@ - - - - - + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-108.xml b/test/java/org/apache/ivy/ant/ivy-108.xml index 1debfe35..c48e1975 100644 --- a/test/java/org/apache/ivy/ant/ivy-108.xml +++ b/test/java/org/apache/ivy/ant/ivy-108.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-381.xml b/test/java/org/apache/ivy/ant/ivy-381.xml index af3b545a..65449e59 100644 --- a/test/java/org/apache/ivy/ant/ivy-381.xml +++ b/test/java/org/apache/ivy/ant/ivy-381.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-custom.xml b/test/java/org/apache/ivy/ant/ivy-custom.xml index 3545efd1..e441b027 100644 --- a/test/java/org/apache/ivy/ant/ivy-custom.xml +++ b/test/java/org/apache/ivy/ant/ivy-custom.xml @@ -1,34 +1,34 @@ - - - - - This is the description of this custom module - - - - - - - - + + + + + This is the description of this custom module + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-different-revisions.xml b/test/java/org/apache/ivy/ant/ivy-different-revisions.xml index ef36d905..c5b488b3 100644 --- a/test/java/org/apache/ivy/ant/ivy-different-revisions.xml +++ b/test/java/org/apache/ivy/ant/ivy-different-revisions.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-double.xml b/test/java/org/apache/ivy/ant/ivy-double.xml index 432e9818..657ebbca 100644 --- a/test/java/org/apache/ivy/ant/ivy-double.xml +++ b/test/java/org/apache/ivy/ant/ivy-double.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-doubleretrieve.xml b/test/java/org/apache/ivy/ant/ivy-doubleretrieve.xml index fada5b2f..924a36ac 100644 --- a/test/java/org/apache/ivy/ant/ivy-doubleretrieve.xml +++ b/test/java/org/apache/ivy/ant/ivy-doubleretrieve.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-failure.xml b/test/java/org/apache/ivy/ant/ivy-failure.xml index 40fdda7a..753cc81e 100644 --- a/test/java/org/apache/ivy/ant/ivy-failure.xml +++ b/test/java/org/apache/ivy/ant/ivy-failure.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-failure2.xml b/test/java/org/apache/ivy/ant/ivy-failure2.xml index e2a6b138..9f070249 100644 --- a/test/java/org/apache/ivy/ant/ivy-failure2.xml +++ b/test/java/org/apache/ivy/ant/ivy-failure2.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-failure3.xml b/test/java/org/apache/ivy/ant/ivy-failure3.xml index c0b95764..bcbbcc3e 100644 --- a/test/java/org/apache/ivy/ant/ivy-failure3.xml +++ b/test/java/org/apache/ivy/ant/ivy-failure3.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-import-confs.xml b/test/java/org/apache/ivy/ant/ivy-import-confs.xml index ca4913a8..0a529b87 100644 --- a/test/java/org/apache/ivy/ant/ivy-import-confs.xml +++ b/test/java/org/apache/ivy/ant/ivy-import-confs.xml @@ -1,31 +1,31 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-latest-branch.xml b/test/java/org/apache/ivy/ant/ivy-latest-branch.xml index 2f16912e..5849b521 100644 --- a/test/java/org/apache/ivy/ant/ivy-latest-branch.xml +++ b/test/java/org/apache/ivy/ant/ivy-latest-branch.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-latest-extra.xml b/test/java/org/apache/ivy/ant/ivy-latest-extra.xml index 74b872d5..29ee0883 100644 --- a/test/java/org/apache/ivy/ant/ivy-latest-extra.xml +++ b/test/java/org/apache/ivy/ant/ivy-latest-extra.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-latest.xml b/test/java/org/apache/ivy/ant/ivy-latest.xml index cb166ff1..d2e3a10f 100644 --- a/test/java/org/apache/ivy/ant/ivy-latest.xml +++ b/test/java/org/apache/ivy/ant/ivy-latest.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-multiconf.xml b/test/java/org/apache/ivy/ant/ivy-multiconf.xml index 74870b7d..13d70159 100644 --- a/test/java/org/apache/ivy/ant/ivy-multiconf.xml +++ b/test/java/org/apache/ivy/ant/ivy-multiconf.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-publish-multi.xml b/test/java/org/apache/ivy/ant/ivy-publish-multi.xml index 2fdfea4b..ec2879f9 100644 --- a/test/java/org/apache/ivy/ant/ivy-publish-multi.xml +++ b/test/java/org/apache/ivy/ant/ivy-publish-multi.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-publish.xml b/test/java/org/apache/ivy/ant/ivy-publish.xml index cf382a8a..127f2d0a 100644 --- a/test/java/org/apache/ivy/ant/ivy-publish.xml +++ b/test/java/org/apache/ivy/ant/ivy-publish.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-simple.xml b/test/java/org/apache/ivy/ant/ivy-simple.xml index c409d93c..895cfabe 100644 --- a/test/java/org/apache/ivy/ant/ivy-simple.xml +++ b/test/java/org/apache/ivy/ant/ivy-simple.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-simple2.xml b/test/java/org/apache/ivy/ant/ivy-simple2.xml index 101fca41..ce4c1b1c 100644 --- a/test/java/org/apache/ivy/ant/ivy-simple2.xml +++ b/test/java/org/apache/ivy/ant/ivy-simple2.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivy-with-variables.xml b/test/java/org/apache/ivy/ant/ivy-with-variables.xml index 8fd2215c..6005e579 100644 --- a/test/java/org/apache/ivy/ant/ivy-with-variables.xml +++ b/test/java/org/apache/ivy/ant/ivy-with-variables.xml @@ -1,31 +1,31 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/ivysettings-props.properties b/test/java/org/apache/ivy/ant/ivysettings-props.properties index a7d5e8fd..bbe356e1 100644 --- a/test/java/org/apache/ivy/ant/ivysettings-props.properties +++ b/test/java/org/apache/ivy/ant/ivysettings-props.properties @@ -1,19 +1,19 @@ -# *************************************************************** -# * 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.retrieve.pattern = lib/test/[artifact]-[revision].[ext] +# *************************************************************** +# * 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.retrieve.pattern = lib/test/[artifact]-[revision].[ext] diff --git a/test/java/org/apache/ivy/ant/ivysettings-props.xml b/test/java/org/apache/ivy/ant/ivysettings-props.xml index 0616c7a0..8b846ae3 100644 --- a/test/java/org/apache/ivy/ant/ivysettings-props.xml +++ b/test/java/org/apache/ivy/ant/ivysettings-props.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/java/org/apache/ivy/ant/ivysettings-test.xml b/test/java/org/apache/ivy/ant/ivysettings-test.xml index d4f2090b..a36bece7 100644 --- a/test/java/org/apache/ivy/ant/ivysettings-test.xml +++ b/test/java/org/apache/ivy/ant/ivysettings-test.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/published-ivy-custom.xml b/test/java/org/apache/ivy/ant/published-ivy-custom.xml index b320abbf..53ef9c05 100644 --- a/test/java/org/apache/ivy/ant/published-ivy-custom.xml +++ b/test/java/org/apache/ivy/ant/published-ivy-custom.xml @@ -1,30 +1,30 @@ - - - - - This is the description of this custom module - - - - - - - - + + + + + This is the description of this custom module + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/test-convertpom.xml b/test/java/org/apache/ivy/ant/test-convertpom.xml index ac0acd92..dd6021fd 100644 --- a/test/java/org/apache/ivy/ant/test-convertpom.xml +++ b/test/java/org/apache/ivy/ant/test-convertpom.xml @@ -1,46 +1,46 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/ant/test.pom b/test/java/org/apache/ivy/ant/test.pom index ad154f06..44a98893 100644 --- a/test/java/org/apache/ivy/ant/test.pom +++ b/test/java/org/apache/ivy/ant/test.pom @@ -1,58 +1,58 @@ - - - - 4.0.0 - fr.jayasoft - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - commons-logging - commons-logging - 1.0.4 - - - dom4j - dom4j - 1.6 - - - jaxme - jaxme-api - - - jaxen - jaxen - - - - - cglib - cglib - 2.0.2 - - - + + + + 4.0.0 + fr.jayasoft + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + commons-logging + commons-logging + 1.0.4 + + + dom4j + dom4j + 1.6 + + + jaxme + jaxme-api + + + jaxen + jaxen + + + + + cglib + cglib + 2.0.2 + + + diff --git a/test/java/org/apache/ivy/ant/vartest.properties b/test/java/org/apache/ivy/ant/vartest.properties index 3e6b3ae0..4699513d 100644 --- a/test/java/org/apache/ivy/ant/vartest.properties +++ b/test/java/org/apache/ivy/ant/vartest.properties @@ -1,20 +1,20 @@ -# *************************************************************** -# * 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. -# *************************************************************** -mytest1=myvalue1 -mytest2=myvalue2 \ No newline at end of file +# *************************************************************** +# * 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. +# *************************************************************** +mytest1=myvalue1 +mytest2=myvalue2 diff --git a/test/java/org/apache/ivy/core/TestPerformance.java b/test/java/org/apache/ivy/core/TestPerformance.java index df1bf3b9..fcf3e5e7 100644 --- a/test/java/org/apache/ivy/core/TestPerformance.java +++ b/test/java/org/apache/ivy/core/TestPerformance.java @@ -1,160 +1,160 @@ -/* - * 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.core; - -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.Random; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; -import org.apache.ivy.plugins.resolver.FileSystemResolver; -import org.apache.ivy.util.FileUtil; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -/** - * Not a Junit test, performance depends on the machine on which the test is run... - */ -public class TestPerformance { - private final static String PATTERN = "build/test/perf/[module]/[artifact]-[revision].[ext]"; - - private final Ivy _ivy; - - private File _cache; - - public TestPerformance() throws Exception { - _ivy = new Ivy(); - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("def"); - resolver.setSettings(_ivy.getSettings()); - - resolver.addIvyPattern(PATTERN); - resolver.addArtifactPattern(PATTERN); - - _ivy.getSettings().addResolver(resolver); - _ivy.getSettings().setDefaultResolver("def"); - } - - protected void setUp() throws Exception { - createCache(); - } - - 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 void cleanRepo() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/perf")); - del.execute(); - } - - private void generateModules(int nbModules, int minDependencies, int maxDependencies, - int minVersions, int maxVersions) throws IOException { - int nb = 0; - int curDep = 1; - int varDeps = maxDependencies - minDependencies; - int varVersions = maxVersions - minVersions; - Random r = new Random(System.currentTimeMillis()); - - while (nb < nbModules) { - int deps = minDependencies + r.nextInt(varDeps + 1); - int versions = minVersions + r.nextInt(varVersions + 1); - - int prevCurDep = curDep; - for (int ver = 0; ver < versions; ver++) { - DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId - .newInstance("apache", "mod" + nb, "1." + ver), "integration", new Date()); - - curDep = prevCurDep; - for (int i = 0; i < deps && curDep < nbModules; i++) { - int d; - if (i % 2 == 1) { - d = nb + i; - if (d >= prevCurDep) { - d = curDep; - curDep++; - } - } else { - d = curDep; - curDep++; - } - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor( - md, - ModuleRevisionId.newInstance("apache", "mod" + d, "latest.integration"), - false, false, true); - dd.addDependencyConfiguration("default", "default"); - md.addDependency(dd); - } - XmlModuleDescriptorWriter.write(md, new File("build/test/perf/mod" + nb + "/ivy-1." - + ver + ".xml")); - FileUtil - .copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), - new File("build/test/perf/mod" + nb + "/mod" + nb + "-1." + ver - + ".jar"), null); - } - nb++; - } - } - - public void testPerfs() throws Exception { - generateModules(70, 2, 5, 2, 15); - - long start = System.currentTimeMillis(); - ResolveReport report = _ivy.resolve(new File("build/test/perf/mod0/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"}).setRevision("1.0")); - long end = System.currentTimeMillis(); - System.out.println("resolve " + report.getConfigurationReport("default").getNodesNumber() - + " modules took " + (end - start) + " ms"); - - cleanRepo(); - } - - private ResolveOptions getResolveOptions(String[] confs) { - return new ResolveOptions().setConfs(confs).setCache( - CacheManager.getInstance(_ivy.getSettings(), _cache)); - } - - public static void main(String[] args) throws Exception { - TestPerformance t = new TestPerformance(); - t.setUp(); - t.testPerfs(); - t.tearDown(); - } -} +/* + * 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.core; + +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.Random; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter; +import org.apache.ivy.plugins.resolver.FileSystemResolver; +import org.apache.ivy.util.FileUtil; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +/** + * Not a Junit test, performance depends on the machine on which the test is run... + */ +public class TestPerformance { + private final static String PATTERN = "build/test/perf/[module]/[artifact]-[revision].[ext]"; + + private final Ivy _ivy; + + private File _cache; + + public TestPerformance() throws Exception { + _ivy = new Ivy(); + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("def"); + resolver.setSettings(_ivy.getSettings()); + + resolver.addIvyPattern(PATTERN); + resolver.addArtifactPattern(PATTERN); + + _ivy.getSettings().addResolver(resolver); + _ivy.getSettings().setDefaultResolver("def"); + } + + protected void setUp() throws Exception { + createCache(); + } + + 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 void cleanRepo() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/perf")); + del.execute(); + } + + private void generateModules(int nbModules, int minDependencies, int maxDependencies, + int minVersions, int maxVersions) throws IOException { + int nb = 0; + int curDep = 1; + int varDeps = maxDependencies - minDependencies; + int varVersions = maxVersions - minVersions; + Random r = new Random(System.currentTimeMillis()); + + while (nb < nbModules) { + int deps = minDependencies + r.nextInt(varDeps + 1); + int versions = minVersions + r.nextInt(varVersions + 1); + + int prevCurDep = curDep; + for (int ver = 0; ver < versions; ver++) { + DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId + .newInstance("apache", "mod" + nb, "1." + ver), "integration", new Date()); + + curDep = prevCurDep; + for (int i = 0; i < deps && curDep < nbModules; i++) { + int d; + if (i % 2 == 1) { + d = nb + i; + if (d >= prevCurDep) { + d = curDep; + curDep++; + } + } else { + d = curDep; + curDep++; + } + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor( + md, + ModuleRevisionId.newInstance("apache", "mod" + d, "latest.integration"), + false, false, true); + dd.addDependencyConfiguration("default", "default"); + md.addDependency(dd); + } + XmlModuleDescriptorWriter.write(md, new File("build/test/perf/mod" + nb + "/ivy-1." + + ver + ".xml")); + FileUtil + .copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), + new File("build/test/perf/mod" + nb + "/mod" + nb + "-1." + ver + + ".jar"), null); + } + nb++; + } + } + + public void testPerfs() throws Exception { + generateModules(70, 2, 5, 2, 15); + + long start = System.currentTimeMillis(); + ResolveReport report = _ivy.resolve(new File("build/test/perf/mod0/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"}).setRevision("1.0")); + long end = System.currentTimeMillis(); + System.out.println("resolve " + report.getConfigurationReport("default").getNodesNumber() + + " modules took " + (end - start) + " ms"); + + cleanRepo(); + } + + private ResolveOptions getResolveOptions(String[] confs) { + return new ResolveOptions().setConfs(confs).setCache( + CacheManager.getInstance(_ivy.getSettings(), _cache)); + } + + public static void main(String[] args) throws Exception { + TestPerformance t = new TestPerformance(); + t.setUp(); + t.testPerfs(); + t.tearDown(); + } +} diff --git a/test/java/org/apache/ivy/core/cache/CacheManagerTest.java b/test/java/org/apache/ivy/core/cache/CacheManagerTest.java index cbca7694..470b00a6 100644 --- a/test/java/org/apache/ivy/core/cache/CacheManagerTest.java +++ b/test/java/org/apache/ivy/core/cache/CacheManagerTest.java @@ -1,104 +1,104 @@ -/* - * 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.core.cache; - -import java.io.File; -import java.util.Date; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.tools.ant.util.FileUtils; - -/** - * @see CacheManager - */ -public class CacheManagerTest extends TestCase { - private CacheManager cacheManager; - - private Artifact artifact; - - private ArtifactOrigin origin; - - protected void setUp() throws Exception { - File f = File.createTempFile("ivycache", ".dir"); - Ivy ivy = new Ivy(); - ivy.configureDefault(); - IvySettings settings = ivy.getSettings(); - f.delete(); // we want to use the file as a directory, so we delete the file itself - cacheManager = new CacheManager(settings, f); - - artifact = createArtifact("org", "module", "rev", "name", "type", "ext"); - origin = new ArtifactOrigin(true, "/some/where"); - cacheManager.saveArtifactOrigin(artifact, origin); - } - - protected void tearDown() throws Exception { - FileUtils.delete(cacheManager.getCache()); - } - - public void testArtifactOrigin() { - ArtifactOrigin found = cacheManager.getSavedArtifactOrigin(artifact); - assertEquals(origin, found); - - artifact = createArtifact("org", "module", "rev", "name", "type2", "ext"); - found = cacheManager.getSavedArtifactOrigin(artifact); - assertNull(found); - } - - public void testUniqueness() { - cacheManager.saveArtifactOrigin(artifact, origin); - - artifact = createArtifact("org1", "module", "rev", "name", "type", "ext"); - ArtifactOrigin found = cacheManager.getSavedArtifactOrigin(artifact); - assertNull(found); - - artifact = createArtifact("org", "module1", "rev", "name", "type", "ext"); - found = cacheManager.getSavedArtifactOrigin(artifact); - assertNull(found); - - artifact = createArtifact("org", "module", "rev1", "name", "type", "ext"); - found = cacheManager.getSavedArtifactOrigin(artifact); - assertNull(found); - - artifact = createArtifact("org", "module", "rev", "name1", "type", "ext"); - found = cacheManager.getSavedArtifactOrigin(artifact); - assertNull(found); - - artifact = createArtifact("org", "module", "rev", "name", "type1", "ext"); - found = cacheManager.getSavedArtifactOrigin(artifact); - assertNull(found); - - artifact = createArtifact("org", "module", "rev", "name", "type", "ext1"); - found = cacheManager.getSavedArtifactOrigin(artifact); - assertNull(found); - } - - protected Artifact createArtifact(String org, String module, String rev, String name, - String type, String ext) { - ModuleId mid = new ModuleId(org, module); - ModuleRevisionId mrid = new ModuleRevisionId(mid, rev); - return new DefaultArtifact(mrid, new Date(), name, type, ext); - } - -} +/* + * 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.core.cache; + +import java.io.File; +import java.util.Date; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.tools.ant.util.FileUtils; + +/** + * @see CacheManager + */ +public class CacheManagerTest extends TestCase { + private CacheManager cacheManager; + + private Artifact artifact; + + private ArtifactOrigin origin; + + protected void setUp() throws Exception { + File f = File.createTempFile("ivycache", ".dir"); + Ivy ivy = new Ivy(); + ivy.configureDefault(); + IvySettings settings = ivy.getSettings(); + f.delete(); // we want to use the file as a directory, so we delete the file itself + cacheManager = new CacheManager(settings, f); + + artifact = createArtifact("org", "module", "rev", "name", "type", "ext"); + origin = new ArtifactOrigin(true, "/some/where"); + cacheManager.saveArtifactOrigin(artifact, origin); + } + + protected void tearDown() throws Exception { + FileUtils.delete(cacheManager.getCache()); + } + + public void testArtifactOrigin() { + ArtifactOrigin found = cacheManager.getSavedArtifactOrigin(artifact); + assertEquals(origin, found); + + artifact = createArtifact("org", "module", "rev", "name", "type2", "ext"); + found = cacheManager.getSavedArtifactOrigin(artifact); + assertNull(found); + } + + public void testUniqueness() { + cacheManager.saveArtifactOrigin(artifact, origin); + + artifact = createArtifact("org1", "module", "rev", "name", "type", "ext"); + ArtifactOrigin found = cacheManager.getSavedArtifactOrigin(artifact); + assertNull(found); + + artifact = createArtifact("org", "module1", "rev", "name", "type", "ext"); + found = cacheManager.getSavedArtifactOrigin(artifact); + assertNull(found); + + artifact = createArtifact("org", "module", "rev1", "name", "type", "ext"); + found = cacheManager.getSavedArtifactOrigin(artifact); + assertNull(found); + + artifact = createArtifact("org", "module", "rev", "name1", "type", "ext"); + found = cacheManager.getSavedArtifactOrigin(artifact); + assertNull(found); + + artifact = createArtifact("org", "module", "rev", "name", "type1", "ext"); + found = cacheManager.getSavedArtifactOrigin(artifact); + assertNull(found); + + artifact = createArtifact("org", "module", "rev", "name", "type", "ext1"); + found = cacheManager.getSavedArtifactOrigin(artifact); + assertNull(found); + } + + protected Artifact createArtifact(String org, String module, String rev, String name, + String type, String ext) { + ModuleId mid = new ModuleId(org, module); + ModuleRevisionId mrid = new ModuleRevisionId(mid, rev); + return new DefaultArtifact(mrid, new Date(), name, type, ext); + } + +} diff --git a/test/java/org/apache/ivy/core/event/IvyEventFilterTest.java b/test/java/org/apache/ivy/core/event/IvyEventFilterTest.java index d064afcc..f63725b6 100644 --- a/test/java/org/apache/ivy/core/event/IvyEventFilterTest.java +++ b/test/java/org/apache/ivy/core/event/IvyEventFilterTest.java @@ -1,111 +1,111 @@ -/* - * 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.core.event; - -import java.util.Date; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.event.resolve.EndResolveEvent; -import org.apache.ivy.core.event.resolve.StartResolveEvent; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ResolveReport; - -public class IvyEventFilterTest extends TestCase { - Ivy ivy = new Ivy(); - - ModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo", "bar", - "1.0"), "integration", new Date()); - - ModuleDescriptor md2 = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo2", "bar", - "1.0"), "integration", new Date()); - - ModuleDescriptor md3 = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo3", "baz", - "1.0"), "integration", new Date()); - - ModuleDescriptor md4 = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo", "baz", - "1.0"), "integration", new Date()); - - public void testSimple() { - IvyEventFilter f = new IvyEventFilter("pre-resolve", null, null); - - assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertFalse(f.accept(new EndResolveEvent(md, new String[] {"default"}, - new ResolveReport(md)))); - } - - public void testSimpleExpression() { - IvyEventFilter f = new IvyEventFilter("pre-resolve", "organisation = foo", null); - - assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); - - f = new IvyEventFilter("pre-resolve", "module = bar", null); - - assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); - - f = new IvyEventFilter("pre-resolve", "organisation = foo, foo2", null); - - assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); - } - - public void testAndExpression() { - IvyEventFilter f = new IvyEventFilter("pre-resolve", "organisation = foo AND module = bar", - null); - - assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); - - f = new IvyEventFilter("pre-resolve", "organisation = foo,foo2 AND module = bar", null); - - assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); - } - - public void testOrExpression() { - IvyEventFilter f = new IvyEventFilter("pre-resolve", "organisation = foo3 OR module = bar", - null); - - assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); - } - - public void testNotExpression() { - IvyEventFilter f = new IvyEventFilter("pre-resolve", "NOT organisation = foo", null); - - assertFalse(f.accept(new StartResolveEvent(md, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); - assertTrue(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); - assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); - } -} +/* + * 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.core.event; + +import java.util.Date; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.event.resolve.EndResolveEvent; +import org.apache.ivy.core.event.resolve.StartResolveEvent; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ResolveReport; + +public class IvyEventFilterTest extends TestCase { + Ivy ivy = new Ivy(); + + ModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo", "bar", + "1.0"), "integration", new Date()); + + ModuleDescriptor md2 = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo2", "bar", + "1.0"), "integration", new Date()); + + ModuleDescriptor md3 = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo3", "baz", + "1.0"), "integration", new Date()); + + ModuleDescriptor md4 = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("foo", "baz", + "1.0"), "integration", new Date()); + + public void testSimple() { + IvyEventFilter f = new IvyEventFilter("pre-resolve", null, null); + + assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertFalse(f.accept(new EndResolveEvent(md, new String[] {"default"}, + new ResolveReport(md)))); + } + + public void testSimpleExpression() { + IvyEventFilter f = new IvyEventFilter("pre-resolve", "organisation = foo", null); + + assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); + + f = new IvyEventFilter("pre-resolve", "module = bar", null); + + assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); + + f = new IvyEventFilter("pre-resolve", "organisation = foo, foo2", null); + + assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); + } + + public void testAndExpression() { + IvyEventFilter f = new IvyEventFilter("pre-resolve", "organisation = foo AND module = bar", + null); + + assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); + + f = new IvyEventFilter("pre-resolve", "organisation = foo,foo2 AND module = bar", null); + + assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); + } + + public void testOrExpression() { + IvyEventFilter f = new IvyEventFilter("pre-resolve", "organisation = foo3 OR module = bar", + null); + + assertTrue(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); + } + + public void testNotExpression() { + IvyEventFilter f = new IvyEventFilter("pre-resolve", "NOT organisation = foo", null); + + assertFalse(f.accept(new StartResolveEvent(md, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md2, new String[] {"default"}))); + assertTrue(f.accept(new StartResolveEvent(md3, new String[] {"default"}))); + assertFalse(f.accept(new StartResolveEvent(md4, new String[] {"default"}))); + } +} diff --git a/test/java/org/apache/ivy/core/install/InstallTest.java b/test/java/org/apache/ivy/core/install/InstallTest.java index 1d27340f..a78f04df 100644 --- a/test/java/org/apache/ivy/core/install/InstallTest.java +++ b/test/java/org/apache/ivy/core/install/InstallTest.java @@ -1,140 +1,140 @@ -/* - * 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.core.install; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class InstallTest extends TestCase { - - public void testSimple() throws Exception { - Ivy ivy = Ivy.newInstance(); - ivy.configure(new File("test/repositories/ivysettings.xml")); - - ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), ivy.getSettings() - .getDefaultResolver().getName(), "install", true, true, true, null, _cache, - PatternMatcher.EXACT); - - assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); - } - - public void testSimpleWithoutDefaultResolver() throws Exception { - Ivy ivy = Ivy.newInstance(); - ivy.configure(new File("test/repositories/ivysettings-nodefaultresolver.xml")); - - ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), "test", "install", true, - true, true, null, _cache, PatternMatcher.EXACT); - - assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); - } - - public void testDependencies() throws Exception { - Ivy ivy = Ivy.newInstance(); - ivy.configure(new File("test/repositories/ivysettings.xml")); - - ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), ivy.getSettings() - .getDefaultResolver().getName(), "install", true, true, true, null, _cache, - PatternMatcher.EXACT); - - assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists()); - - assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); - } - - public void testNotTransitive() throws Exception { - Ivy ivy = Ivy.newInstance(); - ivy.configure(new File("test/repositories/ivysettings.xml")); - - ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), ivy.getSettings() - .getDefaultResolver().getName(), "install", false, true, true, null, _cache, - PatternMatcher.EXACT); - - assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists()); - - assertFalse(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); - assertFalse(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); - } - - public void testRegexpMatcher() throws Exception { - Ivy ivy = Ivy.newInstance(); - ivy.configure(new File("test/repositories/ivysettings.xml")); - - ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"), "1", "install", false, true, - true, null, _cache, PatternMatcher.REGEXP); - - assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists()); - - assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.1.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.1.jar").exists()); - - assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); - - // mod1.3 is split because Ivy thinks there are two versions of the module: - // this is the normal behaviour in this case - assertTrue(new File("build/test/install/org1/mod1.3/ivy-B-3.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.3/ivy-A-3.0.xml").exists()); - assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-A-3.0.jar").exists()); - assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-B-3.0.jar").exists()); - - assertTrue(new File("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists()); - } - - private File _cache; - - protected void setUp() throws Exception { - createCache(); - } - - private void createCache() { - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - cleanCache(); - cleanInstall(); - } - - private void cleanCache() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - private void cleanInstall() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/install")); - del.execute(); - } -} +/* + * 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.core.install; + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class InstallTest extends TestCase { + + public void testSimple() throws Exception { + Ivy ivy = Ivy.newInstance(); + ivy.configure(new File("test/repositories/ivysettings.xml")); + + ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), ivy.getSettings() + .getDefaultResolver().getName(), "install", true, true, true, null, _cache, + PatternMatcher.EXACT); + + assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); + } + + public void testSimpleWithoutDefaultResolver() throws Exception { + Ivy ivy = Ivy.newInstance(); + ivy.configure(new File("test/repositories/ivysettings-nodefaultresolver.xml")); + + ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), "test", "install", true, + true, true, null, _cache, PatternMatcher.EXACT); + + assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); + } + + public void testDependencies() throws Exception { + Ivy ivy = Ivy.newInstance(); + ivy.configure(new File("test/repositories/ivysettings.xml")); + + ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), ivy.getSettings() + .getDefaultResolver().getName(), "install", true, true, true, null, _cache, + PatternMatcher.EXACT); + + assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists()); + + assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); + } + + public void testNotTransitive() throws Exception { + Ivy ivy = Ivy.newInstance(); + ivy.configure(new File("test/repositories/ivysettings.xml")); + + ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), ivy.getSettings() + .getDefaultResolver().getName(), "install", false, true, true, null, _cache, + PatternMatcher.EXACT); + + assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists()); + + assertFalse(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); + assertFalse(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); + } + + public void testRegexpMatcher() throws Exception { + Ivy ivy = Ivy.newInstance(); + ivy.configure(new File("test/repositories/ivysettings.xml")); + + ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"), "1", "install", false, true, + true, null, _cache, PatternMatcher.REGEXP); + + assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists()); + + assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.1.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.1.jar").exists()); + + assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists()); + + // mod1.3 is split because Ivy thinks there are two versions of the module: + // this is the normal behaviour in this case + assertTrue(new File("build/test/install/org1/mod1.3/ivy-B-3.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.3/ivy-A-3.0.xml").exists()); + assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-A-3.0.jar").exists()); + assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-B-3.0.jar").exists()); + + assertTrue(new File("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists()); + } + + private File _cache; + + protected void setUp() throws Exception { + createCache(); + } + + private void createCache() { + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + cleanInstall(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + private void cleanInstall() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/install")); + del.execute(); + } +} diff --git a/test/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptorTest.java b/test/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptorTest.java index f3b3b611..1f76c97e 100644 --- a/test/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptorTest.java +++ b/test/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptorTest.java @@ -1,63 +1,63 @@ -/* - * 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.core.module.descriptor; - -import junit.framework.TestCase; - -public class DefaultDependencyDescriptorTest extends TestCase { - - public static void main(String[] args) { - junit.textui.TestRunner.run(DefaultDependencyDescriptorTest.class); - } - - /* - * Test method for - * 'org.apache.ivy.DefaultDependencyDescriptor.replaceSelfFallbackPattern(String, String)' - */ - public void testReplaceSelfFallbackPattern() { - String replacedConf = DefaultDependencyDescriptor.replaceSelfFallbackPattern("@(default)", - "compile"); - assertEquals("compile(default)", replacedConf); - - replacedConf = DefaultDependencyDescriptor.replaceSelfFallbackPattern("default", "compile"); - assertNull(replacedConf); - - replacedConf = DefaultDependencyDescriptor.replaceSelfFallbackPattern("@", "runtime"); - assertEquals("runtime", "runtime"); - - } - - /* - * Test method for - * 'org.apache.ivy.DefaultDependencyDescriptor.replaceThisFallbackPattern(String, String)' - */ - public void testReplaceThisFallbackPattern() { - String replacedConf = DefaultDependencyDescriptor.replaceThisFallbackPattern("#(default)", - "compile"); - assertEquals("compile(default)", replacedConf); - - replacedConf = DefaultDependencyDescriptor.replaceThisFallbackPattern("default", "compile"); - assertNull(replacedConf); - - replacedConf = DefaultDependencyDescriptor.replaceThisFallbackPattern("#", "runtime"); - assertEquals("runtime", "runtime"); - - } - -} +/* + * 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.core.module.descriptor; + +import junit.framework.TestCase; + +public class DefaultDependencyDescriptorTest extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(DefaultDependencyDescriptorTest.class); + } + + /* + * Test method for + * 'org.apache.ivy.DefaultDependencyDescriptor.replaceSelfFallbackPattern(String, String)' + */ + public void testReplaceSelfFallbackPattern() { + String replacedConf = DefaultDependencyDescriptor.replaceSelfFallbackPattern("@(default)", + "compile"); + assertEquals("compile(default)", replacedConf); + + replacedConf = DefaultDependencyDescriptor.replaceSelfFallbackPattern("default", "compile"); + assertNull(replacedConf); + + replacedConf = DefaultDependencyDescriptor.replaceSelfFallbackPattern("@", "runtime"); + assertEquals("runtime", "runtime"); + + } + + /* + * Test method for + * 'org.apache.ivy.DefaultDependencyDescriptor.replaceThisFallbackPattern(String, String)' + */ + public void testReplaceThisFallbackPattern() { + String replacedConf = DefaultDependencyDescriptor.replaceThisFallbackPattern("#(default)", + "compile"); + assertEquals("compile(default)", replacedConf); + + replacedConf = DefaultDependencyDescriptor.replaceThisFallbackPattern("default", "compile"); + assertNull(replacedConf); + + replacedConf = DefaultDependencyDescriptor.replaceThisFallbackPattern("#", "runtime"); + assertEquals("runtime", "runtime"); + + } + +} diff --git a/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java b/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java index 29299529..59db84de 100644 --- a/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java +++ b/test/java/org/apache/ivy/core/module/id/ModuleRevisionIdTest.java @@ -1,49 +1,49 @@ -/* - * 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.core.module.id; - -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -public class ModuleRevisionIdTest extends TestCase { - - public void testEncodeDecodeToString() { - testEncodeDecodeToString(ModuleRevisionId.newInstance("org", "name", "revision")); - testEncodeDecodeToString(ModuleRevisionId.newInstance("org", "name", "")); - testEncodeDecodeToString(ModuleRevisionId.newInstance("org.apache", "name-post", "1.0")); - testEncodeDecodeToString(ModuleRevisionId.newInstance("org/apache", "pre/name", - "1.0-dev8/2")); - Map extraAttributes = new HashMap(); - extraAttributes.put("extra", "extravalue"); - extraAttributes.put("att/name", "att/value"); - extraAttributes.put("att.name", "att.value"); - extraAttributes.put("att module2-1.0 - // -> module3-2.0 - // module2 - // -> module3-1.0 - // settings use 'all' as default conflict manager, and latest-revision for modules from - // myorg - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-448/ivysettings.xml").toURL()); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-448/ivy.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - // rev 1.0 should have been evicted by latest-revision conflict manager - assertTrue(getArchiveFileInCache("myorg", "module3", "2.0", "module3", "jar", "jar") - .exists()); - assertFalse(getArchiveFileInCache("myorg", "module3", "1.0", "module3", "jar", "jar") - .exists()); - } - - public void testResolveRequiresIvyFile() throws Exception { - // mod1.1 depends on mod1.2, mod1.2 has no ivy file - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/ivysettings.xml")); - ((FileSystemResolver) ivy.getSettings().getResolver("1")).setAllownomd(false); - ResolveReport report = ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - assertTrue(report.hasError()); - } - - public void testResolveOtherConfiguration() throws Exception { - ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-other.xml"), - getResolveOptions(new String[] {"test"})); - - assertNotNull(report); - assertFalse(report.hasError()); - - assertEquals("Number of artifacts not correct", 1, report.getConfigurationReport("test") - .getArtifactsNumber()); - } - - public void testResolveWithSlashes() throws Exception { - // test case for IVY-198 - // module depends on mod1.2 - ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-198.xml"), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg/mydep", "system/module", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("yourorg/yourdep", "yoursys/yourmod", "1.0")).exists()); - assertTrue(getArchiveFileInCache("yourorg/yourdep", "yoursys/yourmod", "1.0", "yourmod", - "jar", "jar").exists()); - } - - public void testFromCache() throws Exception { - // mod1.1 depends on mod1.2 - - // we first do a simple resolve so that module is in cache - _ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - // we now use a badly configured ivy, so that it can't find module in repository - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/bugIVY-56/ivysettings.xml")); - - ResolveReport report = ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy - .getSettings(), new String[] {"*"})); - assertFalse(report.hasError()); - - ModuleDescriptor md = report.getModuleDescriptor(); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testFromCache2() throws Exception { - // mod1.1 depends on mod1.2 - - // configuration - Ivy ivy = Ivy.newInstance(); - DualResolver resolver = new DualResolver(); - resolver.setName("dual"); - FileSystemResolver r = new FileSystemResolver(); - r.setName("1"); - r.addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]"); - resolver.add(r); - r = new FileSystemResolver(); - r.setName("2"); - r.addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]"); - resolver.add(r); - ivy.getSettings().addResolver(resolver); - ivy.getSettings().setDefaultResolver("dual"); - - // set up repository - File art = new File("build/testCache2/mod1.2-2.0.jar"); - FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), art, null); - - // we first do a simple resolve so that module is in cache - ResolveReport report = ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - // now we clean the repository to simulate repo not available (network pb for instance) - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/testCache2")); - del.execute(); - - // now do a new resolve: it should use cached data - report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - ModuleDescriptor md = report.getModuleDescriptor(); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testFromCacheOnly() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/bugIVY-56/ivysettings.xml")); - - // ResolveReport report = ivy.resolve(new - // File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - // getResolveOptions(new String[] {"*"})); - // // should have an error, the conf is bad and the dependency should not be found - // assertTrue(report.hasError()); - - // put necessary stuff in cache, and it should now be ok - File ivyfile = ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); - File art = TestHelper.getArchiveFileInCache(ivy, _cache, "org1", "mod1.2", "2.0", "mod1.2", - "jar", "jar"); - FileUtil.copy(ResolveTest.class.getResource("ivy-mod1.2.xml"), ivyfile, null); - FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), art, null); - - ResolveReport report = ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy - .getSettings(), new String[] {"*"})); - assertFalse(report.hasError()); - } - - public void testChangeCacheLayout() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/ivysettings.xml")); - ivy.getSettings().setCacheIvyPattern("[module]/ivy.xml"); - ivy.getSettings().setCacheArtifactPattern("[artifact].[ext]"); - - // mod1.1 depends on mod1.2 - ResolveReport report = ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy - .getSettings(), new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(new File(_cache, "mod1.2/ivy.xml").exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org1", "mod1.2", "2.0", "mod1.2", - "jar", "jar").exists()); - assertTrue(new File(_cache, "mod1.2.jar").exists()); - } - - public void testResolveExtends() throws Exception { - // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(), - getResolveOptions(new String[] {"extension"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies from default - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveExtended() throws Exception { - // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies from default - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveExtendedAndExtends() throws Exception { - // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(), - getResolveOptions(new String[] {"default", "extension"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(1, crr.getArtifactsNumber()); - crr = report.getConfigurationReport("extension"); - assertNotNull(crr); - assertEquals(1, crr.getArtifactsNumber()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveMultipleExtends() throws Exception { - // mod6.2 has two confs default and extension - // mod6.2 depends on mod6.1 in conf (default->extension) - // conf extension extends default - // mod6.1 has two confs default and extension - // mod6.1 depends on mod1.2 2.0 in conf (default->default) - // conf extension extends default - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml").toURL(), - getResolveOptions(new String[] {"default", "extension"})); - assertNotNull(report); - assertFalse(report.hasError()); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(2, crr.getArtifactsNumber()); - crr = report.getConfigurationReport("extension"); - assertNotNull(crr); - assertEquals(2, crr.getArtifactsNumber()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org6", "mod6.1", "0.4")).exists()); - assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.4", "mod6.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveMultipleExtendsAndConfs() throws Exception { - // Test case for IVY-240 - // - // mod6.3 1.1 has four confs libraries, run (extends libraries), compile (extends run) and - // test (extends libraries) - // mod6.3 depends on mod6.2 2.0 in conf (run->default) - // mod6.3 depends on mod6.1 2.+ in conf (test->default) - // mod6.2 2.0 depends on mod6.1 2.0 in conf (default->standalone) - // mod6.1 2.0 has two confs default and standalone - // mod6.1 2.0 depends on mod1.2 2.2 in conf (default->default) - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.1.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - assertFalse(report.hasError()); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ConfigurationResolveReport crr = report.getConfigurationReport("libraries"); - assertEquals(0, crr.getArtifactsNumber()); - - crr = report.getConfigurationReport("run"); - assertEquals(2, crr.getArtifactsNumber()); - assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2", "jar", "jar", crr); - assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr); - - crr = report.getConfigurationReport("compile"); - assertEquals(2, crr.getArtifactsNumber()); - assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2", "jar", "jar", crr); - assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr); - - crr = report.getConfigurationReport("test"); - assertEquals(2, crr.getArtifactsNumber()); - assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr); - assertContainsArtifact("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar", crr); - } - - public void testResolveMultipleConfsWithLatest() throws Exception { - // Test case for IVY-188 - // - // mod6.2 has two confs compile and run - // depends on mod6.1 in conf (compile->default) - // depends on mod1.2 latest (which is 2.2) in conf (run->default) - // mod6.1 - // depends on mod1.2 2.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml").toURL(), - getResolveOptions(new String[] {"compile", "run"})); - assertNotNull(report); - assertFalse(report.hasError()); - - ConfigurationResolveReport crr = report.getConfigurationReport("compile"); - assertNotNull(crr); - assertEquals(2, crr.getArtifactsNumber()); - crr = report.getConfigurationReport("run"); - assertNotNull(crr); - assertEquals(1, crr.getArtifactsNumber()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveMultipleConfsWithConflicts() throws Exception { - // Test case for IVY-173 - // - // mod6.2 has two confs compile and run - // depends on mod1.2 2.1 in conf (compile->default) - // depends on mod1.1 1.0 in conf (*->default) - // depends on mod6.1 in conf (*->default) - // mod6.1 - // depends on mod1.2 2.1 - // mod1.1 - // depends on mod1.2 2.0 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml").toURL(), - getResolveOptions(new String[] {"compile", "run"})); - assertNotNull(report); - assertFalse(report.hasError()); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.5"); - assertEquals(mrid, md.getModuleRevisionId()); - ConfigurationResolveReport crr = report.getConfigurationReport("compile"); - assertNotNull(crr); - assertEquals(3, crr.getArtifactsNumber()); - crr = report.getConfigurationReport("run"); - assertNotNull(crr); - assertEquals(3, crr.getArtifactsNumber()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org6", "mod6.1", "0.5")).exists()); - assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.5", "mod6.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveMultipleExtends2() throws Exception { - // same as before, except that mod6.2 depends on mod1.2 2.1 extension->default - // so mod1.2 2.0 should be evicted in conf extension - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml").toURL(), - getResolveOptions(new String[] {"default", "extension"})); - assertNotNull(report); - assertFalse(report.hasError()); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.4"); - assertEquals(mrid, md.getModuleRevisionId()); - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(2, crr.getArtifactsNumber()); - IvyNode node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); - assertNotNull(node); - assertFalse(node.isEvicted("default")); - crr = report.getConfigurationReport("extension"); - assertNotNull(crr); - assertEquals(2, crr.getArtifactsNumber()); - node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); - assertNotNull(node); - assertTrue(node.isEvicted("extension")); - node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")); - assertNotNull(node); - assertFalse(node.isEvicted("extension")); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org6", "mod6.1", "0.4")).exists()); - assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.4", "mod6.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveSeveralDefaultWithArtifacts() throws Exception { - // test case for IVY-261 - // mod1.6 depends on - // mod1.4, which depends on mod1.3 and selects one of its artifacts - // mod1.3 and selects two of its artifacts - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - // dependencies - assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") - .exists()); - } - - public void testResolveSeveralDefaultWithArtifactsAndConfs() throws Exception { - // test case for IVY-283 - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-283/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-283/ivy.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - // dependencies - ConfigurationResolveReport crr = report.getConfigurationReport("build"); - assertNotNull(crr); - assertEquals(3, - crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "C", "1.0")).length); - - assertTrue(getArchiveFileInCache("medicel", "C", "1.0", "lib_c_a", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("medicel", "C", "1.0", "lib_c_b", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("medicel", "C", "1.0", "lib_c_d", "jar", "jar").exists()); - } - - public void testResolveSeveralDefaultWithArtifactsAndConfs2() throws Exception { - // second test case for IVY-283 - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-283/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-283/ivy-d.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - // dependencies - ConfigurationResolveReport crr = report.getConfigurationReport("build"); - assertNotNull(crr); - assertEquals(9, crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "module_a", - "local")).length); - - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_a", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_b", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_c", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_d", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_e", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_f", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_g", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_h", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_i", "jar", "jar") - .exists()); - } - - public void testResolveDefaultWithArtifactsConf1() throws Exception { - // mod2.2 depends on mod1.3 and selects its artifacts - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURL(), - getResolveOptions(new String[] {"myconf1"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") - .exists()); - assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists()); - } - - public void testResolveDefaultWithArtifactsConf2() throws Exception { - // mod2.2 depends on mod1.3 and selects its artifacts - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURL(), - getResolveOptions(new String[] {"myconf2"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") - .exists()); - assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") - .exists()); - assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists()); - } - - public void testResolveDefaultWithArtifactsAndConfMapping() throws Exception { - // mod2.2 depends on mod1.3 and specify its artifacts and a conf mapping - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.1.xml").toURL(), - getResolveOptions(new String[] {"myconf1"})); - assertNotNull(report); - assertFalse(report.hasError()); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5.1"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") - .exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") - .exists()); - assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists()); - } - - public void testResolveWithIncludeArtifactsConf1() throws Exception { - // mod2.3 depends on mod2.1 and selects its artifacts in myconf1 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml").toURL(), - getResolveOptions(new String[] {"myconf1"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.4"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveWithIncludeArtifactsConf2() throws Exception { - // mod2.3 depends on mod2.1 and selects its artifacts in myconf1 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml").toURL(), - getResolveOptions(new String[] {"myconf2"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.4"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveWithIncludeArtifactsWithoutConf() throws Exception { - // mod2.3 depends on mod2.1 and selects its artifacts - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.5"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveWithExcludesArtifacts() throws Exception { - // mod2.3 depends on mod2.1 and selects its artifacts - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveWithExcludesArtifacts2() throws Exception { - // mod2.3 depends on mod2.1 and badly excludes artifacts with incorrect matcher - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.2"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveWithExcludesArtifacts3() throws Exception { - // mod2.3 depends on mod2.1 and excludes artifacts with exact matcher - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveWithExcludesArtifacts4() throws Exception { - // mod2.3 depends on mod2.1 and excludes artifacts with regexp matcher - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.4"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveWithExcludesArtifacts5() throws Exception { - // mod2.3 depends on mod2.1 and excludes artifacts with glob matcher - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.5"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); - } - - public void testResolveTransitiveDependencies() throws Exception { - // mod2.1 depends on mod1.1 which depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveTransitiveDisabled() throws Exception { - // mod2.1 depends on mod1.1 which depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml").toURL(), getResolveOptions( - new String[] {"*"}).setTransitive(false)); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testDependenciesOrder() throws Exception { - ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-225.xml"), - getResolveOptions(new String[] {"default"})); - - Set revisions = report.getConfigurationReport("default").getModuleRevisionIds(); - assertTrue("number of revisions is not correct", revisions.size() >= 3); - - // verify the first 3 modules against the ones in the ivy file - Iterator it = revisions.iterator(); - ModuleRevisionId revId1 = (ModuleRevisionId) it.next(); - assertEquals("mod1.2", revId1.getName()); - assertEquals("1.1", revId1.getRevision()); - - ModuleRevisionId revId2 = (ModuleRevisionId) it.next(); - assertEquals("mod3.2", revId2.getName()); - assertEquals("1.4", revId2.getRevision()); - - ModuleRevisionId revId3 = (ModuleRevisionId) it.next(); - assertEquals("mod5.1", revId3.getName()); - assertEquals("4.2", revId3.getRevision()); - } - - public void testDisableTransitivityPerConfiguration() throws Exception { - // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 - // compile conf is not transitive - - // first we resolve compile conf only - _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(), - getResolveOptions(new String[] {"compile"})); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // then we resolve runtime conf - _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(), - getResolveOptions(new String[] {"runtime"})); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // same as before, but resolve both confs in one call - ResolveReport r = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(), - getResolveOptions(new String[] {"runtime", "compile"})); - assertFalse(r.hasError()); - assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber()); - assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber()); - } - - public void testDisableTransitivityPerConfiguration2() throws Exception { - // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 - // compile conf is not transitive - // compile extends runtime - - // first we resolve compile conf only - _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(), - getResolveOptions(new String[] {"compile"})); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // then we resolve runtime conf - _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(), - getResolveOptions(new String[] {"runtime"})); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // same as before, but resolve both confs in one call - ResolveReport r = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(), - getResolveOptions(new String[] {"runtime", "compile"})); - assertFalse(r.hasError()); - assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber()); - assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber()); - } - - public void testDisableTransitivityPerConfiguration3() throws Exception { - // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 - // compile conf is not transitive - // runtime extends compile - - // first we resolve compile conf only - _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(), - getResolveOptions(new String[] {"compile"})); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // then we resolve runtime conf - _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(), - getResolveOptions(new String[] {"runtime"})); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // same as before, but resolve both confs in one call - ResolveReport r = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(), - getResolveOptions(new String[] {"runtime", "compile"})); - assertFalse(r.hasError()); - assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber()); - assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber()); - } - - public void testDisableTransitivityPerConfiguration4() throws Exception { - // mod2.2 (A,B,compile) depends on mod 2.1 (A->runtime;B->compile) - // compile is not transitive and extends A and B - // - // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 - // compile conf is not transitive and extends runtime - - ResolveReport r = _ivy.resolve(new File("test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertFalse(r.hasError()); - - // here we should get all three recursive dependencies - assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),})), r - .getConfigurationReport("A").getModuleRevisionIds()); - - // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1 - assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),})), r - .getConfigurationReport("B").getModuleRevisionIds()); - - // here we should get only mod2.1 cause compile is not transitive - assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] {ModuleRevisionId - .newInstance("org2", "mod2.1", "0.3.2"),})), r.getConfigurationReport("compile") - .getModuleRevisionIds()); - } - - public void testDisableTransitivityPerConfiguration5() throws Exception { - // mod2.2 (A,B,compile) depends on - // mod 2.1 (A->runtime;B->compile) - // mod1.1 (A->*) ]0.9.9,1.0] (which resolves to 1.0) - // compile is not transitive and extends A and B - // - // mod2.1 (compile, runtime) depends on mod1.1 1.0 which depends on mod1.2 2.0 - // compile conf is not transitive and extends runtime - - ResolveReport r = _ivy.resolve(new File("test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml") - .toURL(), getResolveOptions(new String[] {"A", "B", "compile"})); - assertFalse(r.hasError()); - - // here we should get all three recursive dependencies - assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),})), r - .getConfigurationReport("A").getModuleRevisionIds()); - - // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1 - assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),})), r - .getConfigurationReport("B").getModuleRevisionIds()); - - // here we should get only mod2.1 cause compile is not transitive - assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),})), r - .getConfigurationReport("compile").getModuleRevisionIds()); - } - - public void testResolveDiamond() throws Exception { - // mod4.1 depends on - // - mod1.1 which depends on mod1.2 - // - mod3.1 which depends on mod1.2 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.0", "mod3.1", "jar", "jar").exists()); - } - - public void testResolveConflict() throws Exception { - // mod4.1 v 4.1 depends on - // - mod1.1 v 1.0 which depends on mod1.2 v 2.0 - // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.1.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.1"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(0, crr.getDownloadReports(ModuleRevisionId - .newInstance("org1", "mod1.2", "2.0")).length); - assertEquals(1, crr.getDownloadReports(ModuleRevisionId - .newInstance("org1", "mod1.2", "2.1")).length); - - File r = _cacheManager.getConfigurationResolveReportInCache(ResolveOptions - .getDefaultResolveId(md), "default"); - assertTrue(r.exists()); - final boolean[] found = new boolean[] {false}; - SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.parse(r, new DefaultHandler() { - public void startElement(String uri, String localName, String qName, - org.xml.sax.Attributes attributes) throws SAXException { - if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) { - found[0] = true; - } - } - }); - assertTrue(found[0]); // the report should contain the evicted revision - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists()); - - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveConflict2() throws Exception { - // mod4.1 v 4.14 depends on - // - mod1.1 v 1.0 which depends on mod1.2 v 2.0 - // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 - // - mod6.1 v 0.3 which depends on mod1.2 v 2.0 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.14.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - // dependencies - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(0, crr.getDownloadReports(ModuleRevisionId - .newInstance("org1", "mod1.2", "2.0")).length); - assertEquals(1, crr.getDownloadReports(ModuleRevisionId - .newInstance("org1", "mod1.2", "2.1")).length); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.14"); - File r = _cacheManager.getConfigurationResolveReportInCache(ResolveOptions - .getDefaultResolveId(mrid.getModuleId()), "default"); - assertTrue(r.exists()); - final boolean[] found = new boolean[] {false}; - SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.parse(r, new DefaultHandler() { - public void startElement(String uri, String localName, String qName, - org.xml.sax.Attributes attributes) throws SAXException { - if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) { - found[0] = true; - } - } - }); - assertTrue(found[0]); // the report should contain the evicted revision - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists()); - - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveConflict3() throws Exception { - // test case for IVY-264 - // a depends on x latest, y latest, z latest - // x and z depends on commons-lang 1.0.1 - // y depends on commons-lang 2.0 - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-264/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-264/ivy.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - // dependencies - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("myorg", - "commons-lang", "1.0.1")).length); - assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("myorg", - "commons-lang", "2.0")).length); - - assertFalse(getArchiveFileInCache("myorg", "commons-lang", "1.0.1", "commons-lang", "jar", - "jar").exists()); - - assertTrue(getArchiveFileInCache("myorg", "commons-lang", "2.0", "commons-lang", "jar", - "jar").exists()); - } - - public void testTransitiveEviction() throws Exception { - // mod7.3 depends on mod7.2 v1.0 and on mod7.1 v2.0 - // mod7.2 v1.0 depends on mod7.1 v1.0 (which then should be evicted) - // mod7.1 v1.0 depends on mod 1.2 v1.0 (which should be evicted by transitivity) - - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod7.3/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org7", "mod7.3", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org7", "mod7.2", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org7", "mod7.2", "1.0", "mod7.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org7", "mod7.1", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org7", "mod7.1", "2.0", "mod7.1", "jar", "jar").exists()); - - assertTrue(!getArchiveFileInCache("org7", "mod7.1", "1.0", "mod7.1", "jar", "jar").exists()); - - assertTrue(!getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testTransitiveEviction2() throws Exception { - // IVY-199 - // mod4.1 v 4.13 depends on - // - mod3.2 v 1.2.1 which depends on - // - mod3.1 v 1.0 which depends on mod1.2 v 2.0 - // - mod1.2 v 2.1 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.13.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveConflictInConf() throws Exception { - // conflicts in separate confs are not conflicts - - // mod2.1 conf A depends on mod1.1 which depends on mod1.2 2.0 - // mod2.1 conf B depends on mod1.2 2.1 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.4"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testEvictWithConf() throws Exception { - // bug 105 - test #1 - - // mod6.1 r1.0 depends on - // mod5.1 r4.2 conf A - // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B - // - // mod5.1 r4.2 conf B depends on mod1.2 r2.0 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // should have been evicted before download - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists()); - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - } - - public void testEvictWithConf2() throws Exception { - // same as preceding one but with inverse order, so that - // eviction is done after download - // bug 105 - test #2 - - // mod6.1 r1.1 depends on - // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B - // mod5.1 r4.2 conf A - // - // mod5.1 r4.2 conf B depends on mod1.2 r2.0 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.1.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.1"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // even late eviction should avoid artifact downloading - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - } - - public void testEvictWithConfInMultiConf() throws Exception { - // same as preceding ones but the conflict appears in several root confs - // bug 105 - test #3 - - // mod6.1 r1.2 conf A and conf B depends on - // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B - // mod5.1 r4.2 conf A - // - // mod5.1 r4.2 conf B depends on mod1.2 r2.0 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.2.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.2"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // all artifacts should be present in both confs - ConfigurationResolveReport crr = report.getConfigurationReport("A"); - assertNotNull(crr); - assertEquals(2, crr.getDownloadReports(ModuleRevisionId - .newInstance("org5", "mod5.1", "4.2")).length); - - crr = report.getConfigurationReport("B"); - assertNotNull(crr); - assertEquals(2, crr.getDownloadReports(ModuleRevisionId - .newInstance("org5", "mod5.1", "4.2")).length); - - // even late eviction should avoid artifact downloading - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - } - - public void testEvictWithConfInMultiConf2() throws Exception { - // same as preceding one but the conflict appears in a root conf and not in another - // which should keep the evicted - // bug 105 - test #4 - - // mod6.1 r1.3 conf A depends on - // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B - // - // mod6.1 r1.3 conf B depends on - // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B - // mod5.1 r4.2 conf A - // - // mod5.1 r4.2 conf B depends on mod1.2 r2.0 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.3.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - // 4.2 artifacts should be present in conf B only - ConfigurationResolveReport crr = report.getConfigurationReport("A"); - assertNotNull(crr); - assertEquals(0, crr.getDownloadReports(ModuleRevisionId - .newInstance("org5", "mod5.1", "4.2")).length); - - crr = report.getConfigurationReport("B"); - assertNotNull(crr); - assertEquals(2, crr.getDownloadReports(ModuleRevisionId - .newInstance("org5", "mod5.1", "4.2")).length); - } - - public void testResolveForce() throws Exception { - // mod4.1 v 4.2 depends on - // - mod1.2 v 2.0 and forces it - // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.2.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.2"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceAfterConflictSolved() throws Exception { - // IVY-193 - // mod4.1 v 4.9 depends on - // - mod3.2 v 1.1 which depends on mod1.2 v 2.0 - // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 - // - mod1.2 v 2.0 and forces it - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.9.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.9"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceAfterDependencyExist() throws Exception { - // IVY-193 - // mod4.1 v 4.10 depends on - // - mod3.1 v 1.0.1 which depends on mod1.2 v 2.0 and forces it - // - mod3.2 v 1.2 which depends on mod1.2 v 2.1 and on mod3.1 v1.0.1 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.10.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - - // dependencies - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceInDepOnly() throws Exception { - // IVY-193 - // mod4.1 v 4.11 depends on - // - mod1.2 v 2.0 - // - mod3.2 v 1.3 which depends on - // - mod3.1 v1.1 which depends on - // - mod1.2 v 2.1 - // - mod1.2 v 1.0 and forces it - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.11.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "1.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceInDepOnly2() throws Exception { - // IVY-193 - // mod4.1 v 4.12 depends on - // - mod3.1 v1.0 which depends on - // - mod1.2 v 2.0 - // - mod3.2 v 1.4 which depends on - // - mod1.2 v 2.0 and forces it - // - mod3.1 v1.1 which depends on - // - mod1.2 v 2.1 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.12.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceWithDynamicRevisions() throws Exception { - // mod4.1 v 4.5 depends on - // - mod1.2 v 1+ and forces it - // - mod3.1 v 1.2 which depends on mod1.2 v 2+ - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.5.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.5"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.2")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.2", "mod3.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceWithDynamicRevisionsAndSeveralConfs() throws Exception { - // mod4.1 v 4.6 (conf compile, test extends compile) depends on - // - mod1.2 v 1+ and forces it in conf compile - // - mod3.1 v 1.2 in conf test which depends on mod1.2 v 2+ - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.6.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.6"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.2")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.2", "mod3.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceWithDynamicRevisionsAndSeveralConfs2() throws Exception { - // mod4.1 v 4.7 (conf compile, test extends compile) depends on - // - mod1.2 v 1+ and forces it in conf compile - // - mod3.1 v 1.3 in conf test->runtime - // which defines confs compile, runtime extends compile - // which depends on mod1.2 v 2+ in conf compile->default - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.7.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.7"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.3")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.3", "mod3.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveForceWithDynamicRevisionsAndCyclicDependencies() throws Exception { - // IVY-182 - // * has no revision - // * declares conf compile, test extends compile, - // * depends on - // - mod1.2 v 1+ and forces it in conf compile - // - mod3.1 v 1+ in conf test->runtime excluding mod4.1 (to avoid cyclic dep failure) - // which defines confs compile, runtime extends compile - // which depends on mod1.2 v 2+ in conf compile->default - // which depends on mod4.1 v 4+ in conf compile->compile - ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-182.xml"), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleId mid = new ModuleId("test", "IVY-182"); - assertEquals(mid, md.getModuleRevisionId().getModuleId()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org3", "mod3.1", "1.4")).exists()); - assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.4", "mod3.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveContradictoryConflictResolution() throws Exception { - // mod10.1 v 1.0 depends on - // - mod1.2 v 2.0 and forces it - // - mod4.1 v 4.1 (which selects mod1.2 v 2.1 and evicts mod1.2 v 2.0) - // mod4.1 v 4.1 depends on - // - mod1.1 v 1.0 which depends on mod1.2 v 2.0 - // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod10.1/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org10", "mod10.1", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // conflicting dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveContradictoryConflictResolution2() throws Exception { - // BUG IVY-130 : only mod1.2 v2.0 should be resolved and not v2.1 (because of force) - // mod10.1 v 1.1 depends on - // - mod1.2 v 2.0 and forces it - // - mod4.1 v 4.3 - // mod4.1 v 4.3 depends on - // - mod1.2 v 2.1 - // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 - _ivy.resolve(new File("test/repositories/2/mod10.1/ivy-1.1.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - // conflicting dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveContradictoryConflictResolution3() throws Exception { - // mod 1.2 v2.0 should be selected (despite conflict manager in 4.1, because of force in - // 10.1) - // mod10.1 v 1.3 depends on - // - mod1.2 v 2.0 and forces it - // - mod4.1 v 4.4 - // mod4.1 v 4.4 depends on - // - mod1.2 v 2.0 but selects mod1.2 v 2.1 - // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod10.1/ivy-1.3.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - IvyNode[] evicted = report.getConfigurationReport("default").getEvictedNodes(); - assertEquals(1, evicted.length); - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"), evicted[0] - .getResolvedId()); - } - - public void testExtends() throws Exception { - // mod 5.2 depends on mod5.1 conf B - // mod5.1 conf B publishes art51B - // mod5.1 conf B extends conf A - // mod5.1 conf A publishes art51A - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod5.2/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5", "mod5.2", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - } - - public void testMultiConfs() throws Exception { - // mod 5.2 depends on mod5.1 conf B in its conf B and conf A in its conf A - // mod5.1 conf B publishes art51B - // mod5.1 conf A publishes art51A - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod5.2/ivy-2.0.xml") - .toURL(), getResolveOptions(new String[] {"B", "A"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5", "mod5.2", "2.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - ModuleRevisionId depId = ModuleRevisionId.newInstance("org5", "mod5.1", "4.1"); - - ConfigurationResolveReport crr = report.getConfigurationReport("A"); - assertNotNull(crr); - assertEquals(1, crr.getDownloadReports(depId).length); - - File r = new File(_cache, ResolveOptions.getDefaultResolveId(mrid.getModuleId()) + "-A.xml"); - assertTrue(r.exists()); - final boolean[] found = new boolean[] {false}; - SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.parse(r, new DefaultHandler() { - public void startElement(String uri, String localName, String qName, - org.xml.sax.Attributes attributes) throws SAXException { - if ("artifact".equals(qName) && "art51B".equals(attributes.getValue("name"))) { - found[0] = true; - } - } - }); - assertFalse(found[0]); - - assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists()); - } - - public void testThisConfiguration() throws Exception { - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod14.4/ivy-1.1.xml") - .toURL(), getResolveOptions(new String[] {"compile"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org14", "mod14.4", "1.1"); - assertEquals(mrid, md.getModuleRevisionId()); - ConfigurationResolveReport crr = report.getConfigurationReport("compile"); - assertNotNull(crr); - assertEquals(4, crr.getArtifactsNumber()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org14", "mod14.2", "1.1")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org14", "mod14.1", "1.1")).exists()); - assertTrue(!_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org8", "mod8.3", "1.0")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org8", "mod8.1", "1.0")).exists()); - - cleanCache(); - createCache(); - report = _ivy.resolve(new File("test/repositories/2/mod14.4/ivy-1.1.xml").toURL(), - getResolveOptions(new String[] {"standalone"})); - crr = report.getConfigurationReport("standalone"); - assertNotNull(crr); - assertEquals(7, crr.getArtifactsNumber()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org14", "mod14.1", "1.1")).exists()); - assertTrue(!_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org14", "mod14.2", "1.1")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org8", "mod8.3", "1.0")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org8", "mod8.1", "1.0")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org8", "mod8.4", "1.1")).exists()); - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org8", "mod8.2", "1.1")).exists()); - } - - public void testLatest() throws Exception { - // mod1.4 depends on latest mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.1"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - ModuleRevisionId depId = ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"); - - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(1, crr.getDownloadReports(depId).length); - - File r = _cacheManager.getConfigurationResolveReportInCache(ResolveOptions - .getDefaultResolveId(mrid.getModuleId()), "default"); - assertTrue(r.exists()); - final boolean[] found = new boolean[] {false}; - SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.parse(r, new DefaultHandler() { - public void startElement(String uri, String localName, String qName, - org.xml.sax.Attributes attributes) throws SAXException { - if ("artifact".equals(qName) && "mod1.2".equals(attributes.getValue("name"))) { - found[0] = true; - } - } - }); - assertTrue(found[0]); - - assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testLatestMultiple() throws Exception { - // mod1.5 depends on - // latest mod1.4, which depends on mod1.2 2.2 - // latest mod1.2 (which is 2.2) - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertFalse(report.hasError()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.4", "2.0")).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); - } - - public void testLatestWhenReleased() throws Exception { - // The test verify that latest.integration dependencies can be resolved with released - // version also. - ResolveReport report = _ivy.resolve( - ResolveTest.class.getResource("ivy-latestreleased.xml"), - getResolveOptions(new String[] {"default"})); - assertFalse(report.hasError()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod_released", "1.1")).exists()); - } - - public void testVersionRange1() throws Exception { - // mod 1.4 depends on mod1.2 [1.0,2.0[ - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertFalse(report.hasError()); - - // dependencies - ModuleRevisionId depId = ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"); - - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(1, crr.getDownloadReports(depId).length); - - assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); - } - - public void testVersionRange2() throws Exception { - // mod 1.4 depends on mod1.2 [1.5,2.0[ - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File( - "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertTrue(report.hasError()); - } - - public void testLatestMilestone() throws Exception { - // mod9.2 depends on latest.milestone of mod6.4 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertFalse(report.hasError()); - - // dependencies - ModuleRevisionId depId = ModuleRevisionId.newInstance("org6", "mod6.4", "3"); - - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(1, crr.getDownloadReports(depId).length); - - assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); - } - - public void testLatestMilestone2() throws Exception { - // mod9.2 depends on latest.milestone of mod6.2, but there is no milestone - // test case for IVY-318 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml").toURL(), - getResolveOptions(new String[] {"default"})); - // we should have an error since there is no milestone version, it should be considered as a - // non resolved dependency - assertTrue(report.hasError()); - - // dependencies - ConfigurationResolveReport crr = report.getConfigurationReport("default"); - assertNotNull(crr); - assertEquals(0, crr.getArtifactsNumber()); - } - - public void testIVY56() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/bugIVY-56/ivysettings.xml")); - - ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-56.xml"), - getResolveOptions(new String[] {"default"})); - assertNotNull(report); - } - - public void testIVY214() throws Exception { - ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-214.xml"), - getResolveOptions(new String[] {"compile"})); - - assertNotNull(report); - assertFalse(report.hasError()); - - assertEquals("Number of artifacts not correct", 1, report.getConfigurationReport("compile") - .getArtifactsNumber()); - } - - public void testIVY218() throws Exception { - ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-218.xml"), - getResolveOptions(new String[] {"test"})); - - assertNotNull(report); - assertFalse(report.hasError()); - - assertEquals("Number of artifacts not correct", 3, report.getConfigurationReport("test") - .getArtifactsNumber()); - } - - public void testCircular() throws Exception { - // mod6.3 depends on mod6.2, which itself depends on mod6.3 - - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"default"})); - assertFalse(report.hasError()); - - _settings.setCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance()); - report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertFalse(report.hasError()); - - _settings.setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance()); - report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertFalse(report.hasError()); - - _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); - try { - _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"default"})); - fail("no exception with circular dependency strategy set to error"); - } catch (CircularDependencyException ex) { - assertEquals( - "[ org6 | mod6.3 | 1.0 ]->[ org6 | mod6.2 | 1.0 ]->[ org6 | mod6.3 | latest.integration ]", - ex.getMessage()); - } - } - - public void testCircular2() throws Exception { - // mod 9.1 (no revision) depends on mod9.2, which depends on mod9.1 2.+ - - ResolveReport report = _ivy.resolve(new File("test/repositories/circular/ivy.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); - try { - _ivy.resolve(new File("test/repositories/circular/ivy.xml").toURL(), - getResolveOptions(new String[] {"*"})); - fail("no exception with circular dependency strategy set to error"); - } catch (CircularDependencyException ex) { - // ok - assertEquals( - "[ org8 | mod8.5 | NONE ]->[ org8 | mod8.6 | 2.+ ]->[ org8 | mod8.5 | 2.+ ]", ex - .getMessage()); - } - } - - public void testCircular3() throws Exception { - // test case for IVY-400 - // mod6.3 depends on mod6.2, which itself depends on mod6.3, - // in both configuration default and test - - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml") - .toURL(), getResolveOptions(new String[] {"default", "test"})); - assertFalse(report.hasError()); - // we should have mod 6.2 artifact in both configurations - assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber()); - assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber()); - - _settings.setCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance()); - report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml").toURL(), - getResolveOptions(new String[] {"default", "test"})); - assertFalse(report.hasError()); - assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber()); - assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber()); - - _settings.setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance()); - report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml").toURL(), - getResolveOptions(new String[] {"default", "test"})); - assertFalse(report.hasError()); - assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber()); - assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber()); - - _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); - try { - _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml").toURL(), - getResolveOptions(new String[] {"default", "test"})); - fail("no exception with circular dependency strategy set to error"); - } catch (CircularDependencyException ex) { - assertEquals( - "[ org6 | mod6.3 | 1.2 ]->[ org6 | mod6.2 | 1.1 ]->[ org6 | mod6.3 | 1.2 ]", ex - .getMessage()); - } - } - - public void testRegularCircular() throws Exception { - // mod11.1 depends on mod11.2 but excludes itself - // mod11.2 depends on mod11.1 - _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod11.1/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"test"})); - - assertNotNull(report); - assertFalse(report.hasError()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org11", "mod11.2", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org11", "mod11.2", "1.0", "mod11.2", "jar", "jar") - .exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org11", "mod11.1", "1.0")).exists()); - assertFalse(getArchiveFileInCache("org11", "mod11.1", "1.0", "mod11.1", "jar", "jar") - .exists()); - } - - public void testResolveDualChain() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(ResolveTest.class.getResource("dualchainresolverconf.xml")); - - DependencyResolver resolver = ivy.getSettings().getResolver("default"); - assertNotNull(resolver); - assertTrue(resolver instanceof DualResolver); - - // first without cache - ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), - getResolveOptions(new String[] {"default"})); - - assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml").exists()); - assertTrue(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists()); - assertTrue(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists()); - - // second with cache for ivy file only - new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").delete(); - new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").delete(); - assertFalse(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists()); - assertFalse(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists()); - ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), - getResolveOptions(new String[] {"default"})); - - assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml").exists()); - assertTrue(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists()); - assertTrue(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists()); - } - - public void testBug148() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/bug148/ivysettings.xml")); - - ivy.resolve(ResolveTest.class.getResource("ivy-148.xml"), - getResolveOptions(new String[] {"*"})); - - assertTrue(new File("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml").exists()); - assertTrue(new File("build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar").exists()); - assertTrue(new File("build/cache/idautomation/barcode/ivy-4.10.xml").exists()); - assertTrue(new File("build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar") - .exists()); - } - - public void testBug148b() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/bug148/ivysettings.xml")); - - ivy.resolve(ResolveTest.class.getResource("ivy-148b.xml"), - getResolveOptions(new String[] {"*"})); - - assertTrue(new File("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml").exists()); - assertTrue(new File("build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar").exists()); - assertTrue(new File("build/cache/idautomation/barcode/ivy-4.10.xml").exists()); - assertTrue(new File("build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar") - .exists()); - } - - public void testBadFiles() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/badfile/ivysettings.xml")); - - try { - ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badorg.xml").toURL(), - getResolveOptions(new String[] {"*"})); - fail("bad org should have raised an exception !"); - } catch (Exception ex) { - // OK, it raised an exception - } - try { - ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badmodule.xml").toURL(), - getResolveOptions(new String[] {"*"})); - fail("bad module should have raised an exception !"); - } catch (Exception ex) { - // OK, it raised an exception - } - try { - ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badrevision.xml").toURL(), - getResolveOptions(new String[] {"*"})); - fail("bad revision should have raised an exception !"); - } catch (Exception ex) { - // OK, it raised an exception - } - } - - public void testTransitiveSetting() throws Exception { - // mod2.4 depends on mod1.1 with transitive set to false - // mod1.1 depends on mod1.2, which should not be resolved because of the transitive setting - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.4", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - - assertTrue(!_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(!getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolverDirectlyUsingCache() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(ResolveTest.class.getResource("badcacheconf.xml")); - File depIvyFileInCache = ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")); - FileUtil.copy(File.createTempFile("test", "xml"), depIvyFileInCache, null); // creates a - // fake - // dependency - // file in cache - ResolveReport report = ivy.resolve(new File( - "test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.4", "0.3"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(depIvyFileInCache.exists()); - assertTrue(!TestHelper.getArchiveFileInCache(ivy, _cache, "org1", "mod1.1", "1.0", - "mod1.1", "jar", "jar").exists()); - } - - public void testVisibility1() throws Exception { - _ivy.resolve(new File("test/repositories/2/mod8.2/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0", "a-private", "txt", "txt") - .exists()); - } - - public void testVisibility2() throws Exception { - _ivy.resolve(new File("test/repositories/2/mod8.3/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"private"})); - - assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0", "a-private", "txt", "txt") - .exists()); - assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.0", "a", "txt", "txt").exists()); - } - - public void testVisibility3() throws Exception { - _ivy.resolve(new File("test/repositories/2/mod8.4/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0", "a-private", "txt", "txt") - .exists()); - assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.0", "a", "txt", "txt").exists()); - } - - public void testVisibility4() throws Exception { - _ivy.resolve(new File("test/repositories/2/mod8.4/ivy-1.1.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.1", "a-private", "txt", "txt") - .exists()); - assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.1", "a", "txt", "txt").exists()); - } - - // ///////////////////////////////////////////////////////// - // here comes a series of test provided by Chris Rudd - // about configuration mapping and eviction - // ///////////////////////////////////////////////////////// - - public void testConfigurationMapping1() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/1/ivy.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - ConfigurationResolveReport conf = report.getConfigurationReport("default"); - - assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); - assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); - assertContainsArtifact("test", "b", "1.0.2", "b", "txt", "txt", conf); - assertDoesntContainArtifact("test", "b", "1.0.2", "b-bt", "txt", "txt", conf); - assertContainsArtifact("test", "c", "1.0.2", "c", "txt", "txt", conf); - assertDoesntContainArtifact("test", "c", "1.0.2", "c-bt", "txt", "txt", conf); - } - - public void testConfigurationMapping2() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/2/ivy.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - ConfigurationResolveReport conf = report.getConfigurationReport("default"); - - assertContainsArtifact("test", "a", "1.0.1", "a", "txt", "txt", conf); - assertDoesntContainArtifact("test", "a", "1.0.1", "a-bt", "txt", "txt", conf); - assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); - assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); - assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); - assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); - } - - public void testConfigurationMapping3() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/3/ivy.xml") - .toURL(), getResolveOptions(new String[] {"buildtime"})); - - ConfigurationResolveReport conf = report.getConfigurationReport("buildtime"); - - assertContainsArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); - assertDoesntContainArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); - assertContainsArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); - assertDoesntContainArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); - assertContainsArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); - assertDoesntContainArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); - } - - public void testConfigurationMapping4() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/4/ivy.xml") - .toURL(), getResolveOptions(new String[] {"default"})); - - ConfigurationResolveReport conf = report.getConfigurationReport("default"); - - assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); - assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); - assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); - assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); - assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); - assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); - } - - public void testConfigurationMapping5() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/5/ivy.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - ConfigurationResolveReport conf = report.getConfigurationReport("default"); - - assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); - assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); - assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); - assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); - assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); - assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); - } - - public void testConfigurationMapping6() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/6/ivy.xml") - .toURL(), getResolveOptions(new String[] {"default", "buildtime"})); - - ConfigurationResolveReport conf = report.getConfigurationReport("default"); - - assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); - assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); - assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); - assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); - assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); - assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); - } - - public void testConfigurationMapping7() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/7/ivy.xml") - .toURL(), getResolveOptions(new String[] {"buildtime", "default"})); - - ConfigurationResolveReport conf = report.getConfigurationReport("default"); - - assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); - assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); - assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); - assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); - assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); - assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); - } - - public void testIVY97() throws Exception { - // mod9.2 depends on mod9.1 and mod1.2 - // mod9.1 depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org9", "mod9.2", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org9", "mod9.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org9", "mod9.1", "1.0", "mod9.1", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveTransitiveExcludesSimple() throws Exception { - // mod2.5 depends on mod2.3 and excludes one artifact from mod2.1 - // mod2.3 depends on mod2.1 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.5", "0.6"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.3", "0.7")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.3", "0.7", "mod2.3", "jar", "jar").exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - } - - public void testResolveTransitiveExcludesDiamond1() throws Exception { - // mod2.6 depends on mod2.3 and mod2.5 - // mod2.3 depends on mod2.1 and excludes art21B - // mod2.5 depends on mod2.1 and excludes art21A - _ivy.resolve(new File("test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - } - - public void testResolveTransitiveExcludesDiamond2() throws Exception { - // mod2.6 depends on mod2.3 and mod2.5 - // mod2.3 depends on mod2.1 and excludes art21B - // mod2.5 depends on mod2.1 and excludes art21B - _ivy.resolve(new File("test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - } - - public void testResolveTransitiveExcludesDiamond3() throws Exception { - // mod2.6 depends on mod2.3 and mod2.5 and on mod2.1 for which it excludes art21A - // mod2.3 depends on mod2.1 and excludes art21B - // mod2.5 depends on mod2.1 and excludes art21B - _ivy.resolve(new File("test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - } - - public void testResolveTransitiveExcludes2() throws Exception { - // mod2.6 depends on mod2.3 for which it excludes art21A - // mod2.3 depends on mod2.1 and excludes art21B - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml").toURL(), - getResolveOptions(new String[] {"*"})); - ModuleDescriptor md = report.getModuleDescriptor(); - assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.9"), md - .getModuleRevisionId()); - - assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); - } - - public void testResolveExcludesModule() throws Exception { - // mod2.6 depends on mod2.1 and excludes mod1.1 - // mod2.1 depends on mod1.1 which depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml").toURL(), - getResolveOptions(new String[] {"*"})); - ModuleDescriptor md = report.getModuleDescriptor(); - assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.10"), md - .getModuleRevisionId()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveExcludesModuleWide() throws Exception { - // mod2.6 depends on mod2.1 and excludes mod1.1 module wide - // mod2.1 depends on mod1.1 which depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org2/mod2.6/ivys/ivy-0.11.xml").toURL(), - getResolveOptions(new String[] {"*"})); - ModuleDescriptor md = report.getModuleDescriptor(); - assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.11"), md - .getModuleRevisionId()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testResolveExceptConfiguration() throws Exception { - // mod10.2 depends on mod5.1 conf *, !A - _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-2.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists()); - } - - public void testResolveFallbackConfiguration() throws Exception { - // mod10.2 depends on mod5.1 conf runtime(default) - _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - } - - public void testResolveFallbackConfiguration2() throws Exception { - // mod10.2 depends on mod5.1 conf runtime(*) - _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.1.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - } - - public void testResolveFallbackConfiguration3() throws Exception { - // mod10.2 depends on mod5.1 conf runtime(*),compile(*) - _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.2.xml").toURL(), - getResolveOptions(new String[] {"*"})); - - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - } - - public void testResolveFallbackConfiguration4() throws Exception { - // mod10.2 depends on mod5.1 conf runtime() - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.3.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - assertFalse(report.hasError()); - - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); - assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); - } - - public void testResolveMaven2() throws Exception { - // test3 depends on test2 which depends on test - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/m2/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File( - "test/repositories/m2/org/apache/test3/1.0/test3-1.0.pom").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test3", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("org.apache", "test2", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test2", "1.0", - "test2", "jar", "jar").exists()); - - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("org.apache", "test", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test", "1.0", - "test", "jar", "jar").exists()); - } - - public void testResolveMaven2Classifiers() throws Exception { - // test case for IVY-418 - // test-classifier depends on test-classified with classifier asl - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/m2/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File( - "test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom") - .toURL(), getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId - .newInstance("org.apache", "test-classifier", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("org.apache", "test-classified", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test-classified", - "1.0", "test-classified", "jar", "jar").exists()); - } - - public void testResolveMaven2WithVersionProperty() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/m2/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File( - "test/repositories/m2/org/apache/test-version/1.0/test-version-1.0.pom").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test-version", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("org.apache", "test-classifier", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test-classifier", - "1.0", "test-classifier", "jar", "jar").exists()); - } - - public void testNamespaceMapping() throws Exception { - // the dependency is in another namespace - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); - ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace.xml"), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("systemorg", "systemmod", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg", "systemmod", "1.0", - "A", "jar", "jar").exists()); - } - - public void testNamespaceMapping2() throws Exception { - // the dependency is in another namespace and has itself a dependency on a module available - // in the same namespace - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); - ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace2.xml"), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "2.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("systemorg", "systemmod2", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg", "systemmod2", "1.0", - "B", "jar", "jar").exists()); - - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("systemorg", "systemmod", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg", "systemmod", "1.0", - "A", "jar", "jar").exists()); - } - - public void testNamespaceMapping3() throws Exception { - // same as 2 but with poms - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); - ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace3.xml"), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "3.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); - - // dependencies - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("systemorg2", "system-2", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg2", "system-2", "1.0", - "2", "jar", "jar").exists()); - - assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( - ModuleRevisionId.newInstance("systemorg2", "system-1", "1.0")).exists()); - assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg2", "system-1", "1.0", - "1", "jar", "jar").exists()); - } - - public void testNamespaceMapping4() throws Exception { - // same as 2 but with incorrect dependency asked: the first ivy file asks for a dependency - // in the resolver namespace and not the system one: this should fail - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); - ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace4.xml"), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "4.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertTrue(report.hasError()); - } - - public void testIVY151() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/multirevisions/ivysettings.xml")); - ResolveReport report = ivy.resolve(new File("test/repositories/multirevisions/ivy.xml") - .toURL(), getResolveOptions(new String[] {"compile", "test"})); - - assertNotNull(report); - assertNotNull(report.getUnresolvedDependencies()); - assertEquals("Number of unresolved dependencies not correct", 0, report - .getUnresolvedDependencies().length); - } - - public void testCheckRevision() throws Exception { - // mod12.2 depends on mod12.1 1.0 which depends on mod1.2 - // mod12.1 doesn't have revision in its ivy file - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod12.2/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - assertTrue(report.hasError()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org12", "mod12.1", "1.0")).exists()); - assertFalse(getArchiveFileInCache("org12", "mod12.1", "1.0", "mod12.1", "jar", "jar") - .exists()); - - assertFalse(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testTrustRevision() throws Exception { - // mod12.2 depends on mod12.1 1.0 which depends on mod1.2 - // mod12.1 doesn't have revision in its ivy file - - ((BasicResolver) _settings.getResolver("2-ivy")).setCheckconsistency(false); - - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod12.2/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - assertFalse(report.hasError()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org12", "mod12.1", "1.0")).exists()); - assertTrue(getArchiveFileInCache("org12", "mod12.1", "1.0", "mod12.1", "jar", "jar") - .exists()); - - assertTrue(_cacheManager.getIvyFileInCache( - ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); - assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); - } - - public void testTransitiveConfMapping() throws Exception { - // IVY-168 - // mod13.3 depends on mod13.2 which depends on mod13.1 - // each module has two confs: j2ee and compile - // each module only publishes one artifact in conf compile - // each module has the following conf mapping on its dependencies: *->@ - // moreover, mod13.1 depends on mod1.2 in with the following conf mapping: compile->default - // thus conf j2ee should be empty for each modules - - ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod13.3/ivy-1.0.xml") - .toURL(), getResolveOptions(new String[] {"*"})); - - assertFalse(report.hasError()); - - assertEquals(3, report.getConfigurationReport("compile").getArtifactsNumber()); - assertEquals(0, report.getConfigurationReport("j2ee").getArtifactsNumber()); - } - - public void testExtraAttributes() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/extra-attributes/ivysettings.xml")); - - ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-extra-att.xml"), - getResolveOptions(ivy.getSettings(), new String[] {"*"}).setValidate(false)); - assertFalse(report.hasError()); - - assertTrue(new File(_cache, "apache/mymodule/task1/1854/ivy.xml").exists()); - assertTrue(new File(_cache, "apache/mymodule/task1/1854/mymodule-windows.jar").exists()); - assertTrue(new File(_cache, "apache/mymodule/task1/1854/mymodule-linux.jar").exists()); - } - - public void testBranches1() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/branches/ivysettings.xml")); - - ResolveReport report = ivy.resolve(new File( - "test/repositories/branches/bar/bar1/trunk/1/ivy.xml").toURL(), getResolveOptions( - new String[] {"*"}).setValidate(false)); - assertFalse(report.hasError()); - - assertTrue(getArchiveFileInCache("foo", "foo1", "3", "foo1", "jar", "jar").exists()); - } - - public void testBranches2() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/branches/ivysettings.xml")); - - ResolveReport report = ivy.resolve(new File( - "test/repositories/branches/bar/bar1/trunk/2/ivy.xml").toURL(), getResolveOptions( - new String[] {"*"}).setValidate(false)); - assertFalse(report.hasError()); - - assertTrue(getArchiveFileInCache("foo", "foo1", "4", "foo1", "jar", "jar").exists()); - } - - public void testBranches3() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/branches/ivysettings-defaultbranch1.xml")); - - ResolveReport report = ivy.resolve(new File( - "test/repositories/branches/bar/bar1/trunk/1/ivy.xml").toURL(), getResolveOptions( - new String[] {"*"}).setValidate(false)); - assertFalse(report.hasError()); - - assertTrue(getArchiveFileInCache("foo", "foo1", "4", "foo1", "jar", "jar").exists()); - } - - public void testBranches4() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/branches/ivysettings.xml")); - - ResolveReport report = ivy.resolve(new File( - "test/repositories/branches/bar/bar1/trunk/3/ivy.xml").toURL(), getResolveOptions( - new String[] {"*"}).setValidate(false)); - assertFalse(report.hasError()); - - assertTrue(getArchiveFileInCache("foo", "foo1", "3", "foo1", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("bar", "bar2", "2", "bar2", "jar", "jar").exists()); - } - - public void testBranches5() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/branches/ivysettings-fooonbranch1.xml")); - - ResolveReport report = ivy.resolve(new File( - "test/repositories/branches/bar/bar1/trunk/3/ivy.xml").toURL(), getResolveOptions( - new String[] {"*"}).setValidate(false)); - assertFalse(report.hasError()); - - assertTrue(getArchiveFileInCache("foo", "foo1", "4", "foo1", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("bar", "bar2", "2", "bar2", "jar", "jar").exists()); - } - - public void testExternalArtifacts() throws Exception { - Ivy ivy = Ivy.newInstance(); - ivy.getSettings().setVariable("test.base.url", - new File("test/repositories/external-artifacts").toURL().toString()); - ivy.configure(new File("test/repositories/external-artifacts/ivysettings.xml")); - - ResolveReport report = ivy.resolve(new File("test/repositories/external-artifacts/ivy.xml") - .toURL(), getResolveOptions(new String[] {"*"}).setValidate(false)); - assertFalse(report.hasError()); - - assertTrue(getArchiveFileInCache("apache", "A", "1.0", "a", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("apache", "B", "2.0", "b", "jar", "jar").exists()); - assertTrue(getArchiveFileInCache("apache", "C", "3.0", "C", "jar", "jar").exists()); - } - - public void testResolveWithSpecifiedCache() throws Exception { - File cache2 = new File("build/cache2"); - try { - _ivy.getSettings().setDefaultCache(_cache); - - // the module to resolve - ModuleRevisionId module = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - - // use a non-default cache - ResolveOptions options = getResolveOptions(new String[] {"*"}); - options.setTransitive(false); - options.setUseOrigin(true); - options.setCache(CacheManager.getInstance(_ivy.getSettings(), cache2)); - ResolveReport report = _ivy.getResolveEngine().resolve(module, options, false); - - // the resolved module - ModuleRevisionId resolvedModule = report.getModuleDescriptor() - .getResolvedModuleRevisionId(); - - // verify that the module in the default cache doesn't exist - assertEquals("Default cache is not empty", _cache.list().length, 0); - - // verify the artifact does exist in the non-default cache. - CacheManager nonDefaultManager = _ivy.getCacheManager(cache2); - assertTrue(TestHelper.getArchiveFileInCache(nonDefaultManager, "org1", "mod1.1", "1.0", - "mod1.1", "jar", "jar").exists()); - assertTrue(nonDefaultManager.getResolvedIvyFileInCache(resolvedModule).exists()); - assertTrue(nonDefaultManager.getResolvedIvyPropertiesInCache(resolvedModule).exists()); - assertNotNull(nonDefaultManager.getSavedArtifactOrigin((Artifact) report.getArtifacts() - .get(0))); - } finally { - // delete the non-default cache - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/cache2")); - del.execute(); - } - } - - public void testResolveWithMultipleIvyPatterns() throws Exception { - Ivy ivy = new Ivy(); - ivy.configure(new File("test/repositories/multi-ivypattern/ivysettings.xml")); - - ModuleRevisionId module = ModuleRevisionId.newInstance("org1", "mod1.1", "1.+"); - - // use a non-default cache - ResolveOptions options = getResolveOptions(ivy.getSettings(), new String[] {"*"}); - options.setTransitive(false); - options.setUseOrigin(true); - options.setDownload(false); - ResolveReport report = ivy.getResolveEngine().resolve(module, options, false); - - List dependencies = report.getDependencies(); - assertNotNull(dependencies); - assertEquals(1, dependencies.size()); - IvyNode dependency = (IvyNode) dependencies.get(0); - assertEquals("1.1", dependency.getResolvedId().getRevision()); - } - - // ////////////////////////////////////////////////////////// - // helper methods to ease the tests - // ////////////////////////////////////////////////////////// - - private void assertContainsArtifact(String org, String module, String rev, String artName, - String type, String ext, ConfigurationResolveReport conf) { - Artifact art = getArtifact(org, module, rev, artName, type, ext); - if (!containsArtifact(art, conf.getDownloadedArtifactsReports())) { - fail("artifact " + art + " should be part of " + conf.getConfiguration() + " from " - + conf.getModuleDescriptor().getModuleRevisionId()); - } - } - - private void assertDoesntContainArtifact(String org, String module, String rev, String artName, - String type, String ext, ConfigurationResolveReport conf) { - Artifact art = getArtifact(org, module, rev, artName, type, ext); - if (containsArtifact(art, conf.getDownloadedArtifactsReports())) { - fail("artifact " + art + " should NOT be part of " + conf.getConfiguration() + " from " - + conf.getModuleDescriptor().getModuleRevisionId()); - } - } - - private Artifact getArtifact(String org, String module, String rev, String artName, - String type, String ext) { - return new DefaultArtifact(ModuleRevisionId.newInstance(org, module, rev), new Date(), - artName, type, ext); - } - - private boolean containsArtifact(Artifact art, ArtifactDownloadReport[] adr) { - for (int i = 0; i < adr.length; i++) { - Artifact artifact = adr[i].getArtifact(); - if (artifact.getModuleRevisionId().equals(art.getModuleRevisionId()) - && artifact.getName().equals(art.getName()) - && artifact.getType().equals(art.getType()) - && artifact.getExt().equals(art.getExt())) { - return true; - } - } - return false; - } - - private File getArchiveFileInCache(String organisation, String module, String revision, - String artifact, String type, String ext) { - return TestHelper.getArchiveFileInCache(_cacheManager, organisation, module, revision, - artifact, type, ext); - } - - private ResolveOptions getResolveOptions(String[] confs) { - return getResolveOptions(_ivy.getSettings(), confs); - } - - private ResolveOptions getResolveOptions(IvySettings settings, String[] confs) { - return new ResolveOptions().setConfs(confs).setCache( - CacheManager.getInstance(settings, _cache)); - } - -} +/* + * 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.core.resolve; + +import java.io.File; +import java.util.Arrays; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.TestHelper; +import org.apache.ivy.core.cache.ArtifactOrigin; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.ConfigurationResolveReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.circular.CircularDependencyException; +import org.apache.ivy.plugins.circular.ErrorCircularDependencyStrategy; +import org.apache.ivy.plugins.circular.IgnoreCircularDependencyStrategy; +import org.apache.ivy.plugins.circular.WarnCircularDependencyStrategy; +import org.apache.ivy.plugins.resolver.BasicResolver; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.plugins.resolver.DualResolver; +import org.apache.ivy.plugins.resolver.FileSystemResolver; +import org.apache.ivy.util.FileUtil; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * + */ +public class ResolveTest extends TestCase { + private Ivy _ivy; + + private IvySettings _settings; + + private File _cache; + + private CacheManager _cacheManager; + + public ResolveTest() { + } + + protected void setUp() throws Exception { + _ivy = Ivy.newInstance(); + _ivy.configure(new File("test/repositories/ivysettings.xml")); + _settings = _ivy.getSettings(); + _cache = new File("build/cache"); + _cacheManager = _ivy.getCacheManager(_cache); + createCache(); + } + + private void createCache() { + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + public void testResolveWithRetainingArtifactName() throws Exception { + _settings.setCacheArtifactPattern(_ivy.substitute("[module]/[originalname].[ext]")); + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod15.2/ivy-1.1.xml") + .toURL(), getResolveOptions(new String[] {"default"})); + assertNotNull(report); + + ArtifactDownloadReport[] dReports = report.getConfigurationReport("default") + .getDownloadReports(ModuleRevisionId.newInstance("org15", "mod15.1", "1.1")); + assertNotNull(dReports); + assertEquals("number of downloaded artifacts not correct", 1, dReports.length); + + Artifact artifact = dReports[0].getArtifact(); + assertNotNull(artifact); + + String cachePath = _cacheManager.getArchivePathInCache(artifact); + assertTrue("artifact name has not been retained: " + cachePath, cachePath + .endsWith("library.jar")); + + dReports = report.getConfigurationReport("default").getDownloadReports( + ModuleRevisionId.newInstance("org14", "mod14.1", "1.1")); + assertNotNull(dReports); + assertEquals("number of downloaded artifacts not correct", 1, dReports.length); + + artifact = dReports[0].getArtifact(); + assertNotNull(artifact); + + cachePath = _cacheManager.getArchivePathInCache(artifact); + assertTrue("artifact name has not been retained: " + cachePath, cachePath + .endsWith("mod14.1-1.1.jar")); + } + + public void testArtifactOrigin() throws Exception { + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertNotNull(report); + + ArtifactDownloadReport[] dReports = report.getConfigurationReport("default") + .getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); + assertNotNull(dReports); + assertEquals("number of downloaded artifacts not correct", 1, dReports.length); + + Artifact artifact = dReports[0].getArtifact(); + assertNotNull(artifact); + + String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar") + .getAbsolutePath(); + + // verify the origin in the report + ArtifactOrigin reportOrigin = dReports[0].getArtifactOrigin(); + assertNotNull(reportOrigin); + assertEquals("isLocal for artifact not correct", true, reportOrigin.isLocal()); + assertEquals("location for artifact not correct", expectedLocation, reportOrigin + .getLocation()); + + // verify the saved origin on disk + ArtifactOrigin ivyOrigin = _cacheManager.getSavedArtifactOrigin(artifact); + assertNotNull(ivyOrigin); + assertEquals("isLocal for artifact not correct", true, ivyOrigin.isLocal()); + assertEquals("location for artifact not correct", expectedLocation, ivyOrigin.getLocation()); + + // now resolve the same artifact again and verify the origin of the (not-downloaded) + // artifact + report = _ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertNotNull(report); + + dReports = report.getConfigurationReport("default").getDownloadReports( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); + assertNotNull(dReports); + assertEquals("number of downloaded artifacts not correct", 1, dReports.length); + assertEquals("download status not correct", DownloadStatus.NO, dReports[0] + .getDownloadStatus()); + reportOrigin = dReports[0].getArtifactOrigin(); + assertNotNull(reportOrigin); + assertEquals("isLocal for artifact not correct", true, reportOrigin.isLocal()); + assertEquals("location for artifact not correct", expectedLocation, reportOrigin + .getLocation()); + } + + public void testUseOrigin() throws Exception { + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions( + new String[] {"default"}).setUseOrigin(true)); + assertNotNull(report); + + ArtifactDownloadReport[] dReports = report.getConfigurationReport("default") + .getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); + assertNotNull(dReports); + assertEquals("number of downloaded artifacts not correct.", 1, dReports.length); + assertEquals( + "download status not correct: should not download the artifact in useOrigin mode.", + DownloadStatus.NO, dReports[0].getDownloadStatus()); + + Artifact artifact = dReports[0].getArtifact(); + assertNotNull(artifact); + + String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar") + .getAbsolutePath(); + + ArtifactOrigin origin = _cacheManager.getSavedArtifactOrigin(artifact); + File artInCache = new File(_cache, _cacheManager.getArchivePathInCache(artifact, origin)); + assertFalse("should not download artifact in useOrigin mode.", artInCache.exists()); + assertEquals("location for artifact not correct.", expectedLocation, _cacheManager + .getArchiveFileInCache(artifact).getAbsolutePath()); + } + + public void testResolveSimple() throws Exception { + // mod1.1 depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveBadStatus() throws Exception { + // mod1.4 depends on modfailure, modfailure has a bad status + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.4/ivys/ivy-1.1.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + assertTrue(report.hasError()); + } + + public void testResolveNoRevisionInPattern() throws Exception { + // module1 depends on latest version of module2, for which there is no revision in the + // pattern + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/norev/ivysettings.xml").toURL()); + ResolveReport report = ivy.resolve(new File("test/repositories/norev/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + assertFalse(report.hasError()); + } + + public void testResolveNoRevisionInDep() throws Exception { + // mod1.4 depends on mod1.6, in which the ivy file has no revision + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.4/ivys/ivy-1.2.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + assertTrue(report.hasError()); + } + + public void testResolveNoRevisionNowhere() throws Exception { + // test case for IVY-258 + // module1 depends on latest version of module2, which contains no revision in its ivy file, + // nor in the pattern + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-258/ivysettings.xml").toURL()); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-258/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + ((BasicResolver) ivy.getSettings().getResolver("myresolver")).setCheckconsistency(false); + report = ivy.resolve(new File("test/repositories/IVY-258/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + } + + public void testResolveWithConflictManagerPerModule() throws Exception { + // test case for IVY-448 + // all modules from myorg + // module1 + // -> module2-1.0 + // -> module3-2.0 + // module2 + // -> module3-1.0 + // settings use 'all' as default conflict manager, and latest-revision for modules from + // myorg + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-448/ivysettings.xml").toURL()); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-448/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + // rev 1.0 should have been evicted by latest-revision conflict manager + assertTrue(getArchiveFileInCache("myorg", "module3", "2.0", "module3", "jar", "jar") + .exists()); + assertFalse(getArchiveFileInCache("myorg", "module3", "1.0", "module3", "jar", "jar") + .exists()); + } + + public void testResolveRequiresIvyFile() throws Exception { + // mod1.1 depends on mod1.2, mod1.2 has no ivy file + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/ivysettings.xml")); + ((FileSystemResolver) ivy.getSettings().getResolver("1")).setAllownomd(false); + ResolveReport report = ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + assertTrue(report.hasError()); + } + + public void testResolveOtherConfiguration() throws Exception { + ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-other.xml"), + getResolveOptions(new String[] {"test"})); + + assertNotNull(report); + assertFalse(report.hasError()); + + assertEquals("Number of artifacts not correct", 1, report.getConfigurationReport("test") + .getArtifactsNumber()); + } + + public void testResolveWithSlashes() throws Exception { + // test case for IVY-198 + // module depends on mod1.2 + ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-198.xml"), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg/mydep", "system/module", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("yourorg/yourdep", "yoursys/yourmod", "1.0")).exists()); + assertTrue(getArchiveFileInCache("yourorg/yourdep", "yoursys/yourmod", "1.0", "yourmod", + "jar", "jar").exists()); + } + + public void testFromCache() throws Exception { + // mod1.1 depends on mod1.2 + + // we first do a simple resolve so that module is in cache + _ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + // we now use a badly configured ivy, so that it can't find module in repository + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/bugIVY-56/ivysettings.xml")); + + ResolveReport report = ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy + .getSettings(), new String[] {"*"})); + assertFalse(report.hasError()); + + ModuleDescriptor md = report.getModuleDescriptor(); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testFromCache2() throws Exception { + // mod1.1 depends on mod1.2 + + // configuration + Ivy ivy = Ivy.newInstance(); + DualResolver resolver = new DualResolver(); + resolver.setName("dual"); + FileSystemResolver r = new FileSystemResolver(); + r.setName("1"); + r.addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]"); + resolver.add(r); + r = new FileSystemResolver(); + r.setName("2"); + r.addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]"); + resolver.add(r); + ivy.getSettings().addResolver(resolver); + ivy.getSettings().setDefaultResolver("dual"); + + // set up repository + File art = new File("build/testCache2/mod1.2-2.0.jar"); + FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), art, null); + + // we first do a simple resolve so that module is in cache + ResolveReport report = ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + // now we clean the repository to simulate repo not available (network pb for instance) + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/testCache2")); + del.execute(); + + // now do a new resolve: it should use cached data + report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + ModuleDescriptor md = report.getModuleDescriptor(); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testFromCacheOnly() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/bugIVY-56/ivysettings.xml")); + + // ResolveReport report = ivy.resolve(new + // File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + // getResolveOptions(new String[] {"*"})); + // // should have an error, the conf is bad and the dependency should not be found + // assertTrue(report.hasError()); + + // put necessary stuff in cache, and it should now be ok + File ivyfile = ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); + File art = TestHelper.getArchiveFileInCache(ivy, _cache, "org1", "mod1.2", "2.0", "mod1.2", + "jar", "jar"); + FileUtil.copy(ResolveTest.class.getResource("ivy-mod1.2.xml"), ivyfile, null); + FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), art, null); + + ResolveReport report = ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy + .getSettings(), new String[] {"*"})); + assertFalse(report.hasError()); + } + + public void testChangeCacheLayout() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/ivysettings.xml")); + ivy.getSettings().setCacheIvyPattern("[module]/ivy.xml"); + ivy.getSettings().setCacheArtifactPattern("[artifact].[ext]"); + + // mod1.1 depends on mod1.2 + ResolveReport report = ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy + .getSettings(), new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(new File(_cache, "mod1.2/ivy.xml").exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org1", "mod1.2", "2.0", "mod1.2", + "jar", "jar").exists()); + assertTrue(new File(_cache, "mod1.2.jar").exists()); + } + + public void testResolveExtends() throws Exception { + // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(), + getResolveOptions(new String[] {"extension"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies from default + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveExtended() throws Exception { + // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies from default + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveExtendedAndExtends() throws Exception { + // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(), + getResolveOptions(new String[] {"default", "extension"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(1, crr.getArtifactsNumber()); + crr = report.getConfigurationReport("extension"); + assertNotNull(crr); + assertEquals(1, crr.getArtifactsNumber()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveMultipleExtends() throws Exception { + // mod6.2 has two confs default and extension + // mod6.2 depends on mod6.1 in conf (default->extension) + // conf extension extends default + // mod6.1 has two confs default and extension + // mod6.1 depends on mod1.2 2.0 in conf (default->default) + // conf extension extends default + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml").toURL(), + getResolveOptions(new String[] {"default", "extension"})); + assertNotNull(report); + assertFalse(report.hasError()); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(2, crr.getArtifactsNumber()); + crr = report.getConfigurationReport("extension"); + assertNotNull(crr); + assertEquals(2, crr.getArtifactsNumber()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org6", "mod6.1", "0.4")).exists()); + assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.4", "mod6.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveMultipleExtendsAndConfs() throws Exception { + // Test case for IVY-240 + // + // mod6.3 1.1 has four confs libraries, run (extends libraries), compile (extends run) and + // test (extends libraries) + // mod6.3 depends on mod6.2 2.0 in conf (run->default) + // mod6.3 depends on mod6.1 2.+ in conf (test->default) + // mod6.2 2.0 depends on mod6.1 2.0 in conf (default->standalone) + // mod6.1 2.0 has two confs default and standalone + // mod6.1 2.0 depends on mod1.2 2.2 in conf (default->default) + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.1.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + assertFalse(report.hasError()); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ConfigurationResolveReport crr = report.getConfigurationReport("libraries"); + assertEquals(0, crr.getArtifactsNumber()); + + crr = report.getConfigurationReport("run"); + assertEquals(2, crr.getArtifactsNumber()); + assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2", "jar", "jar", crr); + assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr); + + crr = report.getConfigurationReport("compile"); + assertEquals(2, crr.getArtifactsNumber()); + assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2", "jar", "jar", crr); + assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr); + + crr = report.getConfigurationReport("test"); + assertEquals(2, crr.getArtifactsNumber()); + assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr); + assertContainsArtifact("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar", crr); + } + + public void testResolveMultipleConfsWithLatest() throws Exception { + // Test case for IVY-188 + // + // mod6.2 has two confs compile and run + // depends on mod6.1 in conf (compile->default) + // depends on mod1.2 latest (which is 2.2) in conf (run->default) + // mod6.1 + // depends on mod1.2 2.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml").toURL(), + getResolveOptions(new String[] {"compile", "run"})); + assertNotNull(report); + assertFalse(report.hasError()); + + ConfigurationResolveReport crr = report.getConfigurationReport("compile"); + assertNotNull(crr); + assertEquals(2, crr.getArtifactsNumber()); + crr = report.getConfigurationReport("run"); + assertNotNull(crr); + assertEquals(1, crr.getArtifactsNumber()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveMultipleConfsWithConflicts() throws Exception { + // Test case for IVY-173 + // + // mod6.2 has two confs compile and run + // depends on mod1.2 2.1 in conf (compile->default) + // depends on mod1.1 1.0 in conf (*->default) + // depends on mod6.1 in conf (*->default) + // mod6.1 + // depends on mod1.2 2.1 + // mod1.1 + // depends on mod1.2 2.0 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml").toURL(), + getResolveOptions(new String[] {"compile", "run"})); + assertNotNull(report); + assertFalse(report.hasError()); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.5"); + assertEquals(mrid, md.getModuleRevisionId()); + ConfigurationResolveReport crr = report.getConfigurationReport("compile"); + assertNotNull(crr); + assertEquals(3, crr.getArtifactsNumber()); + crr = report.getConfigurationReport("run"); + assertNotNull(crr); + assertEquals(3, crr.getArtifactsNumber()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org6", "mod6.1", "0.5")).exists()); + assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.5", "mod6.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveMultipleExtends2() throws Exception { + // same as before, except that mod6.2 depends on mod1.2 2.1 extension->default + // so mod1.2 2.0 should be evicted in conf extension + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml").toURL(), + getResolveOptions(new String[] {"default", "extension"})); + assertNotNull(report); + assertFalse(report.hasError()); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.4"); + assertEquals(mrid, md.getModuleRevisionId()); + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(2, crr.getArtifactsNumber()); + IvyNode node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); + assertNotNull(node); + assertFalse(node.isEvicted("default")); + crr = report.getConfigurationReport("extension"); + assertNotNull(crr); + assertEquals(2, crr.getArtifactsNumber()); + node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")); + assertNotNull(node); + assertTrue(node.isEvicted("extension")); + node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")); + assertNotNull(node); + assertFalse(node.isEvicted("extension")); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org6", "mod6.1", "0.4")).exists()); + assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.4", "mod6.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveSeveralDefaultWithArtifacts() throws Exception { + // test case for IVY-261 + // mod1.6 depends on + // mod1.4, which depends on mod1.3 and selects one of its artifacts + // mod1.3 and selects two of its artifacts + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + // dependencies + assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") + .exists()); + } + + public void testResolveSeveralDefaultWithArtifactsAndConfs() throws Exception { + // test case for IVY-283 + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-283/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-283/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + // dependencies + ConfigurationResolveReport crr = report.getConfigurationReport("build"); + assertNotNull(crr); + assertEquals(3, + crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "C", "1.0")).length); + + assertTrue(getArchiveFileInCache("medicel", "C", "1.0", "lib_c_a", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("medicel", "C", "1.0", "lib_c_b", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("medicel", "C", "1.0", "lib_c_d", "jar", "jar").exists()); + } + + public void testResolveSeveralDefaultWithArtifactsAndConfs2() throws Exception { + // second test case for IVY-283 + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-283/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-283/ivy-d.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + // dependencies + ConfigurationResolveReport crr = report.getConfigurationReport("build"); + assertNotNull(crr); + assertEquals(9, crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "module_a", + "local")).length); + + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_a", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_b", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_c", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_d", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_e", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_f", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_g", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_h", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("medicel", "module_a", "local", "lib_a_i", "jar", "jar") + .exists()); + } + + public void testResolveDefaultWithArtifactsConf1() throws Exception { + // mod2.2 depends on mod1.3 and selects its artifacts + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURL(), + getResolveOptions(new String[] {"myconf1"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") + .exists()); + assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists()); + } + + public void testResolveDefaultWithArtifactsConf2() throws Exception { + // mod2.2 depends on mod1.3 and selects its artifacts + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURL(), + getResolveOptions(new String[] {"myconf2"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") + .exists()); + assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") + .exists()); + assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists()); + } + + public void testResolveDefaultWithArtifactsAndConfMapping() throws Exception { + // mod2.2 depends on mod1.3 and specify its artifacts and a conf mapping + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.1.xml").toURL(), + getResolveOptions(new String[] {"myconf1"})); + assertNotNull(report); + assertFalse(report.hasError()); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5.1"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar") + .exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar") + .exists()); + assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists()); + } + + public void testResolveWithIncludeArtifactsConf1() throws Exception { + // mod2.3 depends on mod2.1 and selects its artifacts in myconf1 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml").toURL(), + getResolveOptions(new String[] {"myconf1"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.4"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveWithIncludeArtifactsConf2() throws Exception { + // mod2.3 depends on mod2.1 and selects its artifacts in myconf1 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml").toURL(), + getResolveOptions(new String[] {"myconf2"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.4"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveWithIncludeArtifactsWithoutConf() throws Exception { + // mod2.3 depends on mod2.1 and selects its artifacts + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.5"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveWithExcludesArtifacts() throws Exception { + // mod2.3 depends on mod2.1 and selects its artifacts + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveWithExcludesArtifacts2() throws Exception { + // mod2.3 depends on mod2.1 and badly excludes artifacts with incorrect matcher + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.2"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveWithExcludesArtifacts3() throws Exception { + // mod2.3 depends on mod2.1 and excludes artifacts with exact matcher + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveWithExcludesArtifacts4() throws Exception { + // mod2.3 depends on mod2.1 and excludes artifacts with regexp matcher + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.4"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveWithExcludesArtifacts5() throws Exception { + // mod2.3 depends on mod2.1 and excludes artifacts with glob matcher + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.5"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists()); + } + + public void testResolveTransitiveDependencies() throws Exception { + // mod2.1 depends on mod1.1 which depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveTransitiveDisabled() throws Exception { + // mod2.1 depends on mod1.1 which depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml").toURL(), getResolveOptions( + new String[] {"*"}).setTransitive(false)); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testDependenciesOrder() throws Exception { + ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-225.xml"), + getResolveOptions(new String[] {"default"})); + + Set revisions = report.getConfigurationReport("default").getModuleRevisionIds(); + assertTrue("number of revisions is not correct", revisions.size() >= 3); + + // verify the first 3 modules against the ones in the ivy file + Iterator it = revisions.iterator(); + ModuleRevisionId revId1 = (ModuleRevisionId) it.next(); + assertEquals("mod1.2", revId1.getName()); + assertEquals("1.1", revId1.getRevision()); + + ModuleRevisionId revId2 = (ModuleRevisionId) it.next(); + assertEquals("mod3.2", revId2.getName()); + assertEquals("1.4", revId2.getRevision()); + + ModuleRevisionId revId3 = (ModuleRevisionId) it.next(); + assertEquals("mod5.1", revId3.getName()); + assertEquals("4.2", revId3.getRevision()); + } + + public void testDisableTransitivityPerConfiguration() throws Exception { + // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 + // compile conf is not transitive + + // first we resolve compile conf only + _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(), + getResolveOptions(new String[] {"compile"})); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // then we resolve runtime conf + _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(), + getResolveOptions(new String[] {"runtime"})); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // same as before, but resolve both confs in one call + ResolveReport r = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(), + getResolveOptions(new String[] {"runtime", "compile"})); + assertFalse(r.hasError()); + assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber()); + assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber()); + } + + public void testDisableTransitivityPerConfiguration2() throws Exception { + // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 + // compile conf is not transitive + // compile extends runtime + + // first we resolve compile conf only + _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(), + getResolveOptions(new String[] {"compile"})); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // then we resolve runtime conf + _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(), + getResolveOptions(new String[] {"runtime"})); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // same as before, but resolve both confs in one call + ResolveReport r = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(), + getResolveOptions(new String[] {"runtime", "compile"})); + assertFalse(r.hasError()); + assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber()); + assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber()); + } + + public void testDisableTransitivityPerConfiguration3() throws Exception { + // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 + // compile conf is not transitive + // runtime extends compile + + // first we resolve compile conf only + _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(), + getResolveOptions(new String[] {"compile"})); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // then we resolve runtime conf + _ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(), + getResolveOptions(new String[] {"runtime"})); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // same as before, but resolve both confs in one call + ResolveReport r = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(), + getResolveOptions(new String[] {"runtime", "compile"})); + assertFalse(r.hasError()); + assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber()); + assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber()); + } + + public void testDisableTransitivityPerConfiguration4() throws Exception { + // mod2.2 (A,B,compile) depends on mod 2.1 (A->runtime;B->compile) + // compile is not transitive and extends A and B + // + // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2 + // compile conf is not transitive and extends runtime + + ResolveReport r = _ivy.resolve(new File("test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertFalse(r.hasError()); + + // here we should get all three recursive dependencies + assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),})), r + .getConfigurationReport("A").getModuleRevisionIds()); + + // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1 + assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),})), r + .getConfigurationReport("B").getModuleRevisionIds()); + + // here we should get only mod2.1 cause compile is not transitive + assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] {ModuleRevisionId + .newInstance("org2", "mod2.1", "0.3.2"),})), r.getConfigurationReport("compile") + .getModuleRevisionIds()); + } + + public void testDisableTransitivityPerConfiguration5() throws Exception { + // mod2.2 (A,B,compile) depends on + // mod 2.1 (A->runtime;B->compile) + // mod1.1 (A->*) ]0.9.9,1.0] (which resolves to 1.0) + // compile is not transitive and extends A and B + // + // mod2.1 (compile, runtime) depends on mod1.1 1.0 which depends on mod1.2 2.0 + // compile conf is not transitive and extends runtime + + ResolveReport r = _ivy.resolve(new File("test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml") + .toURL(), getResolveOptions(new String[] {"A", "B", "compile"})); + assertFalse(r.hasError()); + + // here we should get all three recursive dependencies + assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),})), r + .getConfigurationReport("A").getModuleRevisionIds()); + + // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1 + assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),})), r + .getConfigurationReport("B").getModuleRevisionIds()); + + // here we should get only mod2.1 cause compile is not transitive + assertEquals(new HashSet(Arrays.asList(new ModuleRevisionId[] { + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"), + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),})), r + .getConfigurationReport("compile").getModuleRevisionIds()); + } + + public void testResolveDiamond() throws Exception { + // mod4.1 depends on + // - mod1.1 which depends on mod1.2 + // - mod3.1 which depends on mod1.2 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.0", "mod3.1", "jar", "jar").exists()); + } + + public void testResolveConflict() throws Exception { + // mod4.1 v 4.1 depends on + // - mod1.1 v 1.0 which depends on mod1.2 v 2.0 + // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.1.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.1"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(0, crr.getDownloadReports(ModuleRevisionId + .newInstance("org1", "mod1.2", "2.0")).length); + assertEquals(1, crr.getDownloadReports(ModuleRevisionId + .newInstance("org1", "mod1.2", "2.1")).length); + + File r = _cacheManager.getConfigurationResolveReportInCache(ResolveOptions + .getDefaultResolveId(md), "default"); + assertTrue(r.exists()); + final boolean[] found = new boolean[] {false}; + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + saxParser.parse(r, new DefaultHandler() { + public void startElement(String uri, String localName, String qName, + org.xml.sax.Attributes attributes) throws SAXException { + if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) { + found[0] = true; + } + } + }); + assertTrue(found[0]); // the report should contain the evicted revision + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists()); + + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveConflict2() throws Exception { + // mod4.1 v 4.14 depends on + // - mod1.1 v 1.0 which depends on mod1.2 v 2.0 + // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 + // - mod6.1 v 0.3 which depends on mod1.2 v 2.0 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.14.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + // dependencies + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(0, crr.getDownloadReports(ModuleRevisionId + .newInstance("org1", "mod1.2", "2.0")).length); + assertEquals(1, crr.getDownloadReports(ModuleRevisionId + .newInstance("org1", "mod1.2", "2.1")).length); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.14"); + File r = _cacheManager.getConfigurationResolveReportInCache(ResolveOptions + .getDefaultResolveId(mrid.getModuleId()), "default"); + assertTrue(r.exists()); + final boolean[] found = new boolean[] {false}; + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + saxParser.parse(r, new DefaultHandler() { + public void startElement(String uri, String localName, String qName, + org.xml.sax.Attributes attributes) throws SAXException { + if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) { + found[0] = true; + } + } + }); + assertTrue(found[0]); // the report should contain the evicted revision + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists()); + + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveConflict3() throws Exception { + // test case for IVY-264 + // a depends on x latest, y latest, z latest + // x and z depends on commons-lang 1.0.1 + // y depends on commons-lang 2.0 + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-264/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-264/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + // dependencies + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("myorg", + "commons-lang", "1.0.1")).length); + assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("myorg", + "commons-lang", "2.0")).length); + + assertFalse(getArchiveFileInCache("myorg", "commons-lang", "1.0.1", "commons-lang", "jar", + "jar").exists()); + + assertTrue(getArchiveFileInCache("myorg", "commons-lang", "2.0", "commons-lang", "jar", + "jar").exists()); + } + + public void testTransitiveEviction() throws Exception { + // mod7.3 depends on mod7.2 v1.0 and on mod7.1 v2.0 + // mod7.2 v1.0 depends on mod7.1 v1.0 (which then should be evicted) + // mod7.1 v1.0 depends on mod 1.2 v1.0 (which should be evicted by transitivity) + + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod7.3/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org7", "mod7.3", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org7", "mod7.2", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org7", "mod7.2", "1.0", "mod7.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org7", "mod7.1", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org7", "mod7.1", "2.0", "mod7.1", "jar", "jar").exists()); + + assertTrue(!getArchiveFileInCache("org7", "mod7.1", "1.0", "mod7.1", "jar", "jar").exists()); + + assertTrue(!getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testTransitiveEviction2() throws Exception { + // IVY-199 + // mod4.1 v 4.13 depends on + // - mod3.2 v 1.2.1 which depends on + // - mod3.1 v 1.0 which depends on mod1.2 v 2.0 + // - mod1.2 v 2.1 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.13.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveConflictInConf() throws Exception { + // conflicts in separate confs are not conflicts + + // mod2.1 conf A depends on mod1.1 which depends on mod1.2 2.0 + // mod2.1 conf B depends on mod1.2 2.1 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.4"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testEvictWithConf() throws Exception { + // bug 105 - test #1 + + // mod6.1 r1.0 depends on + // mod5.1 r4.2 conf A + // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B + // + // mod5.1 r4.2 conf B depends on mod1.2 r2.0 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // should have been evicted before download + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists()); + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + } + + public void testEvictWithConf2() throws Exception { + // same as preceding one but with inverse order, so that + // eviction is done after download + // bug 105 - test #2 + + // mod6.1 r1.1 depends on + // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B + // mod5.1 r4.2 conf A + // + // mod5.1 r4.2 conf B depends on mod1.2 r2.0 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.1.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.1"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // even late eviction should avoid artifact downloading + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + } + + public void testEvictWithConfInMultiConf() throws Exception { + // same as preceding ones but the conflict appears in several root confs + // bug 105 - test #3 + + // mod6.1 r1.2 conf A and conf B depends on + // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B + // mod5.1 r4.2 conf A + // + // mod5.1 r4.2 conf B depends on mod1.2 r2.0 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.2.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.2"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // all artifacts should be present in both confs + ConfigurationResolveReport crr = report.getConfigurationReport("A"); + assertNotNull(crr); + assertEquals(2, crr.getDownloadReports(ModuleRevisionId + .newInstance("org5", "mod5.1", "4.2")).length); + + crr = report.getConfigurationReport("B"); + assertNotNull(crr); + assertEquals(2, crr.getDownloadReports(ModuleRevisionId + .newInstance("org5", "mod5.1", "4.2")).length); + + // even late eviction should avoid artifact downloading + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + } + + public void testEvictWithConfInMultiConf2() throws Exception { + // same as preceding one but the conflict appears in a root conf and not in another + // which should keep the evicted + // bug 105 - test #4 + + // mod6.1 r1.3 conf A depends on + // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B + // + // mod6.1 r1.3 conf B depends on + // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B + // mod5.1 r4.2 conf A + // + // mod5.1 r4.2 conf B depends on mod1.2 r2.0 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.1/ivy-1.3.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + // 4.2 artifacts should be present in conf B only + ConfigurationResolveReport crr = report.getConfigurationReport("A"); + assertNotNull(crr); + assertEquals(0, crr.getDownloadReports(ModuleRevisionId + .newInstance("org5", "mod5.1", "4.2")).length); + + crr = report.getConfigurationReport("B"); + assertNotNull(crr); + assertEquals(2, crr.getDownloadReports(ModuleRevisionId + .newInstance("org5", "mod5.1", "4.2")).length); + } + + public void testResolveForce() throws Exception { + // mod4.1 v 4.2 depends on + // - mod1.2 v 2.0 and forces it + // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.2.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.2"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceAfterConflictSolved() throws Exception { + // IVY-193 + // mod4.1 v 4.9 depends on + // - mod3.2 v 1.1 which depends on mod1.2 v 2.0 + // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 + // - mod1.2 v 2.0 and forces it + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.9.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.9"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceAfterDependencyExist() throws Exception { + // IVY-193 + // mod4.1 v 4.10 depends on + // - mod3.1 v 1.0.1 which depends on mod1.2 v 2.0 and forces it + // - mod3.2 v 1.2 which depends on mod1.2 v 2.1 and on mod3.1 v1.0.1 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.10.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + + // dependencies + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceInDepOnly() throws Exception { + // IVY-193 + // mod4.1 v 4.11 depends on + // - mod1.2 v 2.0 + // - mod3.2 v 1.3 which depends on + // - mod3.1 v1.1 which depends on + // - mod1.2 v 2.1 + // - mod1.2 v 1.0 and forces it + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.11.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "1.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceInDepOnly2() throws Exception { + // IVY-193 + // mod4.1 v 4.12 depends on + // - mod3.1 v1.0 which depends on + // - mod1.2 v 2.0 + // - mod3.2 v 1.4 which depends on + // - mod1.2 v 2.0 and forces it + // - mod3.1 v1.1 which depends on + // - mod1.2 v 2.1 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.12.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceWithDynamicRevisions() throws Exception { + // mod4.1 v 4.5 depends on + // - mod1.2 v 1+ and forces it + // - mod3.1 v 1.2 which depends on mod1.2 v 2+ + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.5.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.5"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.2")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.2", "mod3.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceWithDynamicRevisionsAndSeveralConfs() throws Exception { + // mod4.1 v 4.6 (conf compile, test extends compile) depends on + // - mod1.2 v 1+ and forces it in conf compile + // - mod3.1 v 1.2 in conf test which depends on mod1.2 v 2+ + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.6.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.6"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.2")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.2", "mod3.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceWithDynamicRevisionsAndSeveralConfs2() throws Exception { + // mod4.1 v 4.7 (conf compile, test extends compile) depends on + // - mod1.2 v 1+ and forces it in conf compile + // - mod3.1 v 1.3 in conf test->runtime + // which defines confs compile, runtime extends compile + // which depends on mod1.2 v 2+ in conf compile->default + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.7.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.7"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.3")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.3", "mod3.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveForceWithDynamicRevisionsAndCyclicDependencies() throws Exception { + // IVY-182 + // * has no revision + // * declares conf compile, test extends compile, + // * depends on + // - mod1.2 v 1+ and forces it in conf compile + // - mod3.1 v 1+ in conf test->runtime excluding mod4.1 (to avoid cyclic dep failure) + // which defines confs compile, runtime extends compile + // which depends on mod1.2 v 2+ in conf compile->default + // which depends on mod4.1 v 4+ in conf compile->compile + ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-182.xml"), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleId mid = new ModuleId("test", "IVY-182"); + assertEquals(mid, md.getModuleRevisionId().getModuleId()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org3", "mod3.1", "1.4")).exists()); + assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.4", "mod3.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveContradictoryConflictResolution() throws Exception { + // mod10.1 v 1.0 depends on + // - mod1.2 v 2.0 and forces it + // - mod4.1 v 4.1 (which selects mod1.2 v 2.1 and evicts mod1.2 v 2.0) + // mod4.1 v 4.1 depends on + // - mod1.1 v 1.0 which depends on mod1.2 v 2.0 + // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod10.1/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org10", "mod10.1", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // conflicting dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveContradictoryConflictResolution2() throws Exception { + // BUG IVY-130 : only mod1.2 v2.0 should be resolved and not v2.1 (because of force) + // mod10.1 v 1.1 depends on + // - mod1.2 v 2.0 and forces it + // - mod4.1 v 4.3 + // mod4.1 v 4.3 depends on + // - mod1.2 v 2.1 + // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 + _ivy.resolve(new File("test/repositories/2/mod10.1/ivy-1.1.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + // conflicting dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveContradictoryConflictResolution3() throws Exception { + // mod 1.2 v2.0 should be selected (despite conflict manager in 4.1, because of force in + // 10.1) + // mod10.1 v 1.3 depends on + // - mod1.2 v 2.0 and forces it + // - mod4.1 v 4.4 + // mod4.1 v 4.4 depends on + // - mod1.2 v 2.0 but selects mod1.2 v 2.1 + // - mod3.1 v 1.1 which depends on mod1.2 v 2.1 + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod10.1/ivy-1.3.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + IvyNode[] evicted = report.getConfigurationReport("default").getEvictedNodes(); + assertEquals(1, evicted.length); + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"), evicted[0] + .getResolvedId()); + } + + public void testExtends() throws Exception { + // mod 5.2 depends on mod5.1 conf B + // mod5.1 conf B publishes art51B + // mod5.1 conf B extends conf A + // mod5.1 conf A publishes art51A + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod5.2/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5", "mod5.2", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + } + + public void testMultiConfs() throws Exception { + // mod 5.2 depends on mod5.1 conf B in its conf B and conf A in its conf A + // mod5.1 conf B publishes art51B + // mod5.1 conf A publishes art51A + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod5.2/ivy-2.0.xml") + .toURL(), getResolveOptions(new String[] {"B", "A"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5", "mod5.2", "2.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + ModuleRevisionId depId = ModuleRevisionId.newInstance("org5", "mod5.1", "4.1"); + + ConfigurationResolveReport crr = report.getConfigurationReport("A"); + assertNotNull(crr); + assertEquals(1, crr.getDownloadReports(depId).length); + + File r = new File(_cache, ResolveOptions.getDefaultResolveId(mrid.getModuleId()) + "-A.xml"); + assertTrue(r.exists()); + final boolean[] found = new boolean[] {false}; + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + saxParser.parse(r, new DefaultHandler() { + public void startElement(String uri, String localName, String qName, + org.xml.sax.Attributes attributes) throws SAXException { + if ("artifact".equals(qName) && "art51B".equals(attributes.getValue("name"))) { + found[0] = true; + } + } + }); + assertFalse(found[0]); + + assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists()); + } + + public void testThisConfiguration() throws Exception { + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod14.4/ivy-1.1.xml") + .toURL(), getResolveOptions(new String[] {"compile"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org14", "mod14.4", "1.1"); + assertEquals(mrid, md.getModuleRevisionId()); + ConfigurationResolveReport crr = report.getConfigurationReport("compile"); + assertNotNull(crr); + assertEquals(4, crr.getArtifactsNumber()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org14", "mod14.2", "1.1")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org14", "mod14.1", "1.1")).exists()); + assertTrue(!_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org8", "mod8.3", "1.0")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org8", "mod8.1", "1.0")).exists()); + + cleanCache(); + createCache(); + report = _ivy.resolve(new File("test/repositories/2/mod14.4/ivy-1.1.xml").toURL(), + getResolveOptions(new String[] {"standalone"})); + crr = report.getConfigurationReport("standalone"); + assertNotNull(crr); + assertEquals(7, crr.getArtifactsNumber()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org14", "mod14.1", "1.1")).exists()); + assertTrue(!_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org14", "mod14.2", "1.1")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org8", "mod8.3", "1.0")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org8", "mod8.1", "1.0")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org8", "mod8.4", "1.1")).exists()); + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org8", "mod8.2", "1.1")).exists()); + } + + public void testLatest() throws Exception { + // mod1.4 depends on latest mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.1"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + ModuleRevisionId depId = ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"); + + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(1, crr.getDownloadReports(depId).length); + + File r = _cacheManager.getConfigurationResolveReportInCache(ResolveOptions + .getDefaultResolveId(mrid.getModuleId()), "default"); + assertTrue(r.exists()); + final boolean[] found = new boolean[] {false}; + SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); + saxParser.parse(r, new DefaultHandler() { + public void startElement(String uri, String localName, String qName, + org.xml.sax.Attributes attributes) throws SAXException { + if ("artifact".equals(qName) && "mod1.2".equals(attributes.getValue("name"))) { + found[0] = true; + } + } + }); + assertTrue(found[0]); + + assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testLatestMultiple() throws Exception { + // mod1.5 depends on + // latest mod1.4, which depends on mod1.2 2.2 + // latest mod1.2 (which is 2.2) + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertFalse(report.hasError()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.4", "2.0")).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); + } + + public void testLatestWhenReleased() throws Exception { + // The test verify that latest.integration dependencies can be resolved with released + // version also. + ResolveReport report = _ivy.resolve( + ResolveTest.class.getResource("ivy-latestreleased.xml"), + getResolveOptions(new String[] {"default"})); + assertFalse(report.hasError()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod_released", "1.1")).exists()); + } + + public void testVersionRange1() throws Exception { + // mod 1.4 depends on mod1.2 [1.0,2.0[ + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertFalse(report.hasError()); + + // dependencies + ModuleRevisionId depId = ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"); + + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(1, crr.getDownloadReports(depId).length); + + assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); + } + + public void testVersionRange2() throws Exception { + // mod 1.4 depends on mod1.2 [1.5,2.0[ + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File( + "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertTrue(report.hasError()); + } + + public void testLatestMilestone() throws Exception { + // mod9.2 depends on latest.milestone of mod6.4 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertFalse(report.hasError()); + + // dependencies + ModuleRevisionId depId = ModuleRevisionId.newInstance("org6", "mod6.4", "3"); + + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(1, crr.getDownloadReports(depId).length); + + assertTrue(_cacheManager.getIvyFileInCache(depId).exists()); + } + + public void testLatestMilestone2() throws Exception { + // mod9.2 depends on latest.milestone of mod6.2, but there is no milestone + // test case for IVY-318 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml").toURL(), + getResolveOptions(new String[] {"default"})); + // we should have an error since there is no milestone version, it should be considered as a + // non resolved dependency + assertTrue(report.hasError()); + + // dependencies + ConfigurationResolveReport crr = report.getConfigurationReport("default"); + assertNotNull(crr); + assertEquals(0, crr.getArtifactsNumber()); + } + + public void testIVY56() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/bugIVY-56/ivysettings.xml")); + + ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-56.xml"), + getResolveOptions(new String[] {"default"})); + assertNotNull(report); + } + + public void testIVY214() throws Exception { + ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-214.xml"), + getResolveOptions(new String[] {"compile"})); + + assertNotNull(report); + assertFalse(report.hasError()); + + assertEquals("Number of artifacts not correct", 1, report.getConfigurationReport("compile") + .getArtifactsNumber()); + } + + public void testIVY218() throws Exception { + ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-218.xml"), + getResolveOptions(new String[] {"test"})); + + assertNotNull(report); + assertFalse(report.hasError()); + + assertEquals("Number of artifacts not correct", 3, report.getConfigurationReport("test") + .getArtifactsNumber()); + } + + public void testCircular() throws Exception { + // mod6.3 depends on mod6.2, which itself depends on mod6.3 + + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"default"})); + assertFalse(report.hasError()); + + _settings.setCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance()); + report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertFalse(report.hasError()); + + _settings.setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance()); + report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertFalse(report.hasError()); + + _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); + try { + _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"default"})); + fail("no exception with circular dependency strategy set to error"); + } catch (CircularDependencyException ex) { + assertEquals( + "[ org6 | mod6.3 | 1.0 ]->[ org6 | mod6.2 | 1.0 ]->[ org6 | mod6.3 | latest.integration ]", + ex.getMessage()); + } + } + + public void testCircular2() throws Exception { + // mod 9.1 (no revision) depends on mod9.2, which depends on mod9.1 2.+ + + ResolveReport report = _ivy.resolve(new File("test/repositories/circular/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); + try { + _ivy.resolve(new File("test/repositories/circular/ivy.xml").toURL(), + getResolveOptions(new String[] {"*"})); + fail("no exception with circular dependency strategy set to error"); + } catch (CircularDependencyException ex) { + // ok + assertEquals( + "[ org8 | mod8.5 | NONE ]->[ org8 | mod8.6 | 2.+ ]->[ org8 | mod8.5 | 2.+ ]", ex + .getMessage()); + } + } + + public void testCircular3() throws Exception { + // test case for IVY-400 + // mod6.3 depends on mod6.2, which itself depends on mod6.3, + // in both configuration default and test + + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml") + .toURL(), getResolveOptions(new String[] {"default", "test"})); + assertFalse(report.hasError()); + // we should have mod 6.2 artifact in both configurations + assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber()); + assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber()); + + _settings.setCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance()); + report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml").toURL(), + getResolveOptions(new String[] {"default", "test"})); + assertFalse(report.hasError()); + assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber()); + assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber()); + + _settings.setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance()); + report = _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml").toURL(), + getResolveOptions(new String[] {"default", "test"})); + assertFalse(report.hasError()); + assertEquals(1, report.getConfigurationReport("default").getArtifactsNumber()); + assertEquals(1, report.getConfigurationReport("test").getArtifactsNumber()); + + _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); + try { + _ivy.resolve(new File("test/repositories/2/mod6.3/ivy-1.2.xml").toURL(), + getResolveOptions(new String[] {"default", "test"})); + fail("no exception with circular dependency strategy set to error"); + } catch (CircularDependencyException ex) { + assertEquals( + "[ org6 | mod6.3 | 1.2 ]->[ org6 | mod6.2 | 1.1 ]->[ org6 | mod6.3 | 1.2 ]", ex + .getMessage()); + } + } + + public void testRegularCircular() throws Exception { + // mod11.1 depends on mod11.2 but excludes itself + // mod11.2 depends on mod11.1 + _settings.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance()); + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod11.1/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"test"})); + + assertNotNull(report); + assertFalse(report.hasError()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org11", "mod11.2", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org11", "mod11.2", "1.0", "mod11.2", "jar", "jar") + .exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org11", "mod11.1", "1.0")).exists()); + assertFalse(getArchiveFileInCache("org11", "mod11.1", "1.0", "mod11.1", "jar", "jar") + .exists()); + } + + public void testResolveDualChain() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(ResolveTest.class.getResource("dualchainresolverconf.xml")); + + DependencyResolver resolver = ivy.getSettings().getResolver("default"); + assertNotNull(resolver); + assertTrue(resolver instanceof DualResolver); + + // first without cache + ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), + getResolveOptions(new String[] {"default"})); + + assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml").exists()); + assertTrue(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists()); + assertTrue(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists()); + + // second with cache for ivy file only + new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").delete(); + new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").delete(); + assertFalse(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists()); + assertFalse(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists()); + ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), + getResolveOptions(new String[] {"default"})); + + assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml").exists()); + assertTrue(new File("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists()); + assertTrue(new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists()); + } + + public void testBug148() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/bug148/ivysettings.xml")); + + ivy.resolve(ResolveTest.class.getResource("ivy-148.xml"), + getResolveOptions(new String[] {"*"})); + + assertTrue(new File("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml").exists()); + assertTrue(new File("build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar").exists()); + assertTrue(new File("build/cache/idautomation/barcode/ivy-4.10.xml").exists()); + assertTrue(new File("build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar") + .exists()); + } + + public void testBug148b() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/bug148/ivysettings.xml")); + + ivy.resolve(ResolveTest.class.getResource("ivy-148b.xml"), + getResolveOptions(new String[] {"*"})); + + assertTrue(new File("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml").exists()); + assertTrue(new File("build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar").exists()); + assertTrue(new File("build/cache/idautomation/barcode/ivy-4.10.xml").exists()); + assertTrue(new File("build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar") + .exists()); + } + + public void testBadFiles() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/badfile/ivysettings.xml")); + + try { + ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badorg.xml").toURL(), + getResolveOptions(new String[] {"*"})); + fail("bad org should have raised an exception !"); + } catch (Exception ex) { + // OK, it raised an exception + } + try { + ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badmodule.xml").toURL(), + getResolveOptions(new String[] {"*"})); + fail("bad module should have raised an exception !"); + } catch (Exception ex) { + // OK, it raised an exception + } + try { + ivy.resolve(new File("test/repositories/badfile/ivys/ivy-badrevision.xml").toURL(), + getResolveOptions(new String[] {"*"})); + fail("bad revision should have raised an exception !"); + } catch (Exception ex) { + // OK, it raised an exception + } + } + + public void testTransitiveSetting() throws Exception { + // mod2.4 depends on mod1.1 with transitive set to false + // mod1.1 depends on mod1.2, which should not be resolved because of the transitive setting + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.4", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + + assertTrue(!_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(!getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolverDirectlyUsingCache() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(ResolveTest.class.getResource("badcacheconf.xml")); + File depIvyFileInCache = ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")); + FileUtil.copy(File.createTempFile("test", "xml"), depIvyFileInCache, null); // creates a + // fake + // dependency + // file in cache + ResolveReport report = ivy.resolve(new File( + "test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.4", "0.3"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(depIvyFileInCache.exists()); + assertTrue(!TestHelper.getArchiveFileInCache(ivy, _cache, "org1", "mod1.1", "1.0", + "mod1.1", "jar", "jar").exists()); + } + + public void testVisibility1() throws Exception { + _ivy.resolve(new File("test/repositories/2/mod8.2/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0", "a-private", "txt", "txt") + .exists()); + } + + public void testVisibility2() throws Exception { + _ivy.resolve(new File("test/repositories/2/mod8.3/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"private"})); + + assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0", "a-private", "txt", "txt") + .exists()); + assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.0", "a", "txt", "txt").exists()); + } + + public void testVisibility3() throws Exception { + _ivy.resolve(new File("test/repositories/2/mod8.4/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0", "a-private", "txt", "txt") + .exists()); + assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.0", "a", "txt", "txt").exists()); + } + + public void testVisibility4() throws Exception { + _ivy.resolve(new File("test/repositories/2/mod8.4/ivy-1.1.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.1", "a-private", "txt", "txt") + .exists()); + assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.1", "a", "txt", "txt").exists()); + } + + // ///////////////////////////////////////////////////////// + // here comes a series of test provided by Chris Rudd + // about configuration mapping and eviction + // ///////////////////////////////////////////////////////// + + public void testConfigurationMapping1() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/1/ivy.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + ConfigurationResolveReport conf = report.getConfigurationReport("default"); + + assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); + assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); + assertContainsArtifact("test", "b", "1.0.2", "b", "txt", "txt", conf); + assertDoesntContainArtifact("test", "b", "1.0.2", "b-bt", "txt", "txt", conf); + assertContainsArtifact("test", "c", "1.0.2", "c", "txt", "txt", conf); + assertDoesntContainArtifact("test", "c", "1.0.2", "c-bt", "txt", "txt", conf); + } + + public void testConfigurationMapping2() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/2/ivy.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + ConfigurationResolveReport conf = report.getConfigurationReport("default"); + + assertContainsArtifact("test", "a", "1.0.1", "a", "txt", "txt", conf); + assertDoesntContainArtifact("test", "a", "1.0.1", "a-bt", "txt", "txt", conf); + assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); + assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); + assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); + assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); + } + + public void testConfigurationMapping3() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/3/ivy.xml") + .toURL(), getResolveOptions(new String[] {"buildtime"})); + + ConfigurationResolveReport conf = report.getConfigurationReport("buildtime"); + + assertContainsArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); + assertDoesntContainArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); + assertContainsArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); + assertDoesntContainArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); + assertContainsArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); + assertDoesntContainArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); + } + + public void testConfigurationMapping4() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/4/ivy.xml") + .toURL(), getResolveOptions(new String[] {"default"})); + + ConfigurationResolveReport conf = report.getConfigurationReport("default"); + + assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); + assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); + assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); + assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); + assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); + assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); + } + + public void testConfigurationMapping5() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/5/ivy.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + ConfigurationResolveReport conf = report.getConfigurationReport("default"); + + assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); + assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); + assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); + assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); + assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); + assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); + } + + public void testConfigurationMapping6() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/6/ivy.xml") + .toURL(), getResolveOptions(new String[] {"default", "buildtime"})); + + ConfigurationResolveReport conf = report.getConfigurationReport("default"); + + assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); + assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); + assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); + assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); + assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); + assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); + } + + public void testConfigurationMapping7() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/IVY-84/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/IVY-84/tests/7/ivy.xml") + .toURL(), getResolveOptions(new String[] {"buildtime", "default"})); + + ConfigurationResolveReport conf = report.getConfigurationReport("default"); + + assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf); + assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf); + assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf); + assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf); + assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf); + assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf); + } + + public void testIVY97() throws Exception { + // mod9.2 depends on mod9.1 and mod1.2 + // mod9.1 depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org9", "mod9.2", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org9", "mod9.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org9", "mod9.1", "1.0", "mod9.1", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveTransitiveExcludesSimple() throws Exception { + // mod2.5 depends on mod2.3 and excludes one artifact from mod2.1 + // mod2.3 depends on mod2.1 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.5", "0.6"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(_cacheManager.getResolvedIvyFileInCache(mrid).exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.3", "0.7")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.3", "0.7", "mod2.3", "jar", "jar").exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + } + + public void testResolveTransitiveExcludesDiamond1() throws Exception { + // mod2.6 depends on mod2.3 and mod2.5 + // mod2.3 depends on mod2.1 and excludes art21B + // mod2.5 depends on mod2.1 and excludes art21A + _ivy.resolve(new File("test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + } + + public void testResolveTransitiveExcludesDiamond2() throws Exception { + // mod2.6 depends on mod2.3 and mod2.5 + // mod2.3 depends on mod2.1 and excludes art21B + // mod2.5 depends on mod2.1 and excludes art21B + _ivy.resolve(new File("test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + } + + public void testResolveTransitiveExcludesDiamond3() throws Exception { + // mod2.6 depends on mod2.3 and mod2.5 and on mod2.1 for which it excludes art21A + // mod2.3 depends on mod2.1 and excludes art21B + // mod2.5 depends on mod2.1 and excludes art21B + _ivy.resolve(new File("test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + } + + public void testResolveTransitiveExcludes2() throws Exception { + // mod2.6 depends on mod2.3 for which it excludes art21A + // mod2.3 depends on mod2.1 and excludes art21B + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml").toURL(), + getResolveOptions(new String[] {"*"})); + ModuleDescriptor md = report.getModuleDescriptor(); + assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.9"), md + .getModuleRevisionId()); + + assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists()); + } + + public void testResolveExcludesModule() throws Exception { + // mod2.6 depends on mod2.1 and excludes mod1.1 + // mod2.1 depends on mod1.1 which depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml").toURL(), + getResolveOptions(new String[] {"*"})); + ModuleDescriptor md = report.getModuleDescriptor(); + assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.10"), md + .getModuleRevisionId()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveExcludesModuleWide() throws Exception { + // mod2.6 depends on mod2.1 and excludes mod1.1 module wide + // mod2.1 depends on mod1.1 which depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org2/mod2.6/ivys/ivy-0.11.xml").toURL(), + getResolveOptions(new String[] {"*"})); + ModuleDescriptor md = report.getModuleDescriptor(); + assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.11"), md + .getModuleRevisionId()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testResolveExceptConfiguration() throws Exception { + // mod10.2 depends on mod5.1 conf *, !A + _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-2.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists()); + } + + public void testResolveFallbackConfiguration() throws Exception { + // mod10.2 depends on mod5.1 conf runtime(default) + _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + } + + public void testResolveFallbackConfiguration2() throws Exception { + // mod10.2 depends on mod5.1 conf runtime(*) + _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.1.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + } + + public void testResolveFallbackConfiguration3() throws Exception { + // mod10.2 depends on mod5.1 conf runtime(*),compile(*) + _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.2.xml").toURL(), + getResolveOptions(new String[] {"*"})); + + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + } + + public void testResolveFallbackConfiguration4() throws Exception { + // mod10.2 depends on mod5.1 conf runtime() + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.3.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + assertFalse(report.hasError()); + + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists()); + assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists()); + } + + public void testResolveMaven2() throws Exception { + // test3 depends on test2 which depends on test + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/m2/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File( + "test/repositories/m2/org/apache/test3/1.0/test3-1.0.pom").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test3", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test2", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test2", "1.0", + "test2", "jar", "jar").exists()); + + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test", "1.0", + "test", "jar", "jar").exists()); + } + + public void testResolveMaven2Classifiers() throws Exception { + // test case for IVY-418 + // test-classifier depends on test-classified with classifier asl + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/m2/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File( + "test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom") + .toURL(), getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId + .newInstance("org.apache", "test-classifier", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test-classified", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test-classified", + "1.0", "test-classified", "jar", "jar").exists()); + } + + public void testResolveMaven2WithVersionProperty() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/m2/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File( + "test/repositories/m2/org/apache/test-version/1.0/test-version-1.0.pom").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test-version", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("org.apache", "test-classifier", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "org.apache", "test-classifier", + "1.0", "test-classifier", "jar", "jar").exists()); + } + + public void testNamespaceMapping() throws Exception { + // the dependency is in another namespace + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); + ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace.xml"), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("systemorg", "systemmod", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg", "systemmod", "1.0", + "A", "jar", "jar").exists()); + } + + public void testNamespaceMapping2() throws Exception { + // the dependency is in another namespace and has itself a dependency on a module available + // in the same namespace + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); + ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace2.xml"), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "2.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("systemorg", "systemmod2", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg", "systemmod2", "1.0", + "B", "jar", "jar").exists()); + + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("systemorg", "systemmod", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg", "systemmod", "1.0", + "A", "jar", "jar").exists()); + } + + public void testNamespaceMapping3() throws Exception { + // same as 2 but with poms + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); + ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace3.xml"), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "3.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(ivy.getCacheManager(_cache).getResolvedIvyFileInCache(mrid).exists()); + + // dependencies + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("systemorg2", "system-2", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg2", "system-2", "1.0", + "2", "jar", "jar").exists()); + + assertTrue(ivy.getCacheManager(_cache).getIvyFileInCache( + ModuleRevisionId.newInstance("systemorg2", "system-1", "1.0")).exists()); + assertTrue(TestHelper.getArchiveFileInCache(ivy, _cache, "systemorg2", "system-1", "1.0", + "1", "jar", "jar").exists()); + } + + public void testNamespaceMapping4() throws Exception { + // same as 2 but with incorrect dependency asked: the first ivy file asks for a dependency + // in the resolver namespace and not the system one: this should fail + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/namespace/ivysettings.xml")); + ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace4.xml"), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "namespace", "4.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertTrue(report.hasError()); + } + + public void testIVY151() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/multirevisions/ivysettings.xml")); + ResolveReport report = ivy.resolve(new File("test/repositories/multirevisions/ivy.xml") + .toURL(), getResolveOptions(new String[] {"compile", "test"})); + + assertNotNull(report); + assertNotNull(report.getUnresolvedDependencies()); + assertEquals("Number of unresolved dependencies not correct", 0, report + .getUnresolvedDependencies().length); + } + + public void testCheckRevision() throws Exception { + // mod12.2 depends on mod12.1 1.0 which depends on mod1.2 + // mod12.1 doesn't have revision in its ivy file + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod12.2/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + assertTrue(report.hasError()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org12", "mod12.1", "1.0")).exists()); + assertFalse(getArchiveFileInCache("org12", "mod12.1", "1.0", "mod12.1", "jar", "jar") + .exists()); + + assertFalse(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testTrustRevision() throws Exception { + // mod12.2 depends on mod12.1 1.0 which depends on mod1.2 + // mod12.1 doesn't have revision in its ivy file + + ((BasicResolver) _settings.getResolver("2-ivy")).setCheckconsistency(false); + + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod12.2/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + assertFalse(report.hasError()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org12", "mod12.1", "1.0")).exists()); + assertTrue(getArchiveFileInCache("org12", "mod12.1", "1.0", "mod12.1", "jar", "jar") + .exists()); + + assertTrue(_cacheManager.getIvyFileInCache( + ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists()); + assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists()); + } + + public void testTransitiveConfMapping() throws Exception { + // IVY-168 + // mod13.3 depends on mod13.2 which depends on mod13.1 + // each module has two confs: j2ee and compile + // each module only publishes one artifact in conf compile + // each module has the following conf mapping on its dependencies: *->@ + // moreover, mod13.1 depends on mod1.2 in with the following conf mapping: compile->default + // thus conf j2ee should be empty for each modules + + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod13.3/ivy-1.0.xml") + .toURL(), getResolveOptions(new String[] {"*"})); + + assertFalse(report.hasError()); + + assertEquals(3, report.getConfigurationReport("compile").getArtifactsNumber()); + assertEquals(0, report.getConfigurationReport("j2ee").getArtifactsNumber()); + } + + public void testExtraAttributes() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/extra-attributes/ivysettings.xml")); + + ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-extra-att.xml"), + getResolveOptions(ivy.getSettings(), new String[] {"*"}).setValidate(false)); + assertFalse(report.hasError()); + + assertTrue(new File(_cache, "apache/mymodule/task1/1854/ivy.xml").exists()); + assertTrue(new File(_cache, "apache/mymodule/task1/1854/mymodule-windows.jar").exists()); + assertTrue(new File(_cache, "apache/mymodule/task1/1854/mymodule-linux.jar").exists()); + } + + public void testBranches1() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/branches/ivysettings.xml")); + + ResolveReport report = ivy.resolve(new File( + "test/repositories/branches/bar/bar1/trunk/1/ivy.xml").toURL(), getResolveOptions( + new String[] {"*"}).setValidate(false)); + assertFalse(report.hasError()); + + assertTrue(getArchiveFileInCache("foo", "foo1", "3", "foo1", "jar", "jar").exists()); + } + + public void testBranches2() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/branches/ivysettings.xml")); + + ResolveReport report = ivy.resolve(new File( + "test/repositories/branches/bar/bar1/trunk/2/ivy.xml").toURL(), getResolveOptions( + new String[] {"*"}).setValidate(false)); + assertFalse(report.hasError()); + + assertTrue(getArchiveFileInCache("foo", "foo1", "4", "foo1", "jar", "jar").exists()); + } + + public void testBranches3() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/branches/ivysettings-defaultbranch1.xml")); + + ResolveReport report = ivy.resolve(new File( + "test/repositories/branches/bar/bar1/trunk/1/ivy.xml").toURL(), getResolveOptions( + new String[] {"*"}).setValidate(false)); + assertFalse(report.hasError()); + + assertTrue(getArchiveFileInCache("foo", "foo1", "4", "foo1", "jar", "jar").exists()); + } + + public void testBranches4() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/branches/ivysettings.xml")); + + ResolveReport report = ivy.resolve(new File( + "test/repositories/branches/bar/bar1/trunk/3/ivy.xml").toURL(), getResolveOptions( + new String[] {"*"}).setValidate(false)); + assertFalse(report.hasError()); + + assertTrue(getArchiveFileInCache("foo", "foo1", "3", "foo1", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("bar", "bar2", "2", "bar2", "jar", "jar").exists()); + } + + public void testBranches5() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/branches/ivysettings-fooonbranch1.xml")); + + ResolveReport report = ivy.resolve(new File( + "test/repositories/branches/bar/bar1/trunk/3/ivy.xml").toURL(), getResolveOptions( + new String[] {"*"}).setValidate(false)); + assertFalse(report.hasError()); + + assertTrue(getArchiveFileInCache("foo", "foo1", "4", "foo1", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("bar", "bar2", "2", "bar2", "jar", "jar").exists()); + } + + public void testExternalArtifacts() throws Exception { + Ivy ivy = Ivy.newInstance(); + ivy.getSettings().setVariable("test.base.url", + new File("test/repositories/external-artifacts").toURL().toString()); + ivy.configure(new File("test/repositories/external-artifacts/ivysettings.xml")); + + ResolveReport report = ivy.resolve(new File("test/repositories/external-artifacts/ivy.xml") + .toURL(), getResolveOptions(new String[] {"*"}).setValidate(false)); + assertFalse(report.hasError()); + + assertTrue(getArchiveFileInCache("apache", "A", "1.0", "a", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("apache", "B", "2.0", "b", "jar", "jar").exists()); + assertTrue(getArchiveFileInCache("apache", "C", "3.0", "C", "jar", "jar").exists()); + } + + public void testResolveWithSpecifiedCache() throws Exception { + File cache2 = new File("build/cache2"); + try { + _ivy.getSettings().setDefaultCache(_cache); + + // the module to resolve + ModuleRevisionId module = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + + // use a non-default cache + ResolveOptions options = getResolveOptions(new String[] {"*"}); + options.setTransitive(false); + options.setUseOrigin(true); + options.setCache(CacheManager.getInstance(_ivy.getSettings(), cache2)); + ResolveReport report = _ivy.getResolveEngine().resolve(module, options, false); + + // the resolved module + ModuleRevisionId resolvedModule = report.getModuleDescriptor() + .getResolvedModuleRevisionId(); + + // verify that the module in the default cache doesn't exist + assertEquals("Default cache is not empty", _cache.list().length, 0); + + // verify the artifact does exist in the non-default cache. + CacheManager nonDefaultManager = _ivy.getCacheManager(cache2); + assertTrue(TestHelper.getArchiveFileInCache(nonDefaultManager, "org1", "mod1.1", "1.0", + "mod1.1", "jar", "jar").exists()); + assertTrue(nonDefaultManager.getResolvedIvyFileInCache(resolvedModule).exists()); + assertTrue(nonDefaultManager.getResolvedIvyPropertiesInCache(resolvedModule).exists()); + assertNotNull(nonDefaultManager.getSavedArtifactOrigin((Artifact) report.getArtifacts() + .get(0))); + } finally { + // delete the non-default cache + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/cache2")); + del.execute(); + } + } + + public void testResolveWithMultipleIvyPatterns() throws Exception { + Ivy ivy = new Ivy(); + ivy.configure(new File("test/repositories/multi-ivypattern/ivysettings.xml")); + + ModuleRevisionId module = ModuleRevisionId.newInstance("org1", "mod1.1", "1.+"); + + // use a non-default cache + ResolveOptions options = getResolveOptions(ivy.getSettings(), new String[] {"*"}); + options.setTransitive(false); + options.setUseOrigin(true); + options.setDownload(false); + ResolveReport report = ivy.getResolveEngine().resolve(module, options, false); + + List dependencies = report.getDependencies(); + assertNotNull(dependencies); + assertEquals(1, dependencies.size()); + IvyNode dependency = (IvyNode) dependencies.get(0); + assertEquals("1.1", dependency.getResolvedId().getRevision()); + } + + // ////////////////////////////////////////////////////////// + // helper methods to ease the tests + // ////////////////////////////////////////////////////////// + + private void assertContainsArtifact(String org, String module, String rev, String artName, + String type, String ext, ConfigurationResolveReport conf) { + Artifact art = getArtifact(org, module, rev, artName, type, ext); + if (!containsArtifact(art, conf.getDownloadedArtifactsReports())) { + fail("artifact " + art + " should be part of " + conf.getConfiguration() + " from " + + conf.getModuleDescriptor().getModuleRevisionId()); + } + } + + private void assertDoesntContainArtifact(String org, String module, String rev, String artName, + String type, String ext, ConfigurationResolveReport conf) { + Artifact art = getArtifact(org, module, rev, artName, type, ext); + if (containsArtifact(art, conf.getDownloadedArtifactsReports())) { + fail("artifact " + art + " should NOT be part of " + conf.getConfiguration() + " from " + + conf.getModuleDescriptor().getModuleRevisionId()); + } + } + + private Artifact getArtifact(String org, String module, String rev, String artName, + String type, String ext) { + return new DefaultArtifact(ModuleRevisionId.newInstance(org, module, rev), new Date(), + artName, type, ext); + } + + private boolean containsArtifact(Artifact art, ArtifactDownloadReport[] adr) { + for (int i = 0; i < adr.length; i++) { + Artifact artifact = adr[i].getArtifact(); + if (artifact.getModuleRevisionId().equals(art.getModuleRevisionId()) + && artifact.getName().equals(art.getName()) + && artifact.getType().equals(art.getType()) + && artifact.getExt().equals(art.getExt())) { + return true; + } + } + return false; + } + + private File getArchiveFileInCache(String organisation, String module, String revision, + String artifact, String type, String ext) { + return TestHelper.getArchiveFileInCache(_cacheManager, organisation, module, revision, + artifact, type, ext); + } + + private ResolveOptions getResolveOptions(String[] confs) { + return getResolveOptions(_ivy.getSettings(), confs); + } + + private ResolveOptions getResolveOptions(IvySettings settings, String[] confs) { + return new ResolveOptions().setConfs(confs).setCache( + CacheManager.getInstance(settings, _cache)); + } + +} diff --git a/test/java/org/apache/ivy/core/resolve/badcacheconf.xml b/test/java/org/apache/ivy/core/resolve/badcacheconf.xml index 4b3827bd..cf9e1aa1 100644 --- a/test/java/org/apache/ivy/core/resolve/badcacheconf.xml +++ b/test/java/org/apache/ivy/core/resolve/badcacheconf.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/dualchainresolverconf.xml b/test/java/org/apache/ivy/core/resolve/dualchainresolverconf.xml index d2ea484b..2c07b5b2 100644 --- a/test/java/org/apache/ivy/core/resolve/dualchainresolverconf.xml +++ b/test/java/org/apache/ivy/core/resolve/dualchainresolverconf.xml @@ -1,41 +1,41 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-148.xml b/test/java/org/apache/ivy/core/resolve/ivy-148.xml index 5f6116f8..6821de29 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-148.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-148.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-148b.xml b/test/java/org/apache/ivy/core/resolve/ivy-148b.xml index 0fbcac43..fba475c8 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-148b.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-148b.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-182.xml b/test/java/org/apache/ivy/core/resolve/ivy-182.xml index 9ba1986a..09f98689 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-182.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-182.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-198.xml b/test/java/org/apache/ivy/core/resolve/ivy-198.xml index 405db170..baca650c 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-198.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-198.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-214.xml b/test/java/org/apache/ivy/core/resolve/ivy-214.xml index 51d051b0..c8fab96c 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-214.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-214.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-218.xml b/test/java/org/apache/ivy/core/resolve/ivy-218.xml index 5626f690..1c109d33 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-218.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-218.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-225.xml b/test/java/org/apache/ivy/core/resolve/ivy-225.xml index 9a308c03..44ade240 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-225.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-225.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-56.xml b/test/java/org/apache/ivy/core/resolve/ivy-56.xml index 4aa22158..c02c9498 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-56.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-56.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-dualchainresolver.xml b/test/java/org/apache/ivy/core/resolve/ivy-dualchainresolver.xml index d4c8659d..2c512cb3 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-dualchainresolver.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-dualchainresolver.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-extra-att.xml b/test/java/org/apache/ivy/core/resolve/ivy-extra-att.xml index 52932221..4ba15765 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-extra-att.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-extra-att.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-latestreleased.xml b/test/java/org/apache/ivy/core/resolve/ivy-latestreleased.xml index ff4d0441..01cd03e9 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-latestreleased.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-latestreleased.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-mod1.2.xml b/test/java/org/apache/ivy/core/resolve/ivy-mod1.2.xml index 8955f8a1..90d38fb2 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-mod1.2.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-mod1.2.xml @@ -1,26 +1,26 @@ - - - - + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-namespace.xml b/test/java/org/apache/ivy/core/resolve/ivy-namespace.xml index 83d7da1d..b6938aef 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-namespace.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-namespace.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-namespace2.xml b/test/java/org/apache/ivy/core/resolve/ivy-namespace2.xml index f5ec7d34..eab90b99 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-namespace2.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-namespace2.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-namespace3.xml b/test/java/org/apache/ivy/core/resolve/ivy-namespace3.xml index 926fd184..d9f0bf18 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-namespace3.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-namespace3.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-namespace4.xml b/test/java/org/apache/ivy/core/resolve/ivy-namespace4.xml index 263fdab6..fd7fb263 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-namespace4.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-namespace4.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/resolve/ivy-other.xml b/test/java/org/apache/ivy/core/resolve/ivy-other.xml index 8d09e59f..e08cafdd 100644 --- a/test/java/org/apache/ivy/core/resolve/ivy-other.xml +++ b/test/java/org/apache/ivy/core/resolve/ivy-other.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java b/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java index 33696f1a..83bdc554 100644 --- a/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java +++ b/test/java/org/apache/ivy/core/retrieve/RetrieveTest.java @@ -1,185 +1,185 @@ -/* - * 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.core.retrieve; - -import java.io.File; -import java.io.IOException; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.IvyPatternHelper; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class RetrieveTest extends TestCase { - private final Ivy _ivy; - - private File _cache; - - public RetrieveTest() throws Exception { - _ivy = new Ivy(); - _ivy.configure(new File("test/repositories/ivysettings.xml")); - } - - protected void setUp() throws Exception { - createCache(); - } - - private void createCache() { - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - cleanCache(); - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/retrieve")); - del.execute(); - } - - private void cleanCache() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - public void testRetrieveSimple() throws Exception { - // mod1.1 depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - - String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; - _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); - assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", - "jar", "jar", "default")).exists()); - - pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; - _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); - assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", - "jar", "jar", "default")).exists()); - } - - public void testRetrieveOverwrite() throws Exception { - // mod1.1 depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - - String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; - - // we create a fake old file to see if it is overwritten - File file = new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", - "mod1.2", "jar", "jar", "default")); - file.getParentFile().mkdirs(); - file.createNewFile(); - file.setLastModified(10000); - _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); - assertEquals( - new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").lastModified(), file - .lastModified()); - } - - public void testRetrieveWithSymlinks() throws Exception { - // mod1.1 depends on mod1.2 - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - - String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; - _ivy - .retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions().setMakeSymlinks( - true)); - assertLink(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", - "jar", "default")); - - pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; - _ivy - .retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions().setMakeSymlinks( - true)); - assertLink(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", - "jar", "default")); - } - - private void assertLink(String filename) throws IOException { - // if the OS is known to support symlink, check that the file is a symlink, - // otherwise just check the file exist. - - File file = new File(filename); - assertTrue("The file " + filename + " doesn't exist", file.exists()); - - String os = System.getProperty("os.name"); - if (os.equals("Linux") || os.equals("Solaris") || os.equals("FreeBSD")) { - // these OS should support symnlink, so check that the file is actually a symlink. - // this is done be checking that the canonical path is different from the absolute - // path. - File absFile = file.getAbsoluteFile(); - File canFile = file.getCanonicalFile(); - assertFalse("The file " + filename + " isn't a symlink", absFile.equals(canFile)); - } - } - - public void testRetrieveWithVariable() throws Exception { - // mod1.1 depends on mod1.2 - _ivy.setVariable("retrieve.dir", "retrieve"); - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"*"})); - assertNotNull(report); - ModuleDescriptor md = report.getModuleDescriptor(); - assertNotNull(md); - - String pattern = "build/test/${retrieve.dir}/[module]/[conf]/[artifact]-[revision].[ext]"; - _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); - pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve"); - assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", - "jar", "jar", "default")).exists()); - - pattern = "build/test/${retrieve.dir}/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; - _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); - pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve"); - assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", - "jar", "jar", "default")).exists()); - } - - private RetrieveOptions getRetrieveOptions() { - return new RetrieveOptions().setCache(CacheManager.getInstance(_ivy.getSettings(), _cache)); - } - - private ResolveOptions getResolveOptions(String[] confs) { - return new ResolveOptions().setConfs(confs).setCache( - CacheManager.getInstance(_ivy.getSettings(), _cache)); - } - -} +/* + * 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.core.retrieve; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.IvyPatternHelper; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class RetrieveTest extends TestCase { + private final Ivy _ivy; + + private File _cache; + + public RetrieveTest() throws Exception { + _ivy = new Ivy(); + _ivy.configure(new File("test/repositories/ivysettings.xml")); + } + + protected void setUp() throws Exception { + createCache(); + } + + private void createCache() { + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + cleanCache(); + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("build/test/retrieve")); + del.execute(); + } + + private void cleanCache() { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + public void testRetrieveSimple() throws Exception { + // mod1.1 depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + + String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; + _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); + assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", + "jar", "jar", "default")).exists()); + + pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; + _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); + assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", + "jar", "jar", "default")).exists()); + } + + public void testRetrieveOverwrite() throws Exception { + // mod1.1 depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + + String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; + + // we create a fake old file to see if it is overwritten + File file = new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", + "mod1.2", "jar", "jar", "default")); + file.getParentFile().mkdirs(); + file.createNewFile(); + file.setLastModified(10000); + _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); + assertEquals( + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").lastModified(), file + .lastModified()); + } + + public void testRetrieveWithSymlinks() throws Exception { + // mod1.1 depends on mod1.2 + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + + String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; + _ivy + .retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions().setMakeSymlinks( + true)); + assertLink(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", + "jar", "default")); + + pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; + _ivy + .retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions().setMakeSymlinks( + true)); + assertLink(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", + "jar", "default")); + } + + private void assertLink(String filename) throws IOException { + // if the OS is known to support symlink, check that the file is a symlink, + // otherwise just check the file exist. + + File file = new File(filename); + assertTrue("The file " + filename + " doesn't exist", file.exists()); + + String os = System.getProperty("os.name"); + if (os.equals("Linux") || os.equals("Solaris") || os.equals("FreeBSD")) { + // these OS should support symnlink, so check that the file is actually a symlink. + // this is done be checking that the canonical path is different from the absolute + // path. + File absFile = file.getAbsoluteFile(); + File canFile = file.getCanonicalFile(); + assertFalse("The file " + filename + " isn't a symlink", absFile.equals(canFile)); + } + } + + public void testRetrieveWithVariable() throws Exception { + // mod1.1 depends on mod1.2 + _ivy.setVariable("retrieve.dir", "retrieve"); + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"*"})); + assertNotNull(report); + ModuleDescriptor md = report.getModuleDescriptor(); + assertNotNull(md); + + String pattern = "build/test/${retrieve.dir}/[module]/[conf]/[artifact]-[revision].[ext]"; + _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); + pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve"); + assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", + "jar", "jar", "default")).exists()); + + pattern = "build/test/${retrieve.dir}/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; + _ivy.retrieve(md.getModuleRevisionId(), pattern, getRetrieveOptions()); + pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve"); + assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", + "jar", "jar", "default")).exists()); + } + + private RetrieveOptions getRetrieveOptions() { + return new RetrieveOptions().setCache(CacheManager.getInstance(_ivy.getSettings(), _cache)); + } + + private ResolveOptions getResolveOptions(String[] confs) { + return new ResolveOptions().setConfs(confs).setCache( + CacheManager.getInstance(_ivy.getSettings(), _cache)); + } + +} diff --git a/test/java/org/apache/ivy/core/settings/ConfigureTest.java b/test/java/org/apache/ivy/core/settings/ConfigureTest.java index 997db8c7..3accadf3 100644 --- a/test/java/org/apache/ivy/core/settings/ConfigureTest.java +++ b/test/java/org/apache/ivy/core/settings/ConfigureTest.java @@ -1,79 +1,79 @@ -/* - * 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.core.settings; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.plugins.resolver.IBiblioResolver; -import org.apache.ivy.plugins.resolver.IvyRepResolver; - -public class ConfigureTest extends TestCase { - public void testDefault() throws ParseException, IOException { - Ivy ivy = new Ivy(); - ivy.configureDefault(); - - IvySettings settings = ivy.getSettings(); - assertNotNull(settings.getDefaultResolver()); - - DependencyResolver publicResolver = settings.getResolver("public"); - assertNotNull(publicResolver); - assertTrue(publicResolver instanceof IBiblioResolver); - IBiblioResolver ibiblio = (IBiblioResolver) publicResolver; - assertTrue(ibiblio.isM2compatible()); - } - - public void testDefault14() throws ParseException, IOException { - Ivy ivy = new Ivy(); - ivy.configureDefault14(); - - IvySettings settings = ivy.getSettings(); - assertNotNull(settings.getDefaultResolver()); - - DependencyResolver publicResolver = settings.getResolver("public"); - assertTrue(publicResolver instanceof IvyRepResolver); - } - - public void testTypedefWithCustomClasspath() throws Exception { - Ivy ivy = new Ivy(); - ivy.setVariable("ivy.custom.test.dir", new File("test/java/org/apache/ivy/core/settings") - .toURL().toString()); - ivy.configure(ConfigureTest.class.getResource("ivysettings-custom-typedef.xml")); - - DependencyResolver custom = ivy.getSettings().getResolver("custom"); - assertNotNull(custom); - assertEquals("org.apache.ivy.plugins.resolver.CustomResolver", custom.getClass().getName()); - } - - public void testTypedefWithCustomClasspathWithFile() throws Exception { - Ivy ivy = new Ivy(); - ivy.setVariable("ivy.custom.test.dir", new File("test/java/org/apache/ivy/core/settings") - .toString()); - ivy.configure(ConfigureTest.class.getResource("ivysettings-custom-typedef2.xml")); - - DependencyResolver custom = ivy.getSettings().getResolver("custom"); - assertNotNull(custom); - assertEquals("org.apache.ivy.plugins.resolver.CustomResolver", custom.getClass().getName()); - } - -} +/* + * 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.core.settings; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.plugins.resolver.IBiblioResolver; +import org.apache.ivy.plugins.resolver.IvyRepResolver; + +public class ConfigureTest extends TestCase { + public void testDefault() throws ParseException, IOException { + Ivy ivy = new Ivy(); + ivy.configureDefault(); + + IvySettings settings = ivy.getSettings(); + assertNotNull(settings.getDefaultResolver()); + + DependencyResolver publicResolver = settings.getResolver("public"); + assertNotNull(publicResolver); + assertTrue(publicResolver instanceof IBiblioResolver); + IBiblioResolver ibiblio = (IBiblioResolver) publicResolver; + assertTrue(ibiblio.isM2compatible()); + } + + public void testDefault14() throws ParseException, IOException { + Ivy ivy = new Ivy(); + ivy.configureDefault14(); + + IvySettings settings = ivy.getSettings(); + assertNotNull(settings.getDefaultResolver()); + + DependencyResolver publicResolver = settings.getResolver("public"); + assertTrue(publicResolver instanceof IvyRepResolver); + } + + public void testTypedefWithCustomClasspath() throws Exception { + Ivy ivy = new Ivy(); + ivy.setVariable("ivy.custom.test.dir", new File("test/java/org/apache/ivy/core/settings") + .toURL().toString()); + ivy.configure(ConfigureTest.class.getResource("ivysettings-custom-typedef.xml")); + + DependencyResolver custom = ivy.getSettings().getResolver("custom"); + assertNotNull(custom); + assertEquals("org.apache.ivy.plugins.resolver.CustomResolver", custom.getClass().getName()); + } + + public void testTypedefWithCustomClasspathWithFile() throws Exception { + Ivy ivy = new Ivy(); + ivy.setVariable("ivy.custom.test.dir", new File("test/java/org/apache/ivy/core/settings") + .toString()); + ivy.configure(ConfigureTest.class.getResource("ivysettings-custom-typedef2.xml")); + + DependencyResolver custom = ivy.getSettings().getResolver("custom"); + assertNotNull(custom); + assertEquals("org.apache.ivy.plugins.resolver.CustomResolver", custom.getClass().getName()); + } + +} diff --git a/test/java/org/apache/ivy/core/settings/OnlineXmlSettingsParserTest.java b/test/java/org/apache/ivy/core/settings/OnlineXmlSettingsParserTest.java index a702c375..cc43222a 100644 --- a/test/java/org/apache/ivy/core/settings/OnlineXmlSettingsParserTest.java +++ b/test/java/org/apache/ivy/core/settings/OnlineXmlSettingsParserTest.java @@ -1,56 +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. - * - */ -package org.apache.ivy.core.settings; - -import java.net.URL; - -import junit.framework.TestCase; - -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.plugins.resolver.IvyRepResolver; -import org.apache.ivy.util.url.URLHandler; -import org.apache.ivy.util.url.URLHandlerDispatcher; -import org.apache.ivy.util.url.URLHandlerRegistry; - -/** - * split from XmlIvyConfigurationParserTest due to dependency on network resource - */ -public class OnlineXmlSettingsParserTest extends TestCase { - // remote.test - - public void testIncludeHttpUrl() throws Exception { - configureURLHandler(); - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(new URL( - "http://incubator.apache.org/ivy/test/ivysettings-include-http-url.xml")); - - DependencyResolver resolver = settings.getResolver("ivyrep"); - assertNotNull(resolver); - assertTrue(resolver instanceof IvyRepResolver); - } - - private void configureURLHandler() { - URLHandlerDispatcher dispatcher = new URLHandlerDispatcher(); - URLHandler httpHandler = URLHandlerRegistry.getHttp(); - dispatcher.setDownloader("http", httpHandler); - dispatcher.setDownloader("https", httpHandler); - URLHandlerRegistry.setDefault(dispatcher); - } - -} +/* + * 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.core.settings; + +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.plugins.resolver.IvyRepResolver; +import org.apache.ivy.util.url.URLHandler; +import org.apache.ivy.util.url.URLHandlerDispatcher; +import org.apache.ivy.util.url.URLHandlerRegistry; + +/** + * split from XmlIvyConfigurationParserTest due to dependency on network resource + */ +public class OnlineXmlSettingsParserTest extends TestCase { + // remote.test + + public void testIncludeHttpUrl() throws Exception { + configureURLHandler(); + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(new URL( + "http://incubator.apache.org/ivy/test/ivysettings-include-http-url.xml")); + + DependencyResolver resolver = settings.getResolver("ivyrep"); + assertNotNull(resolver); + assertTrue(resolver instanceof IvyRepResolver); + } + + private void configureURLHandler() { + URLHandlerDispatcher dispatcher = new URLHandlerDispatcher(); + URLHandler httpHandler = URLHandlerRegistry.getHttp(); + dispatcher.setDownloader("http", httpHandler); + dispatcher.setDownloader("https", httpHandler); + URLHandlerRegistry.setDefault(dispatcher); + } + +} diff --git a/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java b/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java index 2815c88b..d61caf43 100644 --- a/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java +++ b/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java @@ -1,390 +1,390 @@ -/* - * 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.core.settings; - -import java.io.File; -import java.text.ParseException; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.plugins.latest.LatestRevisionStrategy; -import org.apache.ivy.plugins.latest.LatestStrategy; -import org.apache.ivy.plugins.latest.LatestTimeStrategy; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; -import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest; -import org.apache.ivy.plugins.report.ReportOutputter; -import org.apache.ivy.plugins.resolver.ChainResolver; -import org.apache.ivy.plugins.resolver.DependencyResolver; -import org.apache.ivy.plugins.resolver.FileSystemResolver; -import org.apache.ivy.plugins.resolver.MockResolver; -import org.apache.ivy.plugins.version.ChainVersionMatcher; -import org.apache.ivy.plugins.version.MockVersionMatcher; -import org.apache.ivy.plugins.version.VersionMatcher; - -/** - * TODO write javadoc - */ -public class XmlSettingsParserTest extends TestCase { - public void test() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-test.xml")); - - File defaultCache = settings.getDefaultCache(); - assertNotNull(defaultCache); - assertEquals("mycache", defaultCache.getName()); - - assertFalse(settings.isCheckUpToDate()); - assertFalse(settings.doValidate()); - - assertEquals("[module]/ivys/ivy-[revision].xml", settings.getCacheIvyPattern()); - assertEquals("[module]/[type]s/[artifact]-[revision].[ext]", settings - .getCacheArtifactPattern()); - - LatestStrategy latest = settings.getLatestStrategy("mylatest-revision"); - assertNotNull(latest); - assertTrue(latest instanceof LatestRevisionStrategy); - LatestRevisionStrategy l = (LatestRevisionStrategy) latest; - assertEquals(new Integer(-2), l.getSpecialMeanings().get("pre")); - assertEquals(new Integer(4), l.getSpecialMeanings().get("qa")); - - DependencyResolver defaultResolver = settings.getDefaultResolver(); - assertNotNull(defaultResolver); - assertEquals("libraries", defaultResolver.getName()); - assertTrue(defaultResolver instanceof FileSystemResolver); - FileSystemResolver fsres = (FileSystemResolver) defaultResolver; - List ivyPatterns = fsres.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("lib/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0)); - - LatestStrategy strategy = fsres.getLatestStrategy(); - assertNotNull(strategy); - assertTrue(strategy instanceof LatestRevisionStrategy); - - DependencyResolver internal = settings.getResolver("internal"); - assertNotNull(internal); - assertTrue(internal instanceof ChainResolver); - ChainResolver chain = (ChainResolver) internal; - List subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(2, subresolvers.size()); - FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); - assertEquals("int1", fsInt1.getName()); - assertEquals(1, fsInt1.getIvyPatterns().size()); - assertEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", fsInt1 - .getIvyPatterns().get(0)); - assertEquals("int2", ((DependencyResolver) subresolvers.get(1)).getName()); - - strategy = fsInt1.getLatestStrategy(); - assertNotNull(strategy); - assertTrue(strategy instanceof LatestTimeStrategy); - - assertEquals("libraries", settings.getResolver(new ModuleId("unknown", "lib")).getName()); - assertEquals("internal", settings.getResolver(new ModuleId("apache", "ant")).getName()); - assertEquals("int1", settings.getResolver(new ModuleId("apache", "ivy")).getName()); - assertEquals("int1", settings.getResolver(new ModuleId("apache", "ivyde")).getName()); - } - - public void testNoOrgInModule() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - try { - parser.parse(XmlSettingsParserTest.class - .getResource("ivysettings-no-org-in-module.xml")); - fail("no organisation in module is supposed to raise an exception"); - } catch (ParseException e) { - assertTrue("bad exception message: " + e.getMessage(), e.getMessage().indexOf( - "'organisation'") != -1); - } - } - - public void testNoNameInModule() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - try { - parser.parse(XmlSettingsParserTest.class - .getResource("ivysettings-no-name-in-module.xml")); - fail("no name in module is supposed to raise an exception"); - } catch (ParseException e) { - assertTrue("bad exception message: " + e.getMessage(), - e.getMessage().indexOf("'name'") != -1); - } - } - - public void testTypedef() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-typedef.xml")); - - DependencyResolver mock = settings.getResolver("mock3"); - assertNotNull(mock); - assertTrue(mock instanceof MockResolver); - - DependencyResolver internal = settings.getResolver("internal"); - assertNotNull(internal); - assertTrue(internal instanceof ChainResolver); - ChainResolver chain = (ChainResolver) internal; - List subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(2, subresolvers.size()); - - assertEquals("mock1", ((DependencyResolver) subresolvers.get(0)).getName()); - assertEquals("mock2", ((DependencyResolver) subresolvers.get(1)).getName()); - assertTrue(subresolvers.get(0) instanceof MockResolver); - assertTrue(subresolvers.get(1) instanceof MockResolver); - } - - public void testStatuses() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-status.xml")); - - assertEquals("bronze", settings.getStatusManager().getDefaultStatus()); - assertEquals(0, settings.getStatusManager().getPriority("gold")); - assertEquals(1, settings.getStatusManager().getPriority("silver")); - assertEquals(2, settings.getStatusManager().getPriority("bronze")); - assertEquals(false, settings.getStatusManager().isIntegration("gold")); - assertEquals(false, settings.getStatusManager().isIntegration("silver")); - assertEquals(true, settings.getStatusManager().isIntegration("bronze")); - } - - public void testConflictManager() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-conflict-manager.xml")); - - assertEquals("latest-time", settings.getConflictManager(new ModuleId("apache", "ivyde")) - .getName()); - assertEquals("all", settings.getConflictManager(new ModuleId("apache", "ant")).getName()); - } - - public void testVersionMatchers1() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-vmatcher1.xml")); - - VersionMatcher mock = settings.getVersionMatcher("vmock"); - assertNotNull(mock); - assertTrue(mock instanceof MockVersionMatcher); - - VersionMatcher v = settings.getVersionMatcher(); - assertTrue(v instanceof ChainVersionMatcher); - ChainVersionMatcher chain = (ChainVersionMatcher) v; - assertEquals(3, chain.getMatchers().size()); - assertTrue(chain.getMatchers().contains(mock)); - assertTrue(chain.getMatchers().contains(settings.getVersionMatcher("exact"))); - assertTrue(chain.getMatchers().contains(settings.getVersionMatcher("latest"))); - } - - public void testVersionMatchers2() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-vmatcher2.xml")); - - VersionMatcher mock = settings.getVersionMatcher("vmock"); - assertNotNull(mock); - assertTrue(mock instanceof MockVersionMatcher); - - VersionMatcher v = settings.getVersionMatcher(); - assertTrue(v instanceof ChainVersionMatcher); - ChainVersionMatcher chain = (ChainVersionMatcher) v; - assertEquals(5, chain.getMatchers().size()); - assertTrue(chain.getMatchers().contains(mock)); - } - - public void testRef() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-ref.xml")); - - DependencyResolver internal = settings.getResolver("internal"); - assertNotNull(internal); - assertTrue(internal instanceof ChainResolver); - ChainResolver chain = (ChainResolver) internal; - List subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(2, subresolvers.size()); - FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); - assertEquals("fs", fsInt1.getName()); - - List ivyPatterns = fsInt1.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns - .get(0)); - - DependencyResolver external = settings.getResolver("external"); - assertNotNull(external); - assertTrue(external instanceof ChainResolver); - chain = (ChainResolver) external; - subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(1, subresolvers.size()); - FileSystemResolver fsInt2 = (FileSystemResolver) subresolvers.get(0); - assertEquals("fs", fsInt2.getName()); - - ivyPatterns = fsInt2.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns - .get(0)); - } - - public void testMacro() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro.xml")); - - DependencyResolver def = settings.getResolver("default"); - assertNotNull(def); - assertTrue(def instanceof ChainResolver); - ChainResolver chain = (ChainResolver) def; - List subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(2, subresolvers.size()); - FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); - assertEquals("default-fs1", fsInt1.getName()); - - List ivyPatterns = fsInt1.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("path/to/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", - ivyPatterns.get(0)); - - FileSystemResolver fsInt2 = (FileSystemResolver) subresolvers.get(1); - assertEquals("default-fs2", fsInt2.getName()); - - ivyPatterns = fsInt2.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("path/to/secondrep/[organisation]/[module]/[type]s/ivy-[revision].xml", - ivyPatterns.get(0)); - - DependencyResolver other = settings.getResolver("other"); - assertNotNull(other); - assertTrue(other instanceof ChainResolver); - chain = (ChainResolver) other; - subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(2, subresolvers.size()); - - fsInt2 = (FileSystemResolver) subresolvers.get(1); - assertEquals("other-fs2", fsInt2.getName()); - - ivyPatterns = fsInt2.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("path/to/secondrep/[module]/[type]s/ivy-[revision].xml", ivyPatterns.get(0)); - } - - public void testMacroAndRef() throws Exception { - // test case for IVY-319 - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro+ref.xml")); - - DependencyResolver shared = settings.getResolver("shared"); - assertNotNull(shared); - assertTrue(shared instanceof FileSystemResolver); - - DependencyResolver mychain = settings.getResolver("mychain"); - assertNotNull(mychain); - assertTrue(mychain instanceof ChainResolver); - ChainResolver chain = (ChainResolver) mychain; - List subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(1, subresolvers.size()); - shared = (DependencyResolver) subresolvers.get(0); - assertEquals("shared", shared.getName()); - assertTrue(shared instanceof FileSystemResolver); - } - - public void testInclude() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-include.xml")); - - DependencyResolver def = settings.getResolver("default"); - assertNotNull(def); - assertTrue(def instanceof ChainResolver); - ChainResolver chain = (ChainResolver) def; - List subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(2, subresolvers.size()); - FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); - assertEquals("default-fs1", fsInt1.getName()); - - List ivyPatterns = fsInt1.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("path/to/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", - ivyPatterns.get(0)); - - DependencyResolver inc = settings.getResolver("includeworks"); - assertNotNull(inc); - assertTrue(inc instanceof ChainResolver); - chain = (ChainResolver) inc; - subresolvers = chain.getResolvers(); - assertNotNull(subresolvers); - assertEquals(2, subresolvers.size()); - - fsInt1 = (FileSystemResolver) subresolvers.get(0); - assertEquals("includeworks-fs1", fsInt1.getName()); - - ivyPatterns = fsInt1.getIvyPatterns(); - assertNotNull(ivyPatterns); - assertEquals(1, ivyPatterns.size()); - assertEquals("included/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", - ivyPatterns.get(0)); - } - - public void testParser() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-parser.xml")); - assertEquals(ModuleDescriptorParserRegistryTest.MyParser.class.getName(), - ModuleDescriptorParserRegistry.getInstance().getParsers()[0].getClass().getName()); - } - - public void testOutputter() throws Exception { - IvySettings settings = new IvySettings(); - XmlSettingsParser parser = new XmlSettingsParser(settings); - parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-outputter.xml")); - - // System.out.println(Arrays.asList(ivy.getReportOutputters())); - - ReportOutputter testOutputter = settings.getReportOutputter("test"); - assertNotNull(testOutputter); - assertTrue(testOutputter instanceof MyOutputter); - } - - public static class MyOutputter implements ReportOutputter { - - public void output(ResolveReport report, File destDir) { - } - - public String getName() { - return "test"; - } - - } -} +/* + * 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.core.settings; + +import java.io.File; +import java.text.ParseException; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.plugins.latest.LatestRevisionStrategy; +import org.apache.ivy.plugins.latest.LatestStrategy; +import org.apache.ivy.plugins.latest.LatestTimeStrategy; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry; +import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest; +import org.apache.ivy.plugins.report.ReportOutputter; +import org.apache.ivy.plugins.resolver.ChainResolver; +import org.apache.ivy.plugins.resolver.DependencyResolver; +import org.apache.ivy.plugins.resolver.FileSystemResolver; +import org.apache.ivy.plugins.resolver.MockResolver; +import org.apache.ivy.plugins.version.ChainVersionMatcher; +import org.apache.ivy.plugins.version.MockVersionMatcher; +import org.apache.ivy.plugins.version.VersionMatcher; + +/** + * TODO write javadoc + */ +public class XmlSettingsParserTest extends TestCase { + public void test() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-test.xml")); + + File defaultCache = settings.getDefaultCache(); + assertNotNull(defaultCache); + assertEquals("mycache", defaultCache.getName()); + + assertFalse(settings.isCheckUpToDate()); + assertFalse(settings.doValidate()); + + assertEquals("[module]/ivys/ivy-[revision].xml", settings.getCacheIvyPattern()); + assertEquals("[module]/[type]s/[artifact]-[revision].[ext]", settings + .getCacheArtifactPattern()); + + LatestStrategy latest = settings.getLatestStrategy("mylatest-revision"); + assertNotNull(latest); + assertTrue(latest instanceof LatestRevisionStrategy); + LatestRevisionStrategy l = (LatestRevisionStrategy) latest; + assertEquals(new Integer(-2), l.getSpecialMeanings().get("pre")); + assertEquals(new Integer(4), l.getSpecialMeanings().get("qa")); + + DependencyResolver defaultResolver = settings.getDefaultResolver(); + assertNotNull(defaultResolver); + assertEquals("libraries", defaultResolver.getName()); + assertTrue(defaultResolver instanceof FileSystemResolver); + FileSystemResolver fsres = (FileSystemResolver) defaultResolver; + List ivyPatterns = fsres.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("lib/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0)); + + LatestStrategy strategy = fsres.getLatestStrategy(); + assertNotNull(strategy); + assertTrue(strategy instanceof LatestRevisionStrategy); + + DependencyResolver internal = settings.getResolver("internal"); + assertNotNull(internal); + assertTrue(internal instanceof ChainResolver); + ChainResolver chain = (ChainResolver) internal; + List subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(2, subresolvers.size()); + FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); + assertEquals("int1", fsInt1.getName()); + assertEquals(1, fsInt1.getIvyPatterns().size()); + assertEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", fsInt1 + .getIvyPatterns().get(0)); + assertEquals("int2", ((DependencyResolver) subresolvers.get(1)).getName()); + + strategy = fsInt1.getLatestStrategy(); + assertNotNull(strategy); + assertTrue(strategy instanceof LatestTimeStrategy); + + assertEquals("libraries", settings.getResolver(new ModuleId("unknown", "lib")).getName()); + assertEquals("internal", settings.getResolver(new ModuleId("apache", "ant")).getName()); + assertEquals("int1", settings.getResolver(new ModuleId("apache", "ivy")).getName()); + assertEquals("int1", settings.getResolver(new ModuleId("apache", "ivyde")).getName()); + } + + public void testNoOrgInModule() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + try { + parser.parse(XmlSettingsParserTest.class + .getResource("ivysettings-no-org-in-module.xml")); + fail("no organisation in module is supposed to raise an exception"); + } catch (ParseException e) { + assertTrue("bad exception message: " + e.getMessage(), e.getMessage().indexOf( + "'organisation'") != -1); + } + } + + public void testNoNameInModule() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + try { + parser.parse(XmlSettingsParserTest.class + .getResource("ivysettings-no-name-in-module.xml")); + fail("no name in module is supposed to raise an exception"); + } catch (ParseException e) { + assertTrue("bad exception message: " + e.getMessage(), + e.getMessage().indexOf("'name'") != -1); + } + } + + public void testTypedef() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-typedef.xml")); + + DependencyResolver mock = settings.getResolver("mock3"); + assertNotNull(mock); + assertTrue(mock instanceof MockResolver); + + DependencyResolver internal = settings.getResolver("internal"); + assertNotNull(internal); + assertTrue(internal instanceof ChainResolver); + ChainResolver chain = (ChainResolver) internal; + List subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(2, subresolvers.size()); + + assertEquals("mock1", ((DependencyResolver) subresolvers.get(0)).getName()); + assertEquals("mock2", ((DependencyResolver) subresolvers.get(1)).getName()); + assertTrue(subresolvers.get(0) instanceof MockResolver); + assertTrue(subresolvers.get(1) instanceof MockResolver); + } + + public void testStatuses() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-status.xml")); + + assertEquals("bronze", settings.getStatusManager().getDefaultStatus()); + assertEquals(0, settings.getStatusManager().getPriority("gold")); + assertEquals(1, settings.getStatusManager().getPriority("silver")); + assertEquals(2, settings.getStatusManager().getPriority("bronze")); + assertEquals(false, settings.getStatusManager().isIntegration("gold")); + assertEquals(false, settings.getStatusManager().isIntegration("silver")); + assertEquals(true, settings.getStatusManager().isIntegration("bronze")); + } + + public void testConflictManager() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-conflict-manager.xml")); + + assertEquals("latest-time", settings.getConflictManager(new ModuleId("apache", "ivyde")) + .getName()); + assertEquals("all", settings.getConflictManager(new ModuleId("apache", "ant")).getName()); + } + + public void testVersionMatchers1() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-vmatcher1.xml")); + + VersionMatcher mock = settings.getVersionMatcher("vmock"); + assertNotNull(mock); + assertTrue(mock instanceof MockVersionMatcher); + + VersionMatcher v = settings.getVersionMatcher(); + assertTrue(v instanceof ChainVersionMatcher); + ChainVersionMatcher chain = (ChainVersionMatcher) v; + assertEquals(3, chain.getMatchers().size()); + assertTrue(chain.getMatchers().contains(mock)); + assertTrue(chain.getMatchers().contains(settings.getVersionMatcher("exact"))); + assertTrue(chain.getMatchers().contains(settings.getVersionMatcher("latest"))); + } + + public void testVersionMatchers2() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-vmatcher2.xml")); + + VersionMatcher mock = settings.getVersionMatcher("vmock"); + assertNotNull(mock); + assertTrue(mock instanceof MockVersionMatcher); + + VersionMatcher v = settings.getVersionMatcher(); + assertTrue(v instanceof ChainVersionMatcher); + ChainVersionMatcher chain = (ChainVersionMatcher) v; + assertEquals(5, chain.getMatchers().size()); + assertTrue(chain.getMatchers().contains(mock)); + } + + public void testRef() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-ref.xml")); + + DependencyResolver internal = settings.getResolver("internal"); + assertNotNull(internal); + assertTrue(internal instanceof ChainResolver); + ChainResolver chain = (ChainResolver) internal; + List subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(2, subresolvers.size()); + FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); + assertEquals("fs", fsInt1.getName()); + + List ivyPatterns = fsInt1.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns + .get(0)); + + DependencyResolver external = settings.getResolver("external"); + assertNotNull(external); + assertTrue(external instanceof ChainResolver); + chain = (ChainResolver) external; + subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(1, subresolvers.size()); + FileSystemResolver fsInt2 = (FileSystemResolver) subresolvers.get(0); + assertEquals("fs", fsInt2.getName()); + + ivyPatterns = fsInt2.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns + .get(0)); + } + + public void testMacro() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro.xml")); + + DependencyResolver def = settings.getResolver("default"); + assertNotNull(def); + assertTrue(def instanceof ChainResolver); + ChainResolver chain = (ChainResolver) def; + List subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(2, subresolvers.size()); + FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); + assertEquals("default-fs1", fsInt1.getName()); + + List ivyPatterns = fsInt1.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("path/to/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", + ivyPatterns.get(0)); + + FileSystemResolver fsInt2 = (FileSystemResolver) subresolvers.get(1); + assertEquals("default-fs2", fsInt2.getName()); + + ivyPatterns = fsInt2.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("path/to/secondrep/[organisation]/[module]/[type]s/ivy-[revision].xml", + ivyPatterns.get(0)); + + DependencyResolver other = settings.getResolver("other"); + assertNotNull(other); + assertTrue(other instanceof ChainResolver); + chain = (ChainResolver) other; + subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(2, subresolvers.size()); + + fsInt2 = (FileSystemResolver) subresolvers.get(1); + assertEquals("other-fs2", fsInt2.getName()); + + ivyPatterns = fsInt2.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("path/to/secondrep/[module]/[type]s/ivy-[revision].xml", ivyPatterns.get(0)); + } + + public void testMacroAndRef() throws Exception { + // test case for IVY-319 + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-macro+ref.xml")); + + DependencyResolver shared = settings.getResolver("shared"); + assertNotNull(shared); + assertTrue(shared instanceof FileSystemResolver); + + DependencyResolver mychain = settings.getResolver("mychain"); + assertNotNull(mychain); + assertTrue(mychain instanceof ChainResolver); + ChainResolver chain = (ChainResolver) mychain; + List subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(1, subresolvers.size()); + shared = (DependencyResolver) subresolvers.get(0); + assertEquals("shared", shared.getName()); + assertTrue(shared instanceof FileSystemResolver); + } + + public void testInclude() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-include.xml")); + + DependencyResolver def = settings.getResolver("default"); + assertNotNull(def); + assertTrue(def instanceof ChainResolver); + ChainResolver chain = (ChainResolver) def; + List subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(2, subresolvers.size()); + FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0); + assertEquals("default-fs1", fsInt1.getName()); + + List ivyPatterns = fsInt1.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("path/to/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", + ivyPatterns.get(0)); + + DependencyResolver inc = settings.getResolver("includeworks"); + assertNotNull(inc); + assertTrue(inc instanceof ChainResolver); + chain = (ChainResolver) inc; + subresolvers = chain.getResolvers(); + assertNotNull(subresolvers); + assertEquals(2, subresolvers.size()); + + fsInt1 = (FileSystemResolver) subresolvers.get(0); + assertEquals("includeworks-fs1", fsInt1.getName()); + + ivyPatterns = fsInt1.getIvyPatterns(); + assertNotNull(ivyPatterns); + assertEquals(1, ivyPatterns.size()); + assertEquals("included/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]", + ivyPatterns.get(0)); + } + + public void testParser() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-parser.xml")); + assertEquals(ModuleDescriptorParserRegistryTest.MyParser.class.getName(), + ModuleDescriptorParserRegistry.getInstance().getParsers()[0].getClass().getName()); + } + + public void testOutputter() throws Exception { + IvySettings settings = new IvySettings(); + XmlSettingsParser parser = new XmlSettingsParser(settings); + parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-outputter.xml")); + + // System.out.println(Arrays.asList(ivy.getReportOutputters())); + + ReportOutputter testOutputter = settings.getReportOutputter("test"); + assertNotNull(testOutputter); + assertTrue(testOutputter instanceof MyOutputter); + } + + public static class MyOutputter implements ReportOutputter { + + public void output(ResolveReport report, File destDir) { + } + + public String getName() { + return "test"; + } + + } +} diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-conflict-manager.xml b/test/java/org/apache/ivy/core/settings/ivysettings-conflict-manager.xml index a07fcd9c..e0fdd78d 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-conflict-manager.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-conflict-manager.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef.xml b/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef.xml index 7bc25bcc..b4cca8a4 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef2.xml b/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef2.xml index 604e790f..58ae9cd9 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef2.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-custom-typedef2.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-include.xml b/test/java/org/apache/ivy/core/settings/ivysettings-include.xml index 0668177b..b1b9c810 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-include.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-include.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-macro+ref.xml b/test/java/org/apache/ivy/core/settings/ivysettings-macro+ref.xml index a247aabb..ad35e020 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-macro+ref.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-macro+ref.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml b/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml index 889d5209..75bc33a2 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml @@ -1,43 +1,43 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-no-name-in-module.xml b/test/java/org/apache/ivy/core/settings/ivysettings-no-name-in-module.xml index 63fbd938..2bc9abd8 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-no-name-in-module.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-no-name-in-module.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-no-org-in-module.xml b/test/java/org/apache/ivy/core/settings/ivysettings-no-org-in-module.xml index 514e978e..24ca2518 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-no-org-in-module.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-no-org-in-module.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-outputter.xml b/test/java/org/apache/ivy/core/settings/ivysettings-outputter.xml index 8cd59c6d..a925c11d 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-outputter.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-outputter.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-parser.xml b/test/java/org/apache/ivy/core/settings/ivysettings-parser.xml index 5a080227..04e93a2f 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-parser.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-parser.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml b/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml index b9a0ebed..c98cb2e6 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-status.xml b/test/java/org/apache/ivy/core/settings/ivysettings-status.xml index 7b4f5199..5135a053 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-status.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-status.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-test.xml b/test/java/org/apache/ivy/core/settings/ivysettings-test.xml index 4f93e790..a8607b95 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-test.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-test.xml @@ -1,51 +1,51 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-typedef.xml b/test/java/org/apache/ivy/core/settings/ivysettings-typedef.xml index 981017ae..b020a0b1 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-typedef.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-typedef.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher1.xml b/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher1.xml index 4e96826b..040b6f52 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher1.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher1.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher2.xml b/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher2.xml index b52e3c2b..d10d9e09 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher2.xml +++ b/test/java/org/apache/ivy/core/settings/ivysettings-vmatcher2.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/core/settings/ivysettings.properties b/test/java/org/apache/ivy/core/settings/ivysettings.properties index a5f53691..8225680f 100644 --- a/test/java/org/apache/ivy/core/settings/ivysettings.properties +++ b/test/java/org/apache/ivy/core/settings/ivysettings.properties @@ -1,19 +1,19 @@ -# *************************************************************** -# * 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. -# *************************************************************** -libraries.dir=lib \ No newline at end of file +# *************************************************************** +# * 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. +# *************************************************************** +libraries.dir=lib diff --git a/test/java/org/apache/ivy/core/sort/SortTest.java b/test/java/org/apache/ivy/core/sort/SortTest.java index d81d4add..bd41550a 100644 --- a/test/java/org/apache/ivy/core/sort/SortTest.java +++ b/test/java/org/apache/ivy/core/sort/SortTest.java @@ -1,336 +1,336 @@ -/* - * 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.core.sort; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.circular.CircularDependencyHelper; -import org.apache.ivy.plugins.circular.CircularDependencyStrategy; - -public class SortTest extends TestCase { - - private DefaultModuleDescriptor md1; - - private DefaultModuleDescriptor md2; - - private DefaultModuleDescriptor md3; - - private DefaultModuleDescriptor md4; - - private static Ivy ivy; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - md1 = createModuleDescriptorToSort("md1", null); // The revison is often not set in the - // ivy.xml file that are ordered - md2 = createModuleDescriptorToSort("md2", "rev2");// But somtimes they are set - md3 = createModuleDescriptorToSort("md3", "rev3"); - md4 = createModuleDescriptorToSort("md4", "rev4"); - - ivy = new Ivy(); - ivy.configureDefault(); - } - - public void testSort() throws Exception { - addDependency(md2, "md1", "rev1"); - addDependency(md3, "md2", "rev2"); - addDependency(md4, "md3", "rev3"); - - DefaultModuleDescriptor[][] expectedOrder = new DefaultModuleDescriptor[][] {{md1, md2, - md3, md4}}; - - Collection permutations = getAllLists(md1, md3, md2, md4); - for (Iterator it = permutations.iterator(); it.hasNext();) { - List toSort = (List) it.next(); - assertSorted(expectedOrder, ivy.sortModuleDescriptors(toSort)); - } - } - - /** - * Sorter does not throw circular dependency, circular dependencies are handled at resolve time - * only. However the sort respect the transitive order when it is unambiguous. (if A depends - * transitively of B, but B doesn't depends transitively on A then B always comes before A). - */ - public void testCircularDependency() throws Exception { - addDependency(md1, "md4", "rev4"); - addDependency(md2, "md1", "rev1"); - addDependency(md3, "md2", "rev2"); - addDependency(md4, "md3", "rev3"); - - DefaultModuleDescriptor[][] possibleOrder = new DefaultModuleDescriptor[][] { - {md2, md3, md4, md1}, {md3, md4, md1, md2}, {md4, md1, md2, md3}, - {md1, md2, md3, md4}}; - - Collection permutations = getAllLists(md1, md3, md2, md4); - for (Iterator it = permutations.iterator(); it.hasNext();) { - List toSort = (List) it.next(); - assertSorted(possibleOrder, ivy.sortModuleDescriptors(toSort)); - } - } - - public void testCircularDependency2() throws Exception { - addDependency(md2, "md3", "rev3"); - addDependency(md2, "md1", "rev1"); - addDependency(md3, "md2", "rev2"); - addDependency(md4, "md3", "rev3"); - DefaultModuleDescriptor[][] possibleOrder = new DefaultModuleDescriptor[][] { - {md1, md3, md2, md4}, {md1, md2, md3, md4} // , - // {md3, md1, md2, md4} //we don't have this solution. The loops apear has one contigous - // element. - }; - Collection permutations = getAllLists(md1, md3, md2, md4); - for (Iterator it = permutations.iterator(); it.hasNext();) { - List toSort = (List) it.next(); - assertSorted(possibleOrder, ivy.sortModuleDescriptors(toSort)); - } - } - - /** - * In case of Circular dependency a warning is generated. - */ - public void testCircularDependencyReport() { - addDependency(md2, "md3", "rev3"); - addDependency(md2, "md1", "rev1"); - addDependency(md3, "md2", "rev2"); - addDependency(md4, "md3", "rev3"); - - // Would be much easier with a tool like jmock - class CircularDependencyReporterMock implements CircularDependencyStrategy { - private int nbOfCall = 0; - - public String getName() { - return "CircularDependencyReporterMock"; - } - - public void handleCircularDependency(ModuleRevisionId[] mrids) { - assertEquals("handleCircularDependency is expected to be called only once", 0, - nbOfCall); - assertTrue("incorrect cicular dependency invocation" - + CircularDependencyHelper.formatMessage(mrids), mrids.length == 3 - && ((mrids[0].equals(md2.getModuleRevisionId()) - && mrids[1].equals(md3.getModuleRevisionId()) && mrids[2] - .equals(md2.getModuleRevisionId())) || (mrids[0].equals(md3 - .getModuleRevisionId()) - && mrids[1].equals(md2.getModuleRevisionId()) && mrids[2] - .equals(md3.getModuleRevisionId())))); - nbOfCall++; - } - - public void validate() { - Assert.assertEquals("handleCircularDependency has nor been called", 1, nbOfCall); - } - } - CircularDependencyReporterMock circularDepReportMock = new CircularDependencyReporterMock(); - ivy.getSettings().setCircularDependencyStrategy(circularDepReportMock); - - List toSort = Arrays.asList(new ModuleDescriptor[] {md4, md3, md2, md1}); - ivy.sortModuleDescriptors(toSort); - - circularDepReportMock.validate(); - } - - /** - * The dependency can ask for the latest integration. It should match whatever the version - * declared in the modules to order. - */ - public void testLatestIntegration() { - - addDependency(md2, "md1", "latest.integration"); - addDependency(md3, "md2", "latest.integration"); - addDependency(md4, "md3", "latest.integration"); - - DefaultModuleDescriptor[][] expectedOrder = new DefaultModuleDescriptor[][] {{md1, md2, - md3, md4}}; - - Collection permutations = getAllLists(md1, md3, md2, md4); - for (Iterator it = permutations.iterator(); it.hasNext();) { - List toSort = (List) it.next(); - assertSorted(expectedOrder, ivy.sortModuleDescriptors(toSort)); - } - - } - - /** - * When the version asked by a dependency is not compatible with the version declared in the - * module to order, the two modules should be considered as independant NB: I'm sure of what - * 'compatible' means ! - */ - public void testDifferentVersionNotConsidered() { - // To test it, I use a 'broken' loop (in one step, I change the revision) in such a way that - // I get only one solution. If the loop was - // complete more solutions where possible. - - addDependency(md1, "md4", "rev4-other"); - addDependency(md2, "md1", "rev1"); - addDependency(md3, "md2", "rev2"); - addDependency(md4, "md3", "rev3"); - - DefaultModuleDescriptor[][] possibleOrder = new DefaultModuleDescriptor[][] {{md1, md2, - md3, md4}}; - - Collection permutations = getAllLists(md1, md3, md2, md4); - for (Iterator it = permutations.iterator(); it.hasNext();) { - List toSort = (List) it.next(); - assertSorted(possibleOrder, ivy.sortModuleDescriptors(toSort)); - } - - } - - /** - * In case of Different version a warning is generated. - */ - public void testDifferentVersionWarning() { - final DependencyDescriptor md4OtherDep = addDependency(md1, "md4", "rev4-other"); - addDependency(md2, "md1", "rev1"); - addDependency(md3, "md2", "rev2"); - addDependency(md4, "md3", "rev3"); - - // Would be much easier with a tool like jmock - class NonMatchingVersionReporterMock implements NonMatchingVersionReporter { - private int nbOfCall = 0; - - public void reportNonMatchingVersion(DependencyDescriptor descriptor, - ModuleDescriptor md) { - Assert.assertEquals("reportNonMatchingVersion should be invokded only once", 0, - nbOfCall); - Assert.assertEquals(md4OtherDep, descriptor); - Assert.assertEquals(md4, md); - nbOfCall++; - } - - public void validate() { - Assert.assertEquals("reportNonMatchingVersion has not be called", 1, nbOfCall); - } - } - NonMatchingVersionReporterMock nonMatchingVersionReporterMock = new NonMatchingVersionReporterMock(); - List toSort = Arrays.asList(new ModuleDescriptor[] {md4, md3, md2, md1}); - ivy.sortModuleDescriptors(toSort, nonMatchingVersionReporterMock); - nonMatchingVersionReporterMock.validate(); - } - - private DefaultModuleDescriptor createModuleDescriptorToSort(String moduleName, String revision) { - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", moduleName, revision); - return new DefaultModuleDescriptor(mrid, "integration", new Date()); - } - - private DependencyDescriptor addDependency(DefaultModuleDescriptor parent, String moduleName, - String revision) { - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", moduleName, revision); - DependencyDescriptor depDescr = new DefaultDependencyDescriptor(parent, mrid, false, false, - true); - parent.addDependency(depDescr); - return depDescr; - } - - /** - * Verifies that sorted in one of the list of listOfPossibleSort. - * - * @param An - * array of possible sort result - * @param The - * actual sortedList to compare - */ - private void assertSorted(DefaultModuleDescriptor[][] listOfPossibleSort, List sorted) { - for (int i = 0; i < listOfPossibleSort.length; i++) { - DefaultModuleDescriptor[] expectedList = listOfPossibleSort[i]; - assertEquals(expectedList.length, sorted.size()); - boolean isExpected = true; - for (int j = 0; j < expectedList.length; j++) { - if (!expectedList[j].equals(sorted.get(j))) { - isExpected = false; - break; - } - } - if (isExpected) { - return; - } - } - // failed, build a nice message - StringBuffer errorMessage = new StringBuffer(); - errorMessage.append("Unexpected order : \n{ "); - for (int i = 0; i < sorted.size(); i++) { - if (i > 0) - errorMessage.append(" , "); - errorMessage.append(((DefaultModuleDescriptor) sorted.get(i)).getModuleRevisionId()); - } - errorMessage.append("}\nEpected : \n"); - for (int i = 0; i < listOfPossibleSort.length; i++) { - DefaultModuleDescriptor[] expectedList = listOfPossibleSort[i]; - if (i > 0) - errorMessage.append(" or\n"); - errorMessage.append("{ "); - for (int j = 0; j < expectedList.length; j++) { - if (j > 0) - errorMessage.append(" , "); - errorMessage.append(expectedList[j].getModuleRevisionId()); - } - errorMessage.append(" } "); - } - fail(errorMessage.toString()); - } - - /** Returns a collection of lists that contains the elements a,b,c and d */ - private Collection getAllLists(Object a, Object b, Object c, Object d) { - ArrayList r = new ArrayList(24); - r.add(Arrays.asList(new Object[] {a, b, c, d})); - r.add(Arrays.asList(new Object[] {a, b, d, c})); - r.add(Arrays.asList(new Object[] {a, c, b, d})); - r.add(Arrays.asList(new Object[] {a, c, d, b})); - r.add(Arrays.asList(new Object[] {a, d, b, c})); - r.add(Arrays.asList(new Object[] {a, d, c, b})); - r.add(Arrays.asList(new Object[] {b, a, c, d})); - r.add(Arrays.asList(new Object[] {b, a, d, c})); - r.add(Arrays.asList(new Object[] {b, c, a, d})); - r.add(Arrays.asList(new Object[] {b, c, d, a})); - r.add(Arrays.asList(new Object[] {b, d, a, c})); - r.add(Arrays.asList(new Object[] {b, d, c, a})); - r.add(Arrays.asList(new Object[] {c, b, a, d})); - r.add(Arrays.asList(new Object[] {c, b, d, a})); - r.add(Arrays.asList(new Object[] {c, a, b, d})); - r.add(Arrays.asList(new Object[] {c, a, d, b})); - r.add(Arrays.asList(new Object[] {c, d, b, a})); - r.add(Arrays.asList(new Object[] {c, d, a, b})); - r.add(Arrays.asList(new Object[] {d, b, c, a})); - r.add(Arrays.asList(new Object[] {d, b, a, c})); - r.add(Arrays.asList(new Object[] {d, c, b, a})); - r.add(Arrays.asList(new Object[] {d, c, a, b})); - r.add(Arrays.asList(new Object[] {d, a, b, c})); - r.add(Arrays.asList(new Object[] {d, a, c, b})); - return r; - } - -} \ No newline at end of file +/* + * 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.core.sort; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.circular.CircularDependencyHelper; +import org.apache.ivy.plugins.circular.CircularDependencyStrategy; + +public class SortTest extends TestCase { + + private DefaultModuleDescriptor md1; + + private DefaultModuleDescriptor md2; + + private DefaultModuleDescriptor md3; + + private DefaultModuleDescriptor md4; + + private static Ivy ivy; + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + md1 = createModuleDescriptorToSort("md1", null); // The revison is often not set in the + // ivy.xml file that are ordered + md2 = createModuleDescriptorToSort("md2", "rev2");// But somtimes they are set + md3 = createModuleDescriptorToSort("md3", "rev3"); + md4 = createModuleDescriptorToSort("md4", "rev4"); + + ivy = new Ivy(); + ivy.configureDefault(); + } + + public void testSort() throws Exception { + addDependency(md2, "md1", "rev1"); + addDependency(md3, "md2", "rev2"); + addDependency(md4, "md3", "rev3"); + + DefaultModuleDescriptor[][] expectedOrder = new DefaultModuleDescriptor[][] {{md1, md2, + md3, md4}}; + + Collection permutations = getAllLists(md1, md3, md2, md4); + for (Iterator it = permutations.iterator(); it.hasNext();) { + List toSort = (List) it.next(); + assertSorted(expectedOrder, ivy.sortModuleDescriptors(toSort)); + } + } + + /** + * Sorter does not throw circular dependency, circular dependencies are handled at resolve time + * only. However the sort respect the transitive order when it is unambiguous. (if A depends + * transitively of B, but B doesn't depends transitively on A then B always comes before A). + */ + public void testCircularDependency() throws Exception { + addDependency(md1, "md4", "rev4"); + addDependency(md2, "md1", "rev1"); + addDependency(md3, "md2", "rev2"); + addDependency(md4, "md3", "rev3"); + + DefaultModuleDescriptor[][] possibleOrder = new DefaultModuleDescriptor[][] { + {md2, md3, md4, md1}, {md3, md4, md1, md2}, {md4, md1, md2, md3}, + {md1, md2, md3, md4}}; + + Collection permutations = getAllLists(md1, md3, md2, md4); + for (Iterator it = permutations.iterator(); it.hasNext();) { + List toSort = (List) it.next(); + assertSorted(possibleOrder, ivy.sortModuleDescriptors(toSort)); + } + } + + public void testCircularDependency2() throws Exception { + addDependency(md2, "md3", "rev3"); + addDependency(md2, "md1", "rev1"); + addDependency(md3, "md2", "rev2"); + addDependency(md4, "md3", "rev3"); + DefaultModuleDescriptor[][] possibleOrder = new DefaultModuleDescriptor[][] { + {md1, md3, md2, md4}, {md1, md2, md3, md4} // , + // {md3, md1, md2, md4} //we don't have this solution. The loops apear has one contigous + // element. + }; + Collection permutations = getAllLists(md1, md3, md2, md4); + for (Iterator it = permutations.iterator(); it.hasNext();) { + List toSort = (List) it.next(); + assertSorted(possibleOrder, ivy.sortModuleDescriptors(toSort)); + } + } + + /** + * In case of Circular dependency a warning is generated. + */ + public void testCircularDependencyReport() { + addDependency(md2, "md3", "rev3"); + addDependency(md2, "md1", "rev1"); + addDependency(md3, "md2", "rev2"); + addDependency(md4, "md3", "rev3"); + + // Would be much easier with a tool like jmock + class CircularDependencyReporterMock implements CircularDependencyStrategy { + private int nbOfCall = 0; + + public String getName() { + return "CircularDependencyReporterMock"; + } + + public void handleCircularDependency(ModuleRevisionId[] mrids) { + assertEquals("handleCircularDependency is expected to be called only once", 0, + nbOfCall); + assertTrue("incorrect cicular dependency invocation" + + CircularDependencyHelper.formatMessage(mrids), mrids.length == 3 + && ((mrids[0].equals(md2.getModuleRevisionId()) + && mrids[1].equals(md3.getModuleRevisionId()) && mrids[2] + .equals(md2.getModuleRevisionId())) || (mrids[0].equals(md3 + .getModuleRevisionId()) + && mrids[1].equals(md2.getModuleRevisionId()) && mrids[2] + .equals(md3.getModuleRevisionId())))); + nbOfCall++; + } + + public void validate() { + Assert.assertEquals("handleCircularDependency has nor been called", 1, nbOfCall); + } + } + CircularDependencyReporterMock circularDepReportMock = new CircularDependencyReporterMock(); + ivy.getSettings().setCircularDependencyStrategy(circularDepReportMock); + + List toSort = Arrays.asList(new ModuleDescriptor[] {md4, md3, md2, md1}); + ivy.sortModuleDescriptors(toSort); + + circularDepReportMock.validate(); + } + + /** + * The dependency can ask for the latest integration. It should match whatever the version + * declared in the modules to order. + */ + public void testLatestIntegration() { + + addDependency(md2, "md1", "latest.integration"); + addDependency(md3, "md2", "latest.integration"); + addDependency(md4, "md3", "latest.integration"); + + DefaultModuleDescriptor[][] expectedOrder = new DefaultModuleDescriptor[][] {{md1, md2, + md3, md4}}; + + Collection permutations = getAllLists(md1, md3, md2, md4); + for (Iterator it = permutations.iterator(); it.hasNext();) { + List toSort = (List) it.next(); + assertSorted(expectedOrder, ivy.sortModuleDescriptors(toSort)); + } + + } + + /** + * When the version asked by a dependency is not compatible with the version declared in the + * module to order, the two modules should be considered as independant NB: I'm sure of what + * 'compatible' means ! + */ + public void testDifferentVersionNotConsidered() { + // To test it, I use a 'broken' loop (in one step, I change the revision) in such a way that + // I get only one solution. If the loop was + // complete more solutions where possible. + + addDependency(md1, "md4", "rev4-other"); + addDependency(md2, "md1", "rev1"); + addDependency(md3, "md2", "rev2"); + addDependency(md4, "md3", "rev3"); + + DefaultModuleDescriptor[][] possibleOrder = new DefaultModuleDescriptor[][] {{md1, md2, + md3, md4}}; + + Collection permutations = getAllLists(md1, md3, md2, md4); + for (Iterator it = permutations.iterator(); it.hasNext();) { + List toSort = (List) it.next(); + assertSorted(possibleOrder, ivy.sortModuleDescriptors(toSort)); + } + + } + + /** + * In case of Different version a warning is generated. + */ + public void testDifferentVersionWarning() { + final DependencyDescriptor md4OtherDep = addDependency(md1, "md4", "rev4-other"); + addDependency(md2, "md1", "rev1"); + addDependency(md3, "md2", "rev2"); + addDependency(md4, "md3", "rev3"); + + // Would be much easier with a tool like jmock + class NonMatchingVersionReporterMock implements NonMatchingVersionReporter { + private int nbOfCall = 0; + + public void reportNonMatchingVersion(DependencyDescriptor descriptor, + ModuleDescriptor md) { + Assert.assertEquals("reportNonMatchingVersion should be invokded only once", 0, + nbOfCall); + Assert.assertEquals(md4OtherDep, descriptor); + Assert.assertEquals(md4, md); + nbOfCall++; + } + + public void validate() { + Assert.assertEquals("reportNonMatchingVersion has not be called", 1, nbOfCall); + } + } + NonMatchingVersionReporterMock nonMatchingVersionReporterMock = new NonMatchingVersionReporterMock(); + List toSort = Arrays.asList(new ModuleDescriptor[] {md4, md3, md2, md1}); + ivy.sortModuleDescriptors(toSort, nonMatchingVersionReporterMock); + nonMatchingVersionReporterMock.validate(); + } + + private DefaultModuleDescriptor createModuleDescriptorToSort(String moduleName, String revision) { + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", moduleName, revision); + return new DefaultModuleDescriptor(mrid, "integration", new Date()); + } + + private DependencyDescriptor addDependency(DefaultModuleDescriptor parent, String moduleName, + String revision) { + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", moduleName, revision); + DependencyDescriptor depDescr = new DefaultDependencyDescriptor(parent, mrid, false, false, + true); + parent.addDependency(depDescr); + return depDescr; + } + + /** + * Verifies that sorted in one of the list of listOfPossibleSort. + * + * @param An + * array of possible sort result + * @param The + * actual sortedList to compare + */ + private void assertSorted(DefaultModuleDescriptor[][] listOfPossibleSort, List sorted) { + for (int i = 0; i < listOfPossibleSort.length; i++) { + DefaultModuleDescriptor[] expectedList = listOfPossibleSort[i]; + assertEquals(expectedList.length, sorted.size()); + boolean isExpected = true; + for (int j = 0; j < expectedList.length; j++) { + if (!expectedList[j].equals(sorted.get(j))) { + isExpected = false; + break; + } + } + if (isExpected) { + return; + } + } + // failed, build a nice message + StringBuffer errorMessage = new StringBuffer(); + errorMessage.append("Unexpected order : \n{ "); + for (int i = 0; i < sorted.size(); i++) { + if (i > 0) + errorMessage.append(" , "); + errorMessage.append(((DefaultModuleDescriptor) sorted.get(i)).getModuleRevisionId()); + } + errorMessage.append("}\nEpected : \n"); + for (int i = 0; i < listOfPossibleSort.length; i++) { + DefaultModuleDescriptor[] expectedList = listOfPossibleSort[i]; + if (i > 0) + errorMessage.append(" or\n"); + errorMessage.append("{ "); + for (int j = 0; j < expectedList.length; j++) { + if (j > 0) + errorMessage.append(" , "); + errorMessage.append(expectedList[j].getModuleRevisionId()); + } + errorMessage.append(" } "); + } + fail(errorMessage.toString()); + } + + /** Returns a collection of lists that contains the elements a,b,c and d */ + private Collection getAllLists(Object a, Object b, Object c, Object d) { + ArrayList r = new ArrayList(24); + r.add(Arrays.asList(new Object[] {a, b, c, d})); + r.add(Arrays.asList(new Object[] {a, b, d, c})); + r.add(Arrays.asList(new Object[] {a, c, b, d})); + r.add(Arrays.asList(new Object[] {a, c, d, b})); + r.add(Arrays.asList(new Object[] {a, d, b, c})); + r.add(Arrays.asList(new Object[] {a, d, c, b})); + r.add(Arrays.asList(new Object[] {b, a, c, d})); + r.add(Arrays.asList(new Object[] {b, a, d, c})); + r.add(Arrays.asList(new Object[] {b, c, a, d})); + r.add(Arrays.asList(new Object[] {b, c, d, a})); + r.add(Arrays.asList(new Object[] {b, d, a, c})); + r.add(Arrays.asList(new Object[] {b, d, c, a})); + r.add(Arrays.asList(new Object[] {c, b, a, d})); + r.add(Arrays.asList(new Object[] {c, b, d, a})); + r.add(Arrays.asList(new Object[] {c, a, b, d})); + r.add(Arrays.asList(new Object[] {c, a, d, b})); + r.add(Arrays.asList(new Object[] {c, d, b, a})); + r.add(Arrays.asList(new Object[] {c, d, a, b})); + r.add(Arrays.asList(new Object[] {d, b, c, a})); + r.add(Arrays.asList(new Object[] {d, b, a, c})); + r.add(Arrays.asList(new Object[] {d, c, b, a})); + r.add(Arrays.asList(new Object[] {d, c, a, b})); + r.add(Arrays.asList(new Object[] {d, a, b, c})); + r.add(Arrays.asList(new Object[] {d, a, c, b})); + return r; + } + +} diff --git a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java index 69c684c4..d29cfad9 100644 --- a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java +++ b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java @@ -1,192 +1,192 @@ -/* - * 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.conflict; - -import java.io.File; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ConfigurationResolveReport; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.IvyNode; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.util.FileUtil; - -public class LatestConflictManagerTest extends TestCase { - - private Ivy ivy; - - private File _cache; - - protected void setUp() throws Exception { - ivy = new Ivy(); - ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest.xml")); - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - FileUtil.forceDelete(_cache); - } - - // Test case for issue IVY-388 - public void testIvy388() throws Exception { - ResolveReport report = ivy.resolve(LatestConflictManagerTest.class - .getResource("ivy-388.xml"), getResolveOptions()); - - List deps = report.getDependencies(); - Iterator dependencies = deps.iterator(); - String[] confs = report.getConfigurations(); - while (dependencies.hasNext()) { - IvyNode node = (IvyNode) dependencies.next(); - for (int i = 0; i < confs.length; i++) { - String conf = confs[i]; - if (!node.isEvicted(conf)) { - boolean flag1 = report.getConfigurationReport(conf).getDependency( - node.getResolvedId()) != null; - boolean flag2 = report.getConfigurationReport(conf).getModuleRevisionIds() - .contains(node.getResolvedId()); - assertEquals("Inconsistent data for node " + node + " in conf " + conf, flag1, - flag2); - } - } - } - } - - // Test case for issue IVY-383 - public void testIvy383() throws Exception { - ResolveReport report = ivy.resolve(LatestConflictManagerTest.class - .getResource("ivy-383.xml"), getResolveOptions()); - ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); - Iterator iter = defaultReport.getModuleRevisionIds().iterator(); - while (iter.hasNext()) { - ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); - if (mrid.getName().equals("mod1.1")) { - assertEquals("1.0", mrid.getRevision()); - } else if (mrid.getName().equals("mod1.2")) { - assertEquals("2.2", mrid.getRevision()); - } - } - } - - // Test case for issue IVY-407 - public void testLatestTime1() throws Exception { - ivy = new Ivy(); - ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml")); - ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); - - // set timestamps, because svn is not preserving this information, - // and the latest time strategy is relying on it - long time = System.currentTimeMillis() - 10000; - new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time); - new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar") - .setLastModified(time + 2000); - - ResolveReport report = ivy.resolve(LatestConflictManagerTest.class - .getResource("ivy-latest-time-1.xml"), getResolveOptions()); - ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); - Iterator iter = defaultReport.getModuleRevisionIds().iterator(); - while (iter.hasNext()) { - ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); - if (mrid.getName().equals("mod1.1")) { - assertEquals("1.0", mrid.getRevision()); - } else if (mrid.getName().equals("mod1.2")) { - assertEquals("2.2", mrid.getRevision()); - } - } - } - - public void testLatestTime2() throws Exception { - ivy = new Ivy(); - ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml")); - ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); - - // set timestamps, because svn is not preserving this information, - // and the latest time strategy is relying on it - long time = System.currentTimeMillis() - 10000; - new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time); - new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar") - .setLastModified(time + 2000); - - ResolveReport report = ivy.resolve(LatestConflictManagerTest.class - .getResource("ivy-latest-time-2.xml"), getResolveOptions()); - ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); - Iterator iter = defaultReport.getModuleRevisionIds().iterator(); - while (iter.hasNext()) { - ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); - if (mrid.getName().equals("mod1.1")) { - assertEquals("1.0", mrid.getRevision()); - } else if (mrid.getName().equals("mod1.2")) { - assertEquals("2.2", mrid.getRevision()); - } - } - } - - /* - * Test case for issue IVY-407 (with transitivity) There are 5 modules A, B, C, D and E. 1) - * publish C-1.0.0, C-1.0.1 and C-1.0.2 2) B needs C-1.0.0 : retrieve ok and publish B-1.0.0 3) - * A needs B-1.0.0 and C-1.0.2 : retrieve ok and publish A-1.0.0 4) D needs C-1.0.1 : retrieve - * ok and publish D-1.0.0 5) E needs D-1.0.0 and A-1.0.0 (D before A in ivy file) retrieve - * failed to get C-1.0.2 from A (get apparently C-1.0.1 from D) - */ - public void testLatestTimeTransitivity() throws Exception { - ivy = new Ivy(); - ivy.configure(LatestConflictManagerTest.class - .getResource("ivysettings-latest-time-transitivity.xml")); - ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); - - // set timestamps, because svn is not preserving this information, - // and the latest time strategy is relying on it - long time = System.currentTimeMillis() - 10000; - new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml").setLastModified(time); - new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml") - .setLastModified(time + 2000); - new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml") - .setLastModified(time + 4000); - - ResolveReport report = ivy.resolve(LatestConflictManagerTest.class - .getResource("ivy-latest-time-transitivity.xml"), getResolveOptions()); - ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); - Iterator iter = defaultReport.getModuleRevisionIds().iterator(); - while (iter.hasNext()) { - ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); - - if (mrid.getName().equals("A")) { - assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision()); - } else if (mrid.getName().equals("D")) { - assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision()); - } - // by transitivity - else if (mrid.getName().equals("B")) { - assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision()); - } else if (mrid.getName().equals("C")) { - assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision()); - } - } - } - - private ResolveOptions getResolveOptions() { - return new ResolveOptions().setCache(CacheManager.getInstance(ivy.getSettings())) - .setValidate(false); - } -} +/* + * 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.conflict; + +import java.io.File; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ConfigurationResolveReport; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.IvyNode; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.util.FileUtil; + +public class LatestConflictManagerTest extends TestCase { + + private Ivy ivy; + + private File _cache; + + protected void setUp() throws Exception { + ivy = new Ivy(); + ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest.xml")); + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + FileUtil.forceDelete(_cache); + } + + // Test case for issue IVY-388 + public void testIvy388() throws Exception { + ResolveReport report = ivy.resolve(LatestConflictManagerTest.class + .getResource("ivy-388.xml"), getResolveOptions()); + + List deps = report.getDependencies(); + Iterator dependencies = deps.iterator(); + String[] confs = report.getConfigurations(); + while (dependencies.hasNext()) { + IvyNode node = (IvyNode) dependencies.next(); + for (int i = 0; i < confs.length; i++) { + String conf = confs[i]; + if (!node.isEvicted(conf)) { + boolean flag1 = report.getConfigurationReport(conf).getDependency( + node.getResolvedId()) != null; + boolean flag2 = report.getConfigurationReport(conf).getModuleRevisionIds() + .contains(node.getResolvedId()); + assertEquals("Inconsistent data for node " + node + " in conf " + conf, flag1, + flag2); + } + } + } + } + + // Test case for issue IVY-383 + public void testIvy383() throws Exception { + ResolveReport report = ivy.resolve(LatestConflictManagerTest.class + .getResource("ivy-383.xml"), getResolveOptions()); + ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); + Iterator iter = defaultReport.getModuleRevisionIds().iterator(); + while (iter.hasNext()) { + ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); + if (mrid.getName().equals("mod1.1")) { + assertEquals("1.0", mrid.getRevision()); + } else if (mrid.getName().equals("mod1.2")) { + assertEquals("2.2", mrid.getRevision()); + } + } + } + + // Test case for issue IVY-407 + public void testLatestTime1() throws Exception { + ivy = new Ivy(); + ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml")); + ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); + + // set timestamps, because svn is not preserving this information, + // and the latest time strategy is relying on it + long time = System.currentTimeMillis() - 10000; + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time); + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar") + .setLastModified(time + 2000); + + ResolveReport report = ivy.resolve(LatestConflictManagerTest.class + .getResource("ivy-latest-time-1.xml"), getResolveOptions()); + ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); + Iterator iter = defaultReport.getModuleRevisionIds().iterator(); + while (iter.hasNext()) { + ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); + if (mrid.getName().equals("mod1.1")) { + assertEquals("1.0", mrid.getRevision()); + } else if (mrid.getName().equals("mod1.2")) { + assertEquals("2.2", mrid.getRevision()); + } + } + } + + public void testLatestTime2() throws Exception { + ivy = new Ivy(); + ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml")); + ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); + + // set timestamps, because svn is not preserving this information, + // and the latest time strategy is relying on it + long time = System.currentTimeMillis() - 10000; + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time); + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar") + .setLastModified(time + 2000); + + ResolveReport report = ivy.resolve(LatestConflictManagerTest.class + .getResource("ivy-latest-time-2.xml"), getResolveOptions()); + ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); + Iterator iter = defaultReport.getModuleRevisionIds().iterator(); + while (iter.hasNext()) { + ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); + if (mrid.getName().equals("mod1.1")) { + assertEquals("1.0", mrid.getRevision()); + } else if (mrid.getName().equals("mod1.2")) { + assertEquals("2.2", mrid.getRevision()); + } + } + } + + /* + * Test case for issue IVY-407 (with transitivity) There are 5 modules A, B, C, D and E. 1) + * publish C-1.0.0, C-1.0.1 and C-1.0.2 2) B needs C-1.0.0 : retrieve ok and publish B-1.0.0 3) + * A needs B-1.0.0 and C-1.0.2 : retrieve ok and publish A-1.0.0 4) D needs C-1.0.1 : retrieve + * ok and publish D-1.0.0 5) E needs D-1.0.0 and A-1.0.0 (D before A in ivy file) retrieve + * failed to get C-1.0.2 from A (get apparently C-1.0.1 from D) + */ + public void testLatestTimeTransitivity() throws Exception { + ivy = new Ivy(); + ivy.configure(LatestConflictManagerTest.class + .getResource("ivysettings-latest-time-transitivity.xml")); + ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true); + + // set timestamps, because svn is not preserving this information, + // and the latest time strategy is relying on it + long time = System.currentTimeMillis() - 10000; + new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml").setLastModified(time); + new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml") + .setLastModified(time + 2000); + new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml") + .setLastModified(time + 4000); + + ResolveReport report = ivy.resolve(LatestConflictManagerTest.class + .getResource("ivy-latest-time-transitivity.xml"), getResolveOptions()); + ConfigurationResolveReport defaultReport = report.getConfigurationReport("default"); + Iterator iter = defaultReport.getModuleRevisionIds().iterator(); + while (iter.hasNext()) { + ModuleRevisionId mrid = (ModuleRevisionId) iter.next(); + + if (mrid.getName().equals("A")) { + assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision()); + } else if (mrid.getName().equals("D")) { + assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision()); + } + // by transitivity + else if (mrid.getName().equals("B")) { + assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision()); + } else if (mrid.getName().equals("C")) { + assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision()); + } + } + } + + private ResolveOptions getResolveOptions() { + return new ResolveOptions().setCache(CacheManager.getInstance(ivy.getSettings())) + .setValidate(false); + } +} diff --git a/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java b/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java index b9ee1a55..061daa29 100644 --- a/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java +++ b/test/java/org/apache/ivy/plugins/conflict/RegexpConflictManagerTest.java @@ -1,83 +1,83 @@ -/* - * 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.conflict; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.util.FileUtil; - -public class RegexpConflictManagerTest extends TestCase { - private Ivy ivy; - - private File _cache; - - protected void setUp() throws Exception { - ivy = new Ivy(); - ivy.configure(RegexpConflictManagerTest.class.getResource("ivysettings-regexp-test.xml")); - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - FileUtil.forceDelete(_cache); - } - - public void testNoApiConflictResolve() throws Exception { - try { - ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-no-regexp-conflict.xml"), - getResolveOptions()); - } catch (StrictConflictException e) { - fail("Unexpected conflict: " + e); - } - } - - public void testConflictResolve() throws Exception { - try { - ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-conflict.xml"), - getResolveOptions()); - - fail("Resolve should have failed with a conflict"); - } catch (StrictConflictException e) { - // this is expected - assertTrue( - "bad exception message: " + e.getMessage(), - e - .getMessage() - .indexOf( - "[ org1 | mod1.2 | 2.0.0 ]:2.0 (needed by [[ apache | resolve-noconflict | 1.0 ]])") != -1); - assertTrue("bad exception message: " + e.getMessage(), e.getMessage().indexOf( - "conflicts with") != -1); - assertTrue( - "bad exception message: " + e.getMessage(), - e - .getMessage() - .indexOf( - "[ org1 | mod1.2 | 2.1.0 ]:2.1 (needed by [[ apache | resolve-noconflict | 1.0 ]])") != -1); - } - } - - private ResolveOptions getResolveOptions() { - return new ResolveOptions().setCache(CacheManager.getInstance(ivy.getSettings())) - .setValidate(false); - } -} \ No newline at end of file +/* + * 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.conflict; + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.util.FileUtil; + +public class RegexpConflictManagerTest extends TestCase { + private Ivy ivy; + + private File _cache; + + protected void setUp() throws Exception { + ivy = new Ivy(); + ivy.configure(RegexpConflictManagerTest.class.getResource("ivysettings-regexp-test.xml")); + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + FileUtil.forceDelete(_cache); + } + + public void testNoApiConflictResolve() throws Exception { + try { + ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-no-regexp-conflict.xml"), + getResolveOptions()); + } catch (StrictConflictException e) { + fail("Unexpected conflict: " + e); + } + } + + public void testConflictResolve() throws Exception { + try { + ivy.resolve(RegexpConflictManagerTest.class.getResource("ivy-conflict.xml"), + getResolveOptions()); + + fail("Resolve should have failed with a conflict"); + } catch (StrictConflictException e) { + // this is expected + assertTrue( + "bad exception message: " + e.getMessage(), + e + .getMessage() + .indexOf( + "[ org1 | mod1.2 | 2.0.0 ]:2.0 (needed by [[ apache | resolve-noconflict | 1.0 ]])") != -1); + assertTrue("bad exception message: " + e.getMessage(), e.getMessage().indexOf( + "conflicts with") != -1); + assertTrue( + "bad exception message: " + e.getMessage(), + e + .getMessage() + .indexOf( + "[ org1 | mod1.2 | 2.1.0 ]:2.1 (needed by [[ apache | resolve-noconflict | 1.0 ]])") != -1); + } + } + + private ResolveOptions getResolveOptions() { + return new ResolveOptions().setCache(CacheManager.getInstance(ivy.getSettings())) + .setValidate(false); + } +} diff --git a/test/java/org/apache/ivy/plugins/conflict/StrictConflictManagerTest.java b/test/java/org/apache/ivy/plugins/conflict/StrictConflictManagerTest.java index 388cc4ed..fbffec7b 100644 --- a/test/java/org/apache/ivy/plugins/conflict/StrictConflictManagerTest.java +++ b/test/java/org/apache/ivy/plugins/conflict/StrictConflictManagerTest.java @@ -1,70 +1,70 @@ -/* - * 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.conflict; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.ivy.util.FileUtil; - -public class StrictConflictManagerTest extends TestCase { - private Ivy ivy; - - private File _cache; - - protected void setUp() throws Exception { - ivy = new Ivy(); - ivy.configure(StrictConflictManagerTest.class.getResource("ivysettings-strict-test.xml")); - _cache = new File("build/cache"); - _cache.mkdirs(); - } - - protected void tearDown() throws Exception { - FileUtil.forceDelete(_cache); - } - - public void testInitFromConf() throws Exception { - ConflictManager cm = ivy.getSettings().getDefaultConflictManager(); - assertTrue(cm instanceof StrictConflictManager); - } - - public void testNoConflictResolve() throws Exception { - ivy.resolve(StrictConflictManagerTest.class.getResource("ivy-noconflict.xml"), - getResolveOptions()); - } - - public void testConflictResolve() throws Exception { - try { - ivy.resolve(StrictConflictManagerTest.class.getResource("ivy-conflict.xml"), - getResolveOptions()); - - fail("Resolve should have failed with a conflict"); - } catch (StrictConflictException e) { - // this is expected - } - } - - private ResolveOptions getResolveOptions() { - return new ResolveOptions().setCache(CacheManager.getInstance(ivy.getSettings())) - .setValidate(false); - } -} +/* + * 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.conflict; + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.ivy.util.FileUtil; + +public class StrictConflictManagerTest extends TestCase { + private Ivy ivy; + + private File _cache; + + protected void setUp() throws Exception { + ivy = new Ivy(); + ivy.configure(StrictConflictManagerTest.class.getResource("ivysettings-strict-test.xml")); + _cache = new File("build/cache"); + _cache.mkdirs(); + } + + protected void tearDown() throws Exception { + FileUtil.forceDelete(_cache); + } + + public void testInitFromConf() throws Exception { + ConflictManager cm = ivy.getSettings().getDefaultConflictManager(); + assertTrue(cm instanceof StrictConflictManager); + } + + public void testNoConflictResolve() throws Exception { + ivy.resolve(StrictConflictManagerTest.class.getResource("ivy-noconflict.xml"), + getResolveOptions()); + } + + public void testConflictResolve() throws Exception { + try { + ivy.resolve(StrictConflictManagerTest.class.getResource("ivy-conflict.xml"), + getResolveOptions()); + + fail("Resolve should have failed with a conflict"); + } catch (StrictConflictException e) { + // this is expected + } + } + + private ResolveOptions getResolveOptions() { + return new ResolveOptions().setCache(CacheManager.getInstance(ivy.getSettings())) + .setValidate(false); + } +} diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-383.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-383.xml index dc0dd2a7..0e66bc99 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-383.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-383.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-388.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-388.xml index 3456d096..5c3c33fa 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-388.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-388.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-conflict.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-conflict.xml index ba8579be..6311403d 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-conflict.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-conflict.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-1.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-1.xml index 9fdbf3e7..82cfb918 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-1.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-1.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-2.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-2.xml index 8bd3b7df..4caa68e0 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-2.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-2.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-transitivity.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-transitivity.xml index 8220ab97..f4d2d5f7 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-transitivity.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-latest-time-transitivity.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-no-regexp-conflict.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-no-regexp-conflict.xml index 1c794fa1..11e6eb59 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-no-regexp-conflict.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-no-regexp-conflict.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivy-noconflict.xml b/test/java/org/apache/ivy/plugins/conflict/ivy-noconflict.xml index 4d8884f7..53179af8 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivy-noconflict.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivy-noconflict.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time-transitivity.xml b/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time-transitivity.xml index 9ad0ee2e..7fe873cf 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time-transitivity.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time-transitivity.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time.xml b/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time.xml index 0fb79534..c58ac781 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest-time.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest.xml b/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest.xml index c8c1357f..3161653f 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivysettings-latest.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivysettings-regexp-test.xml b/test/java/org/apache/ivy/plugins/conflict/ivysettings-regexp-test.xml index 6c0fde73..c2987197 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivysettings-regexp-test.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivysettings-regexp-test.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/conflict/ivysettings-strict-test.xml b/test/java/org/apache/ivy/plugins/conflict/ivysettings-strict-test.xml index d8464e20..95818a57 100644 --- a/test/java/org/apache/ivy/plugins/conflict/ivysettings-strict-test.xml +++ b/test/java/org/apache/ivy/plugins/conflict/ivysettings-strict-test.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java b/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java index ae015ed3..1de80ea2 100644 --- a/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java +++ b/test/java/org/apache/ivy/plugins/latest/LatestRevisionStrategyTest.java @@ -1,120 +1,120 @@ -/* - * 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.latest; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import junit.framework.TestCase; - -public class LatestRevisionStrategyTest extends TestCase { - public void testComparator() { - ArtifactInfo[] revs = toMockAI(new String[] {"0.2a", "0.2_b", "0.2rc1", "0.2-final", - "1.0-dev1", "1.0-dev2", "1.0-alpha1", "1.0-alpha2", "1.0-beta1", "1.0-beta2", - "1.0-gamma", "1.0-rc1", "1.0-rc2", "1.0", "1.0.1", "2.0"}); - - List shuffled = new ArrayList(Arrays.asList(revs)); - Collections.shuffle(shuffled); - Collections.sort(shuffled, new LatestRevisionStrategy().COMPARATOR); - assertEquals(Arrays.asList(revs), shuffled); - } - - public void testSort() { - ArtifactInfo[] revs = toMockAI(new String[] {"0.2a", "0.2_b", "0.2rc1", "0.2-final", - "1.0-dev1", "1.0-dev2", "1.0-alpha1", "1.0-alpha2", "1.0-beta1", "1.0-beta2", - "1.0-gamma", "1.0-rc1", "1.0-rc2", "1.0", "1.0.1", "2.0"}); - - List shuffled = new ArrayList(Arrays.asList(revs)); - ArtifactInfo[] shuffledRevs = (ArtifactInfo[]) shuffled - .toArray(new ArtifactInfo[revs.length]); - - LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); - List sorted = latestRevisionStrategy.sort(shuffledRevs); - assertEquals(Arrays.asList(revs), sorted); - } - - public void testFindLatest() { - ArtifactInfo[] revs = toMockAI(new String[] {"0.2a", "0.2_b", "0.2rc1", "0.2-final", - "1.0-dev1", "1.0-dev2", "1.0-alpha1", "1.0-alpha2", "1.0-beta1", "1.0-beta2", - "1.0-gamma", "1.0-rc1", "1.0-rc2", "1.0", "1.0.1", "2.0"}); - - List shuffled = new ArrayList(Arrays.asList(revs)); - ArtifactInfo[] shuffledRevs = (ArtifactInfo[]) shuffled - .toArray(new ArtifactInfo[revs.length]); - - LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); - ArtifactInfo latest = latestRevisionStrategy.findLatest(shuffledRevs, new Date()); - assertNotNull(latest); - assertEquals("2.0", latest.getRevision()); - } - - public void testSpecialMeaningComparator() { - ArtifactInfo[] revs = toMockAI(new String[] {"0.1", "0.2-pre", "0.2-dev", "0.2-rc1", - "0.2-final", "0.2-QA", "1.0-dev1",}); - - List shuffled = new ArrayList(Arrays.asList(revs)); - Collections.shuffle(shuffled); - LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); - LatestRevisionStrategy.SpecialMeaning specialMeaning = new LatestRevisionStrategy.SpecialMeaning(); - specialMeaning.setName("pre"); - specialMeaning.setValue(new Integer(-2)); - latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning); - specialMeaning = new LatestRevisionStrategy.SpecialMeaning(); - specialMeaning.setName("QA"); - specialMeaning.setValue(new Integer(4)); - latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning); - Collections.sort(shuffled, latestRevisionStrategy.COMPARATOR); - assertEquals(Arrays.asList(revs), shuffled); - } - - private static class MockArtifactInfo implements ArtifactInfo { - - private long _lastModified; - - private String _rev; - - public MockArtifactInfo(String rev, long lastModified) { - _rev = rev; - _lastModified = lastModified; - } - - public String getRevision() { - return _rev; - } - - public long getLastModified() { - return _lastModified; - } - - public String toString() { - return _rev; - } - } - - private ArtifactInfo[] toMockAI(String[] revs) { - ArtifactInfo[] artifactInfos = new ArtifactInfo[revs.length]; - for (int i = 0; i < artifactInfos.length; i++) { - artifactInfos[i] = new MockArtifactInfo(revs[i], 0); - } - return artifactInfos; - } - -} +/* + * 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.latest; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import junit.framework.TestCase; + +public class LatestRevisionStrategyTest extends TestCase { + public void testComparator() { + ArtifactInfo[] revs = toMockAI(new String[] {"0.2a", "0.2_b", "0.2rc1", "0.2-final", + "1.0-dev1", "1.0-dev2", "1.0-alpha1", "1.0-alpha2", "1.0-beta1", "1.0-beta2", + "1.0-gamma", "1.0-rc1", "1.0-rc2", "1.0", "1.0.1", "2.0"}); + + List shuffled = new ArrayList(Arrays.asList(revs)); + Collections.shuffle(shuffled); + Collections.sort(shuffled, new LatestRevisionStrategy().COMPARATOR); + assertEquals(Arrays.asList(revs), shuffled); + } + + public void testSort() { + ArtifactInfo[] revs = toMockAI(new String[] {"0.2a", "0.2_b", "0.2rc1", "0.2-final", + "1.0-dev1", "1.0-dev2", "1.0-alpha1", "1.0-alpha2", "1.0-beta1", "1.0-beta2", + "1.0-gamma", "1.0-rc1", "1.0-rc2", "1.0", "1.0.1", "2.0"}); + + List shuffled = new ArrayList(Arrays.asList(revs)); + ArtifactInfo[] shuffledRevs = (ArtifactInfo[]) shuffled + .toArray(new ArtifactInfo[revs.length]); + + LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); + List sorted = latestRevisionStrategy.sort(shuffledRevs); + assertEquals(Arrays.asList(revs), sorted); + } + + public void testFindLatest() { + ArtifactInfo[] revs = toMockAI(new String[] {"0.2a", "0.2_b", "0.2rc1", "0.2-final", + "1.0-dev1", "1.0-dev2", "1.0-alpha1", "1.0-alpha2", "1.0-beta1", "1.0-beta2", + "1.0-gamma", "1.0-rc1", "1.0-rc2", "1.0", "1.0.1", "2.0"}); + + List shuffled = new ArrayList(Arrays.asList(revs)); + ArtifactInfo[] shuffledRevs = (ArtifactInfo[]) shuffled + .toArray(new ArtifactInfo[revs.length]); + + LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); + ArtifactInfo latest = latestRevisionStrategy.findLatest(shuffledRevs, new Date()); + assertNotNull(latest); + assertEquals("2.0", latest.getRevision()); + } + + public void testSpecialMeaningComparator() { + ArtifactInfo[] revs = toMockAI(new String[] {"0.1", "0.2-pre", "0.2-dev", "0.2-rc1", + "0.2-final", "0.2-QA", "1.0-dev1",}); + + List shuffled = new ArrayList(Arrays.asList(revs)); + Collections.shuffle(shuffled); + LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy(); + LatestRevisionStrategy.SpecialMeaning specialMeaning = new LatestRevisionStrategy.SpecialMeaning(); + specialMeaning.setName("pre"); + specialMeaning.setValue(new Integer(-2)); + latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning); + specialMeaning = new LatestRevisionStrategy.SpecialMeaning(); + specialMeaning.setName("QA"); + specialMeaning.setValue(new Integer(4)); + latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning); + Collections.sort(shuffled, latestRevisionStrategy.COMPARATOR); + assertEquals(Arrays.asList(revs), shuffled); + } + + private static class MockArtifactInfo implements ArtifactInfo { + + private long _lastModified; + + private String _rev; + + public MockArtifactInfo(String rev, long lastModified) { + _rev = rev; + _lastModified = lastModified; + } + + public String getRevision() { + return _rev; + } + + public long getLastModified() { + return _lastModified; + } + + public String toString() { + return _rev; + } + } + + private ArtifactInfo[] toMockAI(String[] revs) { + ArtifactInfo[] artifactInfos = new ArtifactInfo[revs.length]; + for (int i = 0; i < artifactInfos.length; i++) { + artifactInfos[i] = new MockArtifactInfo(revs[i], 0); + } + return artifactInfos; + } + +} diff --git a/test/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcherTest.java b/test/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcherTest.java index 04156abc..29260e03 100644 --- a/test/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcherTest.java +++ b/test/java/org/apache/ivy/plugins/matcher/AbstractPatternMatcherTest.java @@ -1,96 +1,96 @@ -/* - * 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.matcher; - -import junit.framework.TestCase; - -/** - * Base test classes for PatternMatcher testcase implementation - */ -public abstract class AbstractPatternMatcherTest extends TestCase { - protected PatternMatcher patternMatcher; - - protected boolean exact; - - protected abstract void setUp() throws Exception; - - protected void setUp(PatternMatcher matcher, boolean exact) { - this.patternMatcher = matcher; - this.exact = exact; - } - - public void testAnyExpression() { - Matcher matcher = patternMatcher.getMatcher("*"); - assertTrue(matcher.matches("")); - assertTrue(matcher.matches("We shall transcend borders. The new is old.")); - assertTrue(matcher.matches(" ")); - } - - public void testIsExact() { - Matcher matcher = patternMatcher.getMatcher("*"); - assertEquals(false, matcher.isExact()); - matcher.matches("The words aren't what they were."); - assertEquals(false, matcher.isExact()); - - matcher = patternMatcher.getMatcher("some expression"); - assertEquals(exact, matcher.isExact()); - matcher.matches("The words aren't what they were."); - assertEquals(exact, matcher.isExact()); - } - - public void testNullInput() { - Matcher matcher = patternMatcher.getMatcher("some expression"); - try { - matcher.matches(null); - fail("Should fail for null input"); - } catch (NullPointerException expected) { - - } - } - - public void testNullExpression() { - try { - Matcher matcher = patternMatcher.getMatcher(null); - fail("Should fail for null expression"); - } catch (NullPointerException expected) { - - } - } - - public abstract void testImplementation(); - - public void testLoadTestMatches() { - Matcher matcher = patternMatcher.getMatcher("this.is.an.expression"); - String[] inputs = {"this.is.an.expression", "this:is:an:expression", - "this is an expression", "whatever this is", "maybe, maybe not"}; - for (int i = 0; i < 100000; i++) { - String input = inputs[i % inputs.length]; - boolean success = matcher.matches(input); - } - } - - public void testLoadTestGetMatcher() { - String[] inputs = {"this.is.an.expression", "this:is:an:expression", - "this is an expression", "whatever this is", "maybe, maybe not"}; - - for (int i = 0; i < 100000; i++) { - String expression = inputs[i % inputs.length]; - Matcher matcher = patternMatcher.getMatcher(expression); - } - } -} +/* + * 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.matcher; + +import junit.framework.TestCase; + +/** + * Base test classes for PatternMatcher testcase implementation + */ +public abstract class AbstractPatternMatcherTest extends TestCase { + protected PatternMatcher patternMatcher; + + protected boolean exact; + + protected abstract void setUp() throws Exception; + + protected void setUp(PatternMatcher matcher, boolean exact) { + this.patternMatcher = matcher; + this.exact = exact; + } + + public void testAnyExpression() { + Matcher matcher = patternMatcher.getMatcher("*"); + assertTrue(matcher.matches("")); + assertTrue(matcher.matches("We shall transcend borders. The new is old.")); + assertTrue(matcher.matches(" ")); + } + + public void testIsExact() { + Matcher matcher = patternMatcher.getMatcher("*"); + assertEquals(false, matcher.isExact()); + matcher.matches("The words aren't what they were."); + assertEquals(false, matcher.isExact()); + + matcher = patternMatcher.getMatcher("some expression"); + assertEquals(exact, matcher.isExact()); + matcher.matches("The words aren't what they were."); + assertEquals(exact, matcher.isExact()); + } + + public void testNullInput() { + Matcher matcher = patternMatcher.getMatcher("some expression"); + try { + matcher.matches(null); + fail("Should fail for null input"); + } catch (NullPointerException expected) { + + } + } + + public void testNullExpression() { + try { + Matcher matcher = patternMatcher.getMatcher(null); + fail("Should fail for null expression"); + } catch (NullPointerException expected) { + + } + } + + public abstract void testImplementation(); + + public void testLoadTestMatches() { + Matcher matcher = patternMatcher.getMatcher("this.is.an.expression"); + String[] inputs = {"this.is.an.expression", "this:is:an:expression", + "this is an expression", "whatever this is", "maybe, maybe not"}; + for (int i = 0; i < 100000; i++) { + String input = inputs[i % inputs.length]; + boolean success = matcher.matches(input); + } + } + + public void testLoadTestGetMatcher() { + String[] inputs = {"this.is.an.expression", "this:is:an:expression", + "this is an expression", "whatever this is", "maybe, maybe not"}; + + for (int i = 0; i < 100000; i++) { + String expression = inputs[i % inputs.length]; + Matcher matcher = patternMatcher.getMatcher(expression); + } + } +} diff --git a/test/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcherTest.java b/test/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcherTest.java index f5ca7161..d22066e1 100644 --- a/test/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcherTest.java +++ b/test/java/org/apache/ivy/plugins/matcher/ExactOrRegexpPatternMatcherTest.java @@ -1,51 +1,51 @@ -/* - * 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.matcher; - -import java.util.regex.PatternSyntaxException; - -/** - * - */ -public class ExactOrRegexpPatternMatcherTest extends AbstractPatternMatcherTest { - - protected void setUp() throws Exception { - setUp(new ExactOrRegexpPatternMatcher(), false); - } - - public void testImplementation() { - Matcher matcher = patternMatcher.getMatcher("."); - assertFalse(matcher.matches("")); - assertTrue("Exact match failed", matcher.matches(".")); - assertTrue("Regexp match failed", matcher.matches("a")); - assertFalse(matcher.matches("aa")); - - matcher = patternMatcher.getMatcher(".*"); - assertTrue("Exact match failed", matcher.matches(".*")); - assertTrue("Regexp match failed", matcher.matches("")); - assertTrue(matcher.matches("a")); - assertTrue(matcher.matches("aa")); - - try { - matcher = patternMatcher.getMatcher("("); - fail("Should fail on invalid regexp syntax"); - } catch (PatternSyntaxException e) { - - } - } -} +/* + * 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.matcher; + +import java.util.regex.PatternSyntaxException; + +/** + * + */ +public class ExactOrRegexpPatternMatcherTest extends AbstractPatternMatcherTest { + + protected void setUp() throws Exception { + setUp(new ExactOrRegexpPatternMatcher(), false); + } + + public void testImplementation() { + Matcher matcher = patternMatcher.getMatcher("."); + assertFalse(matcher.matches("")); + assertTrue("Exact match failed", matcher.matches(".")); + assertTrue("Regexp match failed", matcher.matches("a")); + assertFalse(matcher.matches("aa")); + + matcher = patternMatcher.getMatcher(".*"); + assertTrue("Exact match failed", matcher.matches(".*")); + assertTrue("Regexp match failed", matcher.matches("")); + assertTrue(matcher.matches("a")); + assertTrue(matcher.matches("aa")); + + try { + matcher = patternMatcher.getMatcher("("); + fail("Should fail on invalid regexp syntax"); + } catch (PatternSyntaxException e) { + + } + } +} diff --git a/test/java/org/apache/ivy/plugins/matcher/ExactPatternMatcherTest.java b/test/java/org/apache/ivy/plugins/matcher/ExactPatternMatcherTest.java index 7413f051..8374a481 100644 --- a/test/java/org/apache/ivy/plugins/matcher/ExactPatternMatcherTest.java +++ b/test/java/org/apache/ivy/plugins/matcher/ExactPatternMatcherTest.java @@ -1,36 +1,36 @@ -/* - * 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.matcher; - -/** - * @see ExactPatternMatcher - */ -public class ExactPatternMatcherTest extends AbstractPatternMatcherTest { - - protected void setUp() throws Exception { - setUp(new ExactPatternMatcher(), true); - } - - public void testImplementation() { - Matcher matcher = patternMatcher.getMatcher("."); - assertFalse(matcher.matches("")); - assertTrue(matcher.matches(".")); - assertFalse(matcher.matches("a")); - assertFalse(matcher.matches("aa")); - } -} +/* + * 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.matcher; + +/** + * @see ExactPatternMatcher + */ +public class ExactPatternMatcherTest extends AbstractPatternMatcherTest { + + protected void setUp() throws Exception { + setUp(new ExactPatternMatcher(), true); + } + + public void testImplementation() { + Matcher matcher = patternMatcher.getMatcher("."); + assertFalse(matcher.matches("")); + assertTrue(matcher.matches(".")); + assertFalse(matcher.matches("a")); + assertFalse(matcher.matches("aa")); + } +} diff --git a/test/java/org/apache/ivy/plugins/matcher/GlobPatternMatcherTest.java b/test/java/org/apache/ivy/plugins/matcher/GlobPatternMatcherTest.java index a786f1cf..2bb45015 100644 --- a/test/java/org/apache/ivy/plugins/matcher/GlobPatternMatcherTest.java +++ b/test/java/org/apache/ivy/plugins/matcher/GlobPatternMatcherTest.java @@ -1,80 +1,80 @@ -/* - * 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.matcher; - -import java.util.regex.PatternSyntaxException; - -/** - * @see GlobPatternMatcher - */ -public class GlobPatternMatcherTest extends AbstractPatternMatcherTest { - - protected void setUp() throws Exception { - setUp(new GlobPatternMatcher(), false); - } - - public void testValidRegexpSyntaxAsNormalCharacter() { - Matcher matcher = patternMatcher.getMatcher("."); - assertFalse(matcher.matches("")); - assertTrue(matcher.matches(".")); - assertFalse(matcher.matches("a")); - assertFalse(matcher.matches("aa")); - } - - public void testRegexpSyntaxAndGlob() { - Matcher matcher = patternMatcher.getMatcher(".*"); - assertTrue(matcher.matches(".*")); - assertFalse(matcher.matches("")); - assertFalse(matcher.matches("a")); - assertTrue(matcher.matches(".a")); - assertFalse(matcher.matches("abcdef")); - assertTrue(matcher.matches(".abcdef")); - } - - public void testImplementation() { - } - - public void testQuoteMeta() { - Matcher matcher = patternMatcher.getMatcher("\\*"); - assertTrue(matcher.matches("*")); - assertFalse(matcher.matches("X")); - assertFalse(matcher.matches("Xsfsdfsd")); - } - - public void testInvalidRegexpSyntaxAsNormalCharacter() { - Matcher matcher = patternMatcher.getMatcher("("); - assertTrue(matcher.matches("(")); - } - - public void testGlob() { - Matcher matcher = patternMatcher.getMatcher("*ivy*"); - assertTrue(matcher.matches("ivy")); - assertTrue(matcher.matches("abcdefivyuvw")); - assertTrue(matcher.matches("ivyuvw")); - assertTrue(matcher.matches("abcdefivy")); - } - - public void testInvalidSyntax() { - try { - Matcher matcher = patternMatcher.getMatcher("["); - fail("Should fail on invalid regexp syntax"); - } catch (PatternSyntaxException e) { - - } - } -} +/* + * 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.matcher; + +import java.util.regex.PatternSyntaxException; + +/** + * @see GlobPatternMatcher + */ +public class GlobPatternMatcherTest extends AbstractPatternMatcherTest { + + protected void setUp() throws Exception { + setUp(new GlobPatternMatcher(), false); + } + + public void testValidRegexpSyntaxAsNormalCharacter() { + Matcher matcher = patternMatcher.getMatcher("."); + assertFalse(matcher.matches("")); + assertTrue(matcher.matches(".")); + assertFalse(matcher.matches("a")); + assertFalse(matcher.matches("aa")); + } + + public void testRegexpSyntaxAndGlob() { + Matcher matcher = patternMatcher.getMatcher(".*"); + assertTrue(matcher.matches(".*")); + assertFalse(matcher.matches("")); + assertFalse(matcher.matches("a")); + assertTrue(matcher.matches(".a")); + assertFalse(matcher.matches("abcdef")); + assertTrue(matcher.matches(".abcdef")); + } + + public void testImplementation() { + } + + public void testQuoteMeta() { + Matcher matcher = patternMatcher.getMatcher("\\*"); + assertTrue(matcher.matches("*")); + assertFalse(matcher.matches("X")); + assertFalse(matcher.matches("Xsfsdfsd")); + } + + public void testInvalidRegexpSyntaxAsNormalCharacter() { + Matcher matcher = patternMatcher.getMatcher("("); + assertTrue(matcher.matches("(")); + } + + public void testGlob() { + Matcher matcher = patternMatcher.getMatcher("*ivy*"); + assertTrue(matcher.matches("ivy")); + assertTrue(matcher.matches("abcdefivyuvw")); + assertTrue(matcher.matches("ivyuvw")); + assertTrue(matcher.matches("abcdefivy")); + } + + public void testInvalidSyntax() { + try { + Matcher matcher = patternMatcher.getMatcher("["); + fail("Should fail on invalid regexp syntax"); + } catch (PatternSyntaxException e) { + + } + } +} diff --git a/test/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcherTest.java b/test/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcherTest.java index 0d3a9e22..17064bd0 100644 --- a/test/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcherTest.java +++ b/test/java/org/apache/ivy/plugins/matcher/RegexpPatternMatcherTest.java @@ -1,45 +1,45 @@ -/* - * 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.matcher; - -import java.util.regex.PatternSyntaxException; - -/** - * @see RegexpPatternMatcher - */ -public class RegexpPatternMatcherTest extends AbstractPatternMatcherTest { - - protected void setUp() throws Exception { - setUp(new RegexpPatternMatcher(), false); - } - - public void testImplementation() { - Matcher matcher = patternMatcher.getMatcher(".*"); - assertTrue(matcher.matches(".*")); - assertTrue(matcher.matches("")); - assertTrue(matcher.matches("a")); - assertTrue(matcher.matches("aa")); - - try { - matcher = patternMatcher.getMatcher("("); - fail("Should fail on invalid syntax"); - } catch (PatternSyntaxException e) { - - } - } -} +/* + * 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.matcher; + +import java.util.regex.PatternSyntaxException; + +/** + * @see RegexpPatternMatcher + */ +public class RegexpPatternMatcherTest extends AbstractPatternMatcherTest { + + protected void setUp() throws Exception { + setUp(new RegexpPatternMatcher(), false); + } + + public void testImplementation() { + Matcher matcher = patternMatcher.getMatcher(".*"); + assertTrue(matcher.matches(".*")); + assertTrue(matcher.matches("")); + assertTrue(matcher.matches("a")); + assertTrue(matcher.matches("aa")); + + try { + matcher = patternMatcher.getMatcher("("); + fail("Should fail on invalid syntax"); + } catch (PatternSyntaxException e) { + + } + } +} diff --git a/test/java/org/apache/ivy/plugins/namespace/MRIDTransformationRuleTest.java b/test/java/org/apache/ivy/plugins/namespace/MRIDTransformationRuleTest.java index 33be0a80..4e10675a 100644 --- a/test/java/org/apache/ivy/plugins/namespace/MRIDTransformationRuleTest.java +++ b/test/java/org/apache/ivy/plugins/namespace/MRIDTransformationRuleTest.java @@ -1,54 +1,54 @@ -/* - * 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.namespace; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class MRIDTransformationRuleTest extends TestCase { - - public void testTransformation() { - MRIDTransformationRule r = new MRIDTransformationRule(); - r.addSrc(new MRIDRule("apache", "commons.+", null)); - r.addDest(new MRIDRule("$m0", "$m0", null)); - - assertEquals(ModuleRevisionId.newInstance("commons-client", "commons-client", "1.0"), r - .transform(ModuleRevisionId.newInstance("apache", "commons-client", "1.0"))); - assertEquals(ModuleRevisionId.newInstance("apache", "module", "1.0"), r - .transform(ModuleRevisionId.newInstance("apache", "module", "1.0"))); - - r = new MRIDTransformationRule(); - r.addSrc(new MRIDRule(null, "commons\\-(.+)", null)); - r.addDest(new MRIDRule("$o0.commons", "$m1", null)); - - assertEquals(ModuleRevisionId.newInstance("apache.commons", "client", "1.0"), r - .transform(ModuleRevisionId.newInstance("apache", "commons-client", "1.0"))); - assertEquals(ModuleRevisionId.newInstance("apache", "module", "1.0"), r - .transform(ModuleRevisionId.newInstance("apache", "module", "1.0"))); - - r = new MRIDTransformationRule(); - r.addSrc(new MRIDRule("(.+)\\.(.+)", ".+", null)); - r.addDest(new MRIDRule("$o1", "$o2-$m0", null)); - - assertEquals(ModuleRevisionId.newInstance("apache", "commons-client", "1.0"), r - .transform(ModuleRevisionId.newInstance("apache.commons", "client", "1.0"))); - assertEquals(ModuleRevisionId.newInstance("apache", "module", "1.0"), r - .transform(ModuleRevisionId.newInstance("apache", "module", "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. + * + */ +package org.apache.ivy.plugins.namespace; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class MRIDTransformationRuleTest extends TestCase { + + public void testTransformation() { + MRIDTransformationRule r = new MRIDTransformationRule(); + r.addSrc(new MRIDRule("apache", "commons.+", null)); + r.addDest(new MRIDRule("$m0", "$m0", null)); + + assertEquals(ModuleRevisionId.newInstance("commons-client", "commons-client", "1.0"), r + .transform(ModuleRevisionId.newInstance("apache", "commons-client", "1.0"))); + assertEquals(ModuleRevisionId.newInstance("apache", "module", "1.0"), r + .transform(ModuleRevisionId.newInstance("apache", "module", "1.0"))); + + r = new MRIDTransformationRule(); + r.addSrc(new MRIDRule(null, "commons\\-(.+)", null)); + r.addDest(new MRIDRule("$o0.commons", "$m1", null)); + + assertEquals(ModuleRevisionId.newInstance("apache.commons", "client", "1.0"), r + .transform(ModuleRevisionId.newInstance("apache", "commons-client", "1.0"))); + assertEquals(ModuleRevisionId.newInstance("apache", "module", "1.0"), r + .transform(ModuleRevisionId.newInstance("apache", "module", "1.0"))); + + r = new MRIDTransformationRule(); + r.addSrc(new MRIDRule("(.+)\\.(.+)", ".+", null)); + r.addDest(new MRIDRule("$o1", "$o2-$m0", null)); + + assertEquals(ModuleRevisionId.newInstance("apache", "commons-client", "1.0"), r + .transform(ModuleRevisionId.newInstance("apache.commons", "client", "1.0"))); + assertEquals(ModuleRevisionId.newInstance("apache", "module", "1.0"), r + .transform(ModuleRevisionId.newInstance("apache", "module", "1.0"))); + } +} diff --git a/test/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParserTester.java b/test/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParserTester.java index 03c0ba6b..f4004545 100644 --- a/test/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParserTester.java +++ b/test/java/org/apache/ivy/plugins/parser/AbstractModuleDescriptorParserTester.java @@ -1,143 +1,143 @@ -/* - * 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.parser; - -import java.util.Arrays; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ExcludeRule; -import org.apache.ivy.core.module.descriptor.IncludeRule; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.descriptor.Configuration.Visibility; - -public abstract class AbstractModuleDescriptorParserTester extends TestCase { - protected DependencyDescriptor getDependency(DependencyDescriptor[] dependencies, String name) { - for (int i = 0; i < dependencies.length; i++) { - assertNotNull(dependencies[i]); - assertNotNull(dependencies[i].getDependencyId()); - if (name.equals(dependencies[i].getDependencyId().getName())) { - return dependencies[i]; - } - } - return null; - } - - protected void assertArtifacts(Artifact[] artifacts, String[] artifactsNames) { - assertNotNull(artifacts); - assertEquals(artifactsNames.length, artifacts.length); - for (int i = 0; i < artifactsNames.length; i++) { - boolean found = false; - for (int j = 0; j < artifacts.length; j++) { - assertNotNull(artifacts[j]); - if (artifacts[j].getName().equals(artifactsNames[i])) { - found = true; - break; - } - } - assertTrue("artifact not found: " + artifactsNames[i], found); - } - } - - protected void assertDependencyArtifacts(DependencyDescriptor dd, String[] confs, - String[] artifactsNames) { - DependencyArtifactDescriptor[] dads = dd.getDependencyArtifacts(confs); - assertNotNull(dads); - assertEquals(artifactsNames.length, dads.length); - for (int i = 0; i < artifactsNames.length; i++) { - boolean found = false; - for (int j = 0; j < dads.length; j++) { - assertNotNull(dads[j]); - if (dads[j].getName().equals(artifactsNames[i])) { - found = true; - break; - } - } - assertTrue("dependency artifact not found: " + artifactsNames[i], found); - } - } - - protected void assertDependencyArtifactIncludeRules(DependencyDescriptor dd, String[] confs, - String[] artifactsNames) { - IncludeRule[] dads = dd.getIncludeRules(confs); - assertNotNull(dads); - assertEquals(artifactsNames.length, dads.length); - for (int i = 0; i < artifactsNames.length; i++) { - boolean found = false; - for (int j = 0; j < dads.length; j++) { - assertNotNull(dads[j]); - if (dads[j].getId().getName().equals(artifactsNames[i])) { - found = true; - break; - } - } - assertTrue("dependency include not found: " + artifactsNames[i], found); - } - } - - protected void assertDependencyArtifactExcludeRules(DependencyDescriptor dd, String[] confs, - String[] artifactsNames) { - ExcludeRule[] rules = dd.getExcludeRules(confs); - assertNotNull(rules); - assertEquals(artifactsNames.length, rules.length); - for (int i = 0; i < artifactsNames.length; i++) { - boolean found = false; - for (int j = 0; j < rules.length; j++) { - assertNotNull(rules[j]); - if (rules[j].getId().getName().equals(artifactsNames[i])) { - found = true; - break; - } - } - assertTrue("dependency exclude not found: " + artifactsNames[i], found); - } - } - - protected void assertDependencyModulesExcludes(DependencyDescriptor dd, String[] confs, - String[] moduleNames) { - ExcludeRule[] rules = dd.getExcludeRules(confs); - assertNotNull(rules); - assertEquals(moduleNames.length, rules.length); - for (int i = 0; i < moduleNames.length; i++) { - boolean found = false; - for (int j = 0; j < rules.length; j++) { - assertNotNull(rules[j]); - if (rules[j].getId().getModuleId().getName().equals(moduleNames[i])) { - found = true; - break; - } - } - assertTrue("dependency module exclude not found: " + moduleNames[i], found); - } - } - - protected void assertConf(ModuleDescriptor md, String name, String desc, Visibility visibility, - String[] exts) { - Configuration conf = md.getConfiguration(name); - assertNotNull("configuration not found: " + name, conf); - assertEquals(name, conf.getName()); - assertEquals(desc, conf.getDescription()); - assertEquals(visibility, conf.getVisibility()); - assertEquals(Arrays.asList(exts), Arrays.asList(conf.getExtends())); - } - -} +/* + * 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.parser; + +import java.util.Arrays; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ExcludeRule; +import org.apache.ivy.core.module.descriptor.IncludeRule; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.descriptor.Configuration.Visibility; + +public abstract class AbstractModuleDescriptorParserTester extends TestCase { + protected DependencyDescriptor getDependency(DependencyDescriptor[] dependencies, String name) { + for (int i = 0; i < dependencies.length; i++) { + assertNotNull(dependencies[i]); + assertNotNull(dependencies[i].getDependencyId()); + if (name.equals(dependencies[i].getDependencyId().getName())) { + return dependencies[i]; + } + } + return null; + } + + protected void assertArtifacts(Artifact[] artifacts, String[] artifactsNames) { + assertNotNull(artifacts); + assertEquals(artifactsNames.length, artifacts.length); + for (int i = 0; i < artifactsNames.length; i++) { + boolean found = false; + for (int j = 0; j < artifacts.length; j++) { + assertNotNull(artifacts[j]); + if (artifacts[j].getName().equals(artifactsNames[i])) { + found = true; + break; + } + } + assertTrue("artifact not found: " + artifactsNames[i], found); + } + } + + protected void assertDependencyArtifacts(DependencyDescriptor dd, String[] confs, + String[] artifactsNames) { + DependencyArtifactDescriptor[] dads = dd.getDependencyArtifacts(confs); + assertNotNull(dads); + assertEquals(artifactsNames.length, dads.length); + for (int i = 0; i < artifactsNames.length; i++) { + boolean found = false; + for (int j = 0; j < dads.length; j++) { + assertNotNull(dads[j]); + if (dads[j].getName().equals(artifactsNames[i])) { + found = true; + break; + } + } + assertTrue("dependency artifact not found: " + artifactsNames[i], found); + } + } + + protected void assertDependencyArtifactIncludeRules(DependencyDescriptor dd, String[] confs, + String[] artifactsNames) { + IncludeRule[] dads = dd.getIncludeRules(confs); + assertNotNull(dads); + assertEquals(artifactsNames.length, dads.length); + for (int i = 0; i < artifactsNames.length; i++) { + boolean found = false; + for (int j = 0; j < dads.length; j++) { + assertNotNull(dads[j]); + if (dads[j].getId().getName().equals(artifactsNames[i])) { + found = true; + break; + } + } + assertTrue("dependency include not found: " + artifactsNames[i], found); + } + } + + protected void assertDependencyArtifactExcludeRules(DependencyDescriptor dd, String[] confs, + String[] artifactsNames) { + ExcludeRule[] rules = dd.getExcludeRules(confs); + assertNotNull(rules); + assertEquals(artifactsNames.length, rules.length); + for (int i = 0; i < artifactsNames.length; i++) { + boolean found = false; + for (int j = 0; j < rules.length; j++) { + assertNotNull(rules[j]); + if (rules[j].getId().getName().equals(artifactsNames[i])) { + found = true; + break; + } + } + assertTrue("dependency exclude not found: " + artifactsNames[i], found); + } + } + + protected void assertDependencyModulesExcludes(DependencyDescriptor dd, String[] confs, + String[] moduleNames) { + ExcludeRule[] rules = dd.getExcludeRules(confs); + assertNotNull(rules); + assertEquals(moduleNames.length, rules.length); + for (int i = 0; i < moduleNames.length; i++) { + boolean found = false; + for (int j = 0; j < rules.length; j++) { + assertNotNull(rules[j]); + if (rules[j].getId().getModuleId().getName().equals(moduleNames[i])) { + found = true; + break; + } + } + assertTrue("dependency module exclude not found: " + moduleNames[i], found); + } + } + + protected void assertConf(ModuleDescriptor md, String name, String desc, Visibility visibility, + String[] exts) { + Configuration conf = md.getConfiguration(name); + assertNotNull("configuration not found: " + name, conf); + assertEquals(name, conf.getName()); + assertEquals(desc, conf.getDescription()); + assertEquals(visibility, conf.getVisibility()); + assertEquals(Arrays.asList(exts), Arrays.asList(conf.getExtends())); + } + +} diff --git a/test/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistryTest.java b/test/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistryTest.java index c6588d36..b9a97391 100644 --- a/test/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistryTest.java +++ b/test/java/org/apache/ivy/plugins/parser/ModuleDescriptorParserRegistryTest.java @@ -1,61 +1,61 @@ -/* - * 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.parser; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.ParseException; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.repository.Resource; - -public class ModuleDescriptorParserRegistryTest extends TestCase { - public static class MyParser extends AbstractModuleDescriptorParser { - public ModuleDescriptor parseDescriptor(IvySettings ivy, URL descriptorURL, Resource res, - boolean validate) throws ParseException, IOException { - return DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance("test", - "parser", "1.0")); - } - - public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) - throws ParseException, IOException { - } - - public boolean accept(Resource res) { - return true; - } - - } - - public void testAddConfigured() throws Exception { - IvySettings settings = new IvySettings(); - settings.addConfigured(new MyParser()); - ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor( - settings, ModuleDescriptorParserRegistryTest.class.getResource("nores"), false); - assertNotNull(md); - assertEquals(ModuleRevisionId.newInstance("test", "parser", "1.0"), md - .getModuleRevisionId()); - } -} +/* + * 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.parser; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.text.ParseException; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.repository.Resource; + +public class ModuleDescriptorParserRegistryTest extends TestCase { + public static class MyParser extends AbstractModuleDescriptorParser { + public ModuleDescriptor parseDescriptor(IvySettings ivy, URL descriptorURL, Resource res, + boolean validate) throws ParseException, IOException { + return DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance("test", + "parser", "1.0")); + } + + public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md) + throws ParseException, IOException { + } + + public boolean accept(Resource res) { + return true; + } + + } + + public void testAddConfigured() throws Exception { + IvySettings settings = new IvySettings(); + settings.addConfigured(new MyParser()); + ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor( + settings, ModuleDescriptorParserRegistryTest.class.getResource("nores"), false); + assertNotNull(md); + assertEquals(ModuleRevisionId.newInstance("test", "parser", "1.0"), md + .getModuleRevisionId()); + } +} diff --git a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java index 51668b58..f26b5717 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java +++ b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java @@ -1,400 +1,400 @@ -/* - * 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.parser.m2; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParserTester; -import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest; -import org.apache.ivy.plugins.repository.url.URLResource; - -public class PomModuleDescriptorParserTest extends AbstractModuleDescriptorParserTester { - // junit test -- DO NOT REMOVE used by ant to know it's a junit test - - public void testAccept() throws Exception { - assertTrue(PomModuleDescriptorParser.getInstance().accept( - new URLResource(getClass().getResource("test-simple.pom")))); - assertFalse(PomModuleDescriptorParser.getInstance().accept( - new URLResource(XmlModuleDescriptorParserTest.class.getResource("test.xml")))); - } - - public void testSimple() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-simple.pom"), false); - assertNotNull(md); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays - .asList(md.getConfigurations())); - - Artifact[] artifact = md.getArtifacts("master"); - assertEquals(1, artifact.length); - assertEquals(mrid, artifact[0].getModuleRevisionId()); - assertEquals("test", artifact[0].getName()); - assertEquals("jar", artifact[0].getExt()); - assertEquals("jar", artifact[0].getType()); - } - - public void testPackaging() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-packaging.pom"), false); - assertNotNull(md); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays - .asList(md.getConfigurations())); - - Artifact[] artifact = md.getArtifacts("master"); - assertEquals(1, artifact.length); - assertEquals(mrid, artifact[0].getModuleRevisionId()); - assertEquals("test", artifact[0].getName()); - assertEquals("war", artifact[0].getExt()); - assertEquals("war", artifact[0].getType()); - } - - public void testParent() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-parent.pom"), false); - assertNotNull(md); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays - .asList(md.getConfigurations())); - - Artifact[] artifact = md.getArtifacts("master"); - assertEquals(1, artifact.length); - assertEquals(mrid, artifact[0].getModuleRevisionId()); - assertEquals("test", artifact[0].getName()); - } - - public void testParent2() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-parent2.pom"), false); - assertNotNull(md); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); - assertEquals(mrid, md.getModuleRevisionId()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays - .asList(md.getConfigurations())); - - Artifact[] artifact = md.getArtifacts("master"); - assertEquals(1, artifact.length); - assertEquals(mrid, artifact[0].getModuleRevisionId()); - assertEquals("test", artifact[0].getName()); - } - - public void testDependencies() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-dependencies.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), - dds[0].getDependencyRevisionId()); - } - - public void testDependenciesWithClassifier() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-dependencies-with-classifier.pom"), - false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), - dds[0].getDependencyRevisionId()); - Map extraAtt = new HashMap(); - extraAtt.put("classifier", "asl"); - assertEquals(1, dds[0].getAllDependencyArtifacts().length); - assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes()); - } - - public void testWithVersionProperty() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-version.pom"), false); - assertNotNull(md); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("org.apache", "test-other", "1.0"), dds[0] - .getDependencyRevisionId()); - } - - // IVY-392 - public void testDependenciesWithProfile() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-dependencies-with-profile.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), - dds[0].getDependencyRevisionId()); - } - - public void testWithoutVersion() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-without-version.pom"), false); - assertNotNull(md); - - assertEquals(new ModuleId("org.apache", "test"), md.getModuleRevisionId().getModuleId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), - dds[0].getDependencyRevisionId()); - } - - public void testProperties() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-properties.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("drools", "drools-smf", "2.0-beta-18"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("drools", "drools-core", "2.0-beta-18"), dds[0] - .getDependencyRevisionId()); - } - - public void testReal() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("commons-lang-1.0.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("commons-lang", "commons-lang", "1.0"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(1, dds.length); - assertEquals(ModuleRevisionId.newInstance("junit", "junit", "3.7"), dds[0] - .getDependencyRevisionId()); - } - - public void testReal2() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("wicket-1.3-incubating-SNAPSHOT.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache.wicket", "wicket", - "1.3-incubating-SNAPSHOT"), md.getModuleRevisionId()); - } - - public void testVariables() throws Exception { - // test case for IVY-425 - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("spring-hibernate3-2.0.2.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.springframework", "spring-hibernate3", - "2.0.2"), md.getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(11, dds.length); - assertEquals(ModuleRevisionId.newInstance("org.springframework", "spring-web", "2.0.2"), - dds[10].getDependencyRevisionId()); - } - - public void testDependenciesInProfile() throws Exception { - // test case for IVY-423 - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("mule-module-builders-1.3.3.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.mule.modules", "mule-module-builders", - "1.3.3"), md.getModuleRevisionId()); - } - - public void testIVY424() throws Exception { - // test case for IVY-424 - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("shale-tiger-1.1.0-SNAPSHOT.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache.shale", "shale-tiger", - "1.1.0-SNAPSHOT"), md.getModuleRevisionId()); - } - - public void testOptional() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-optional.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md - .getModuleRevisionId()); - assertTrue(Arrays.asList(md.getConfigurationsNames()).contains("optional")); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(2, dds.length); - assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), - dds[0].getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"optional"})), new HashSet(Arrays - .asList(dds[0].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile(*)", "runtime(*)", - "master(*)"})), new HashSet(Arrays.asList(dds[0] - .getDependencyConfigurations("optional")))); - - assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"), dds[1] - .getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( - Arrays.asList(dds[1].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), - new HashSet(Arrays.asList(dds[1].getDependencyConfigurations("compile")))); - assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays - .asList(dds[1].getDependencyConfigurations("runtime")))); - } - - public void testDependenciesWithScope() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-dependencies-with-scope.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(3, dds.length); - assertEquals(ModuleRevisionId.newInstance("odmg", "odmg", "3.0"), dds[0] - .getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"runtime"})), new HashSet(Arrays - .asList(dds[0].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile(*)", "runtime(*)", - "master(*)"})), new HashSet(Arrays.asList(dds[0] - .getDependencyConfigurations("runtime")))); - - assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), - dds[1].getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( - Arrays.asList(dds[1].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), - new HashSet(Arrays.asList(dds[1].getDependencyConfigurations("compile")))); - assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays - .asList(dds[1].getDependencyConfigurations("runtime")))); - - assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"), dds[2] - .getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( - Arrays.asList(dds[2].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), - new HashSet(Arrays.asList(dds[2].getDependencyConfigurations("compile")))); - assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays - .asList(dds[2].getDependencyConfigurations("runtime")))); - } - - public void testExclusion() throws Exception { - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("test-exclusion.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(3, dds.length); - assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), - dds[0].getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( - Arrays.asList(dds[0].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), - new HashSet(Arrays.asList(dds[0].getDependencyConfigurations("compile")))); - assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays - .asList(dds[0].getDependencyConfigurations("runtime")))); - assertEquals(0, dds[0].getAllExcludeRules().length); - - assertEquals(ModuleRevisionId.newInstance("dom4j", "dom4j", "1.6"), dds[1] - .getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( - Arrays.asList(dds[1].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), - new HashSet(Arrays.asList(dds[1].getDependencyConfigurations("compile")))); - assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays - .asList(dds[1].getDependencyConfigurations("runtime")))); - assertDependencyModulesExcludes(dds[1], new String[] {"compile"}, new String[] { - "jaxme-api", "jaxen"}); - assertDependencyModulesExcludes(dds[1], new String[] {"runtime"}, new String[] { - "jaxme-api", "jaxen"}); - - assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"), dds[2] - .getDependencyRevisionId()); - assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( - Arrays.asList(dds[2].getModuleConfigurations()))); - assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), - new HashSet(Arrays.asList(dds[2].getDependencyConfigurations("compile")))); - assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays - .asList(dds[2].getDependencyConfigurations("runtime")))); - assertEquals(0, dds[2].getAllExcludeRules().length); - } - - public void testWithPlugins() throws Exception { - // test case for IVY-417 - ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), getClass().getResource("mule-1.3.3.pom"), false); - assertNotNull(md); - - assertEquals(ModuleRevisionId.newInstance("org.mule", "mule", "1.3.3"), md - .getModuleRevisionId()); - - DependencyDescriptor[] dds = md.getDependencies(); - assertNotNull(dds); - assertEquals(0, dds.length); - } - -} +/* + * 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.parser.m2; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParserTester; +import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest; +import org.apache.ivy.plugins.repository.url.URLResource; + +public class PomModuleDescriptorParserTest extends AbstractModuleDescriptorParserTester { + // junit test -- DO NOT REMOVE used by ant to know it's a junit test + + public void testAccept() throws Exception { + assertTrue(PomModuleDescriptorParser.getInstance().accept( + new URLResource(getClass().getResource("test-simple.pom")))); + assertFalse(PomModuleDescriptorParser.getInstance().accept( + new URLResource(XmlModuleDescriptorParserTest.class.getResource("test.xml")))); + } + + public void testSimple() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-simple.pom"), false); + assertNotNull(md); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays + .asList(md.getConfigurations())); + + Artifact[] artifact = md.getArtifacts("master"); + assertEquals(1, artifact.length); + assertEquals(mrid, artifact[0].getModuleRevisionId()); + assertEquals("test", artifact[0].getName()); + assertEquals("jar", artifact[0].getExt()); + assertEquals("jar", artifact[0].getType()); + } + + public void testPackaging() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-packaging.pom"), false); + assertNotNull(md); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays + .asList(md.getConfigurations())); + + Artifact[] artifact = md.getArtifacts("master"); + assertEquals(1, artifact.length); + assertEquals(mrid, artifact[0].getModuleRevisionId()); + assertEquals("test", artifact[0].getName()); + assertEquals("war", artifact[0].getExt()); + assertEquals("war", artifact[0].getType()); + } + + public void testParent() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-parent.pom"), false); + assertNotNull(md); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays + .asList(md.getConfigurations())); + + Artifact[] artifact = md.getArtifacts("master"); + assertEquals(1, artifact.length); + assertEquals(mrid, artifact[0].getModuleRevisionId()); + assertEquals("test", artifact[0].getName()); + } + + public void testParent2() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-parent2.pom"), false); + assertNotNull(md); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); + assertEquals(mrid, md.getModuleRevisionId()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(PomModuleDescriptorParser.MAVEN2_CONFIGURATIONS), Arrays + .asList(md.getConfigurations())); + + Artifact[] artifact = md.getArtifacts("master"); + assertEquals(1, artifact.length); + assertEquals(mrid, artifact[0].getModuleRevisionId()); + assertEquals("test", artifact[0].getName()); + } + + public void testDependencies() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-dependencies.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), + dds[0].getDependencyRevisionId()); + } + + public void testDependenciesWithClassifier() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-dependencies-with-classifier.pom"), + false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), + dds[0].getDependencyRevisionId()); + Map extraAtt = new HashMap(); + extraAtt.put("classifier", "asl"); + assertEquals(1, dds[0].getAllDependencyArtifacts().length); + assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes()); + } + + public void testWithVersionProperty() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-version.pom"), false); + assertNotNull(md); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("org.apache", "test-other", "1.0"), dds[0] + .getDependencyRevisionId()); + } + + // IVY-392 + public void testDependenciesWithProfile() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-dependencies-with-profile.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), + dds[0].getDependencyRevisionId()); + } + + public void testWithoutVersion() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-without-version.pom"), false); + assertNotNull(md); + + assertEquals(new ModuleId("org.apache", "test"), md.getModuleRevisionId().getModuleId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), + dds[0].getDependencyRevisionId()); + } + + public void testProperties() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-properties.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("drools", "drools-smf", "2.0-beta-18"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("drools", "drools-core", "2.0-beta-18"), dds[0] + .getDependencyRevisionId()); + } + + public void testReal() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("commons-lang-1.0.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("commons-lang", "commons-lang", "1.0"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(1, dds.length); + assertEquals(ModuleRevisionId.newInstance("junit", "junit", "3.7"), dds[0] + .getDependencyRevisionId()); + } + + public void testReal2() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("wicket-1.3-incubating-SNAPSHOT.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache.wicket", "wicket", + "1.3-incubating-SNAPSHOT"), md.getModuleRevisionId()); + } + + public void testVariables() throws Exception { + // test case for IVY-425 + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("spring-hibernate3-2.0.2.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.springframework", "spring-hibernate3", + "2.0.2"), md.getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(11, dds.length); + assertEquals(ModuleRevisionId.newInstance("org.springframework", "spring-web", "2.0.2"), + dds[10].getDependencyRevisionId()); + } + + public void testDependenciesInProfile() throws Exception { + // test case for IVY-423 + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("mule-module-builders-1.3.3.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.mule.modules", "mule-module-builders", + "1.3.3"), md.getModuleRevisionId()); + } + + public void testIVY424() throws Exception { + // test case for IVY-424 + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("shale-tiger-1.1.0-SNAPSHOT.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache.shale", "shale-tiger", + "1.1.0-SNAPSHOT"), md.getModuleRevisionId()); + } + + public void testOptional() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-optional.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md + .getModuleRevisionId()); + assertTrue(Arrays.asList(md.getConfigurationsNames()).contains("optional")); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(2, dds.length); + assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), + dds[0].getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"optional"})), new HashSet(Arrays + .asList(dds[0].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile(*)", "runtime(*)", + "master(*)"})), new HashSet(Arrays.asList(dds[0] + .getDependencyConfigurations("optional")))); + + assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"), dds[1] + .getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( + Arrays.asList(dds[1].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), + new HashSet(Arrays.asList(dds[1].getDependencyConfigurations("compile")))); + assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays + .asList(dds[1].getDependencyConfigurations("runtime")))); + } + + public void testDependenciesWithScope() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-dependencies-with-scope.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(3, dds.length); + assertEquals(ModuleRevisionId.newInstance("odmg", "odmg", "3.0"), dds[0] + .getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"runtime"})), new HashSet(Arrays + .asList(dds[0].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile(*)", "runtime(*)", + "master(*)"})), new HashSet(Arrays.asList(dds[0] + .getDependencyConfigurations("runtime")))); + + assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), + dds[1].getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( + Arrays.asList(dds[1].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), + new HashSet(Arrays.asList(dds[1].getDependencyConfigurations("compile")))); + assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays + .asList(dds[1].getDependencyConfigurations("runtime")))); + + assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"), dds[2] + .getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( + Arrays.asList(dds[2].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), + new HashSet(Arrays.asList(dds[2].getDependencyConfigurations("compile")))); + assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays + .asList(dds[2].getDependencyConfigurations("runtime")))); + } + + public void testExclusion() throws Exception { + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("test-exclusion.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(3, dds.length); + assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), + dds[0].getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( + Arrays.asList(dds[0].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), + new HashSet(Arrays.asList(dds[0].getDependencyConfigurations("compile")))); + assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays + .asList(dds[0].getDependencyConfigurations("runtime")))); + assertEquals(0, dds[0].getAllExcludeRules().length); + + assertEquals(ModuleRevisionId.newInstance("dom4j", "dom4j", "1.6"), dds[1] + .getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( + Arrays.asList(dds[1].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), + new HashSet(Arrays.asList(dds[1].getDependencyConfigurations("compile")))); + assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays + .asList(dds[1].getDependencyConfigurations("runtime")))); + assertDependencyModulesExcludes(dds[1], new String[] {"compile"}, new String[] { + "jaxme-api", "jaxen"}); + assertDependencyModulesExcludes(dds[1], new String[] {"runtime"}, new String[] { + "jaxme-api", "jaxen"}); + + assertEquals(ModuleRevisionId.newInstance("cglib", "cglib", "2.0.2"), dds[2] + .getDependencyRevisionId()); + assertEquals(new HashSet(Arrays.asList(new String[] {"compile", "runtime"})), new HashSet( + Arrays.asList(dds[2].getModuleConfigurations()))); + assertEquals(new HashSet(Arrays.asList(new String[] {"master(*)", "compile(*)"})), + new HashSet(Arrays.asList(dds[2].getDependencyConfigurations("compile")))); + assertEquals(new HashSet(Arrays.asList(new String[] {"runtime(*)"})), new HashSet(Arrays + .asList(dds[2].getDependencyConfigurations("runtime")))); + assertEquals(0, dds[2].getAllExcludeRules().length); + } + + public void testWithPlugins() throws Exception { + // test case for IVY-417 + ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), getClass().getResource("mule-1.3.3.pom"), false); + assertNotNull(md); + + assertEquals(ModuleRevisionId.newInstance("org.mule", "mule", "1.3.3"), md + .getModuleRevisionId()); + + DependencyDescriptor[] dds = md.getDependencies(); + assertNotNull(dds); + assertEquals(0, dds.length); + } + +} diff --git a/test/java/org/apache/ivy/plugins/parser/m2/commons-lang-1.0.pom b/test/java/org/apache/ivy/plugins/parser/m2/commons-lang-1.0.pom index 0168da74..0ca53506 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/commons-lang-1.0.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/commons-lang-1.0.pom @@ -1,108 +1,108 @@ - - - 4.0.0 - commons-lang - commons-lang - Lang - 1.0 - Commons.Lang, a package of Java utility classes for the - classes that are in java.lang's hierarchy, or are considered to be so - standard as to justify existence in java.lang. - 2001 - - - dlr - Daniel Rall - dlr@finemaltcoding.com - CollabNet, Inc. - - Java Developer - - - - scolebourne - Stephen Colebourne - scolebourne@joda.org - SITA ATS Ltd - - Java Developer - - - - bayard - Henri Yandell - bayard@generationjava.com - - - Java Developer - - - - - Steven Caswell - steven@caswell.name - - - Java Developer - - - - - - Ringo De Smet - ringods@yahoo.co.uk - - - Java Developer - - - - Steve Downey - steve.downey@netfolio.com - - - Java Developer - - - - - - - maven-surefire-plugin - - - **/*Test.java - **/*TestCase.java - - - **/Abstract*.java - - - - - - - - junit - junit - 3.7 - - - + + + 4.0.0 + commons-lang + commons-lang + Lang + 1.0 + Commons.Lang, a package of Java utility classes for the + classes that are in java.lang's hierarchy, or are considered to be so + standard as to justify existence in java.lang. + 2001 + + + dlr + Daniel Rall + dlr@finemaltcoding.com + CollabNet, Inc. + + Java Developer + + + + scolebourne + Stephen Colebourne + scolebourne@joda.org + SITA ATS Ltd + + Java Developer + + + + bayard + Henri Yandell + bayard@generationjava.com + + + Java Developer + + + + + Steven Caswell + steven@caswell.name + + + Java Developer + + + + + + Ringo De Smet + ringods@yahoo.co.uk + + + Java Developer + + + + Steve Downey + steve.downey@netfolio.com + + + Java Developer + + + + + + + maven-surefire-plugin + + + **/*Test.java + **/*TestCase.java + + + **/Abstract*.java + + + + + + + + junit + junit + 3.7 + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/mule-1.3.3.pom b/test/java/org/apache/ivy/plugins/parser/m2/mule-1.3.3.pom index 23fc9cbd..a2201830 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/mule-1.3.3.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/mule-1.3.3.pom @@ -1,561 +1,561 @@ - - - - - - 4.0.0 - org.mule - mule - pom - 1.3.3 - - - - MuleSource, Inc. - http://www.mulesource.com - - - - Mule - - Mule is a simple yet robust and highly scalable Integration and ESB services framework. It is designed - as a light-weight, event-driven component technology that handles communication with disparate systems - transparently providing a simple component interface. - - http://mule.mulesource.org - 2003 - - - - - - - - - - - jira - http://dev.mulesource.org/jira/browse/MULE - - - - - scm:svn:http://svn.codehaus.org/mule/trunk/mule - scm:svn:https://svn.codehaus.org/mule/trunk/mule - http://svn.mule.codehaus.org/ - - - - continuum - http://localhost:8080/continuum - - - mail - -
      tcarlson@impsat.com
      -
      -
      -
      -
      - - - http://mule.mulesource.org/Download - - mule-releases - Mule Release Repository - dav:https://dav.codehaus.org/repository/mule/ - - - mule-snapshots - Mule Snapshot Repository - dav:https://dav.codehaus.org/snapshots.repository/mule/ - false - - - mule-site - Mule Website - dav:https://dav.codehaus.org/mule/docs/ - - - - - - codehaus - Codehaus Maven 2.x Release Repository - http://repository.codehaus.org - - false - - - - codehaus-snapshots - Codehaus Maven 2.x Snapshots Repository - http://snapshots.repository.codehaus.org - - true - - - false - - - - mule - Mule Dependencies - http://dist.codehaus.org/mule/dependencies/maven2 - - false - - - - apache-snapshots - Snapshot repository - http://people.apache.org/maven-snapshot-repository - - true - - - false - - - - - local (Maven 1) - Local module repository (lib) - file://lib - - false - - - true - - legacy - - - - - - - - apache-plugin-snapshots - Apache Maven Plugins Snapshot Repository - http://people.apache.org/maven-snapshot-repository - - true - - - false - - - - - - - install - - - - - org.apache.maven.wagon - wagon-webdav - 1.0-beta-2-20060812.020341-4 - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.4 - 1.4 - ISO-8859-1 - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - - - false - - - true - - - - - For more information go to ${pom.url} - Get commercial support: ${pom.organization.url} - Mule ESB and Integration Platform - MulesSource MPL http://www.mulesource.com/MSPL/ - ${pom.organization.url} - ${pom.url} - -//${pom.organisation.name} //DTD mule-configuration XML V1.0//EN - ${pom.url}/dtds - - ${mvn.timestamp.yyyy-MM-dd-HH:mm:ss} - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - 2.3-20060831.124149-5 - - -Xms64m -Xmx256m - - **/Abstract*.* - - org/mule/tck/** - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - org.mule - mule-buildtools - ${version} - - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - - - - - - - clean - - clean - - - - - - - - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-site-plugin - 2.0-20060528.195659-9 - - - - - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - - - - dependencies - index - - - - - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - 128m - 512 - ISO-8859-1 - ISO-8859-1 - - - - - - http://java.sun.com/j2se/1.4.2/docs/api/ - http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ - http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/ - http://jakarta.apache.org/commons/collections/api-3.2/ - http://jakarta.apache.org/commons/io/api-1.2/ - http://jakarta.apache.org/commons/lang/api-2.1/ - http://jakarta.apache.org/commons/logging/commons-logging-1.0.4/docs/apidocs/ - http://jakarta.apache.org/commons/pool/apidocs/ - http://logging.apache.org/log4j/docs/api/ - http://dcl.mathcs.emory.edu/util/backport-util-concurrent/doc/api/ - http://www.junit.org/junit/javadoc/3.8.1/ - - - - Mule Core - org.mule* - - - Modules (not part of the Mule core) - org.mule.extras.* - - - Transports (a.k.a. Providers) - org.mule.providers.* - - - Testing Framework - org.mule.tck* - - - Examples - org.mule.samples.* - - - - - - - - - org.apache.maven.plugins - maven-jxr-plugin - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - - - false - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - codecheck/checkstyle.xml - codecheck/LICENSE.txt - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - - - - - - - - - - - - buildtools - core - modules - transports - tests - examples - - - - - - - - - java14 - - 1.4 - - - - - java5 - - 1.5 - - - - - - tests - - - tests - true - - - - - - distributions - - - distributions - true - - - - distributions - - - - - windows - - - windows - - - - - - ci-server - - - file:///home/luntbuild/publish/mule/docs - - - - - - -
      - + + + + + + 4.0.0 + org.mule + mule + pom + 1.3.3 + + + + MuleSource, Inc. + http://www.mulesource.com + + + + Mule + + Mule is a simple yet robust and highly scalable Integration and ESB services framework. It is designed + as a light-weight, event-driven component technology that handles communication with disparate systems + transparently providing a simple component interface. + + http://mule.mulesource.org + 2003 + + + + + + + + + + + jira + http://dev.mulesource.org/jira/browse/MULE + + + + + scm:svn:http://svn.codehaus.org/mule/trunk/mule + scm:svn:https://svn.codehaus.org/mule/trunk/mule + http://svn.mule.codehaus.org/ + + + + continuum + http://localhost:8080/continuum + + + mail + +
      tcarlson@impsat.com
      +
      +
      +
      +
      + + + http://mule.mulesource.org/Download + + mule-releases + Mule Release Repository + dav:https://dav.codehaus.org/repository/mule/ + + + mule-snapshots + Mule Snapshot Repository + dav:https://dav.codehaus.org/snapshots.repository/mule/ + false + + + mule-site + Mule Website + dav:https://dav.codehaus.org/mule/docs/ + + + + + + codehaus + Codehaus Maven 2.x Release Repository + http://repository.codehaus.org + + false + + + + codehaus-snapshots + Codehaus Maven 2.x Snapshots Repository + http://snapshots.repository.codehaus.org + + true + + + false + + + + mule + Mule Dependencies + http://dist.codehaus.org/mule/dependencies/maven2 + + false + + + + apache-snapshots + Snapshot repository + http://people.apache.org/maven-snapshot-repository + + true + + + false + + + + + local (Maven 1) + Local module repository (lib) + file://lib + + false + + + true + + legacy + + + + + + + + apache-plugin-snapshots + Apache Maven Plugins Snapshot Repository + http://people.apache.org/maven-snapshot-repository + + true + + + false + + + + + + + install + + + + + org.apache.maven.wagon + wagon-webdav + 1.0-beta-2-20060812.020341-4 + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.4 + 1.4 + ISO-8859-1 + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + + + false + + + true + + + + + For more information go to ${pom.url} + Get commercial support: ${pom.organization.url} + Mule ESB and Integration Platform + MulesSource MPL http://www.mulesource.com/MSPL/ + ${pom.organization.url} + ${pom.url} + -//${pom.organisation.name} //DTD mule-configuration XML V1.0//EN + ${pom.url}/dtds + + ${mvn.timestamp.yyyy-MM-dd-HH:mm:ss} + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + 2.3-20060831.124149-5 + + -Xms64m -Xmx256m + + **/Abstract*.* + + org/mule/tck/** + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + org.mule + mule-buildtools + ${version} + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + + + + + + + clean + + clean + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-site-plugin + 2.0-20060528.195659-9 + + + + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + + + + dependencies + index + + + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + 128m + 512 + ISO-8859-1 + ISO-8859-1 + + + + + + http://java.sun.com/j2se/1.4.2/docs/api/ + http://java.sun.com/j2ee/sdk_1.3/techdocs/api/ + http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/ + http://jakarta.apache.org/commons/collections/api-3.2/ + http://jakarta.apache.org/commons/io/api-1.2/ + http://jakarta.apache.org/commons/lang/api-2.1/ + http://jakarta.apache.org/commons/logging/commons-logging-1.0.4/docs/apidocs/ + http://jakarta.apache.org/commons/pool/apidocs/ + http://logging.apache.org/log4j/docs/api/ + http://dcl.mathcs.emory.edu/util/backport-util-concurrent/doc/api/ + http://www.junit.org/junit/javadoc/3.8.1/ + + + + Mule Core + org.mule* + + + Modules (not part of the Mule core) + org.mule.extras.* + + + Transports (a.k.a. Providers) + org.mule.providers.* + + + Testing Framework + org.mule.tck* + + + Examples + org.mule.samples.* + + + + + + + + + org.apache.maven.plugins + maven-jxr-plugin + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + + + false + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + codecheck/checkstyle.xml + codecheck/LICENSE.txt + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + + + + + + + + + + + + buildtools + core + modules + transports + tests + examples + + + + + + + + + java14 + + 1.4 + + + + + java5 + + 1.5 + + + + + + tests + + + tests + true + + + + + + distributions + + + distributions + true + + + + distributions + + + + + windows + + + windows + + + + + + ci-server + + + file:///home/luntbuild/publish/mule/docs + + + + + + +
      + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/mule-module-builders-1.3.3.pom b/test/java/org/apache/ivy/plugins/parser/m2/mule-module-builders-1.3.3.pom index bc2c2d5f..6a273eae 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/mule-module-builders-1.3.3.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/mule-module-builders-1.3.3.pom @@ -1,93 +1,93 @@ - - - - mule-modules - org.mule.modules - 1.3.3 - - 4.0.0 - - mule-module-builders - Mule Configuration Builders - 1.3.3 - Standard configuration builders for Mule - - - java14 - - - 1.4 - - - - xml-apis - xml-apis - - 1.3.03 - - - xerces - xercesImpl - 2.8.1 - - - - commons-digester - commons-digester - 1.7 - - - - - - java5 - - 1.5 - - - - commons-digester - - commons-digester - 1.7 - - - xml-apis - xml-apis - - - - - - - - - - org.apache.geronimo.specs - - geronimo-servlet_2.4_spec - 1.0.1 - - - - deployed - - - + + + + mule-modules + org.mule.modules + 1.3.3 + + 4.0.0 + + mule-module-builders + Mule Configuration Builders + 1.3.3 + Standard configuration builders for Mule + + + java14 + + + 1.4 + + + + xml-apis + xml-apis + + 1.3.03 + + + xerces + xercesImpl + 2.8.1 + + + + commons-digester + commons-digester + 1.7 + + + + + + java5 + + 1.5 + + + + commons-digester + + commons-digester + 1.7 + + + xml-apis + xml-apis + + + + + + + + + + org.apache.geronimo.specs + + geronimo-servlet_2.4_spec + 1.0.1 + + + + deployed + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/shale-tiger-1.1.0-SNAPSHOT.pom b/test/java/org/apache/ivy/plugins/parser/m2/shale-tiger-1.1.0-SNAPSHOT.pom index e79ea6cf..519ac8cc 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/shale-tiger-1.1.0-SNAPSHOT.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/shale-tiger-1.1.0-SNAPSHOT.pom @@ -1,225 +1,225 @@ - - - - shale-parent - org.apache.shale - 1.1.0-SNAPSHOT - - 4.0.0 - - shale-tiger - Shale Tiger Extensions - 1.1.0-SNAPSHOT - - - - maven-surefire-plugin - - - - - basedir - ${basedir} - - - org.apache.commons.logging.LogFactory - - org.apache.commons.logging.impl.LogFactoryImpl - - - org.apache.commons.logging.Log - org.apache.commons.logging.impl.SimpleLog - - - - org.apache.commons.logging.simplelog.log.org.apache.shale.tiger - trace - - - - - - maven-compiler-plugin - - - 1.5 - 1.5 - - - - maven-antrun-plugin - - - - construct-webapp - test-compile - - run - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - j4 - - - - - org.codehaus.mojo - retrotranslator-maven-plugin - - - retrotranslate - - - - - - maven-jar-plugin - - - create-j4-jar - - - jar - - - ${project.build.directory}/classes-retro - j4 - - - - ${project.artifactId}-j4 - ${project.organization.name} - ${project.organization.name} - ${project.description} - 1.1.0-SNAPSHOT - - ${scm.revision} - - - - - - - - - - - - sun.jdk - rt - 1.4.0 - system - - ${java14.jar} - - - net.sf.retrotranslator - retrotranslator-runtime - 1.0.8 - - - - - - - - commons-digester - commons-digester - compile - - - - javax.servlet - servlet-api - provided - - - - junit - junit - test - - - org.apache.myfaces.core - myfaces-api - - provided - - - org.apache.shale - shale-core - 1.1.0-SNAPSHOT - - - - org.apache.shale - shale-test - 1.1.0-SNAPSHOT - test - - - - org.apache.shale - shale-view - 1.1.0-SNAPSHOT - - - - - - - maven-pmd-plugin - - 1.5 - - - - - - - deployed - - + + + + shale-parent + org.apache.shale + 1.1.0-SNAPSHOT + + 4.0.0 + + shale-tiger + Shale Tiger Extensions + 1.1.0-SNAPSHOT + + + + maven-surefire-plugin + + + + + basedir + ${basedir} + + + org.apache.commons.logging.LogFactory + + org.apache.commons.logging.impl.LogFactoryImpl + + + org.apache.commons.logging.Log + org.apache.commons.logging.impl.SimpleLog + + + + org.apache.commons.logging.simplelog.log.org.apache.shale.tiger + trace + + + + + + maven-compiler-plugin + + + 1.5 + 1.5 + + + + maven-antrun-plugin + + + + construct-webapp + test-compile + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + j4 + + + + + org.codehaus.mojo + retrotranslator-maven-plugin + + + retrotranslate + + + + + + maven-jar-plugin + + + create-j4-jar + + + jar + + + ${project.build.directory}/classes-retro + j4 + + + + ${project.artifactId}-j4 + ${project.organization.name} + ${project.organization.name} + ${project.description} + 1.1.0-SNAPSHOT + + ${scm.revision} + + + + + + + + + + + + sun.jdk + rt + 1.4.0 + system + + ${java14.jar} + + + net.sf.retrotranslator + retrotranslator-runtime + 1.0.8 + + + + + + + + commons-digester + commons-digester + compile + + + + javax.servlet + servlet-api + provided + + + + junit + junit + test + + + org.apache.myfaces.core + myfaces-api + + provided + + + org.apache.shale + shale-core + 1.1.0-SNAPSHOT + + + + org.apache.shale + shale-test + 1.1.0-SNAPSHOT + test + + + + org.apache.shale + shale-view + 1.1.0-SNAPSHOT + + + + + + + maven-pmd-plugin + + 1.5 + + + + + + + deployed + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/spring-hibernate3-2.0.2.pom b/test/java/org/apache/ivy/plugins/parser/m2/spring-hibernate3-2.0.2.pom index ee7d216e..5845c3c2 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/spring-hibernate3-2.0.2.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/spring-hibernate3-2.0.2.pom @@ -1,120 +1,120 @@ - - - - 4.0.0 - org.springframework - spring-hibernate3 - jar - Spring Framework: Hibernate3 - - 2.0.2 - Spring Framework: Hibernate3 - http://www.springframework.org - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - repo - - - - scm:cvs:pserver:anonymous:@springframework.cvs.sourceforge.net:/cvsroot/springframework - scm:cvs:ext:username@springframework.cvs.sourceforge.net:/cvsroot/springframework - 2.0.2 - - http://springframework.cvs.sourceforge.net/springframework/ - - - Spring Framework - http://www.springframework.org/ - - - - - - aopalliance - aopalliance - 1.0 - - - commons-logging - - commons-logging - 1.1 - - - org.hibernate - hibernate - 3.2.1.ga - - - - javax.servlet - servlet-api - 2.4 - provided - - - - - ${project.groupId} - spring-aop - ${project.version} - true - - - - ${project.groupId} - spring-beans - ${project.version} - - - ${project.groupId} - - spring-context - ${project.version} - - - ${project.groupId} - spring-core - ${project.version} - - - - ${project.groupId} - spring-dao - ${project.version} - - - - ${project.groupId} - spring-jdbc - ${project.version} - - - ${project.groupId} - spring-web - - ${project.version} - true - - - + + + + 4.0.0 + org.springframework + spring-hibernate3 + jar + Spring Framework: Hibernate3 + + 2.0.2 + Spring Framework: Hibernate3 + http://www.springframework.org + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + repo + + + + scm:cvs:pserver:anonymous:@springframework.cvs.sourceforge.net:/cvsroot/springframework + scm:cvs:ext:username@springframework.cvs.sourceforge.net:/cvsroot/springframework + 2.0.2 + + http://springframework.cvs.sourceforge.net/springframework/ + + + Spring Framework + http://www.springframework.org/ + + + + + + aopalliance + aopalliance + 1.0 + + + commons-logging + + commons-logging + 1.1 + + + org.hibernate + hibernate + 3.2.1.ga + + + + javax.servlet + servlet-api + 2.4 + provided + + + + + ${project.groupId} + spring-aop + ${project.version} + true + + + + ${project.groupId} + spring-beans + ${project.version} + + + ${project.groupId} + + spring-context + ${project.version} + + + ${project.groupId} + spring-core + ${project.version} + + + + ${project.groupId} + spring-dao + ${project.version} + + + + ${project.groupId} + spring-jdbc + ${project.version} + + + ${project.groupId} + spring-web + + ${project.version} + true + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-classifier.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-classifier.pom index e541356a..c5064577 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-classifier.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-classifier.pom @@ -1,39 +1,39 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - commons-logging - commons-logging - 1.0.4 - asl - - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + commons-logging + commons-logging + 1.0.4 + asl + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-profile.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-profile.pom index 0681e32f..13cc13de 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-profile.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-profile.pom @@ -1,88 +1,88 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - j4 - - - - org.codehaus.mojo - retrotranslator-maven-plugin - - - retrotranslate - - - - - maven-jar-plugin - - - create-j4-jar - - jar - - - ${project.build.directory}/classes-retro - j4 - - - ${project.artifactId}-j4 - ${project.organization.name} - ${project.organization.name} - ${project.description} - 2.0.2-SNAPSHOT - ${scm.revision} - - - - - - - - - - - net.sf.retrotranslator - retrotranslator-runtime - 1.0.8 - - - - - - - commons-logging - commons-logging - 1.0.4 - - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + j4 + + + + org.codehaus.mojo + retrotranslator-maven-plugin + + + retrotranslate + + + + + maven-jar-plugin + + + create-j4-jar + + jar + + + ${project.build.directory}/classes-retro + j4 + + + ${project.artifactId}-j4 + ${project.organization.name} + ${project.organization.name} + ${project.description} + 2.0.2-SNAPSHOT + ${scm.revision} + + + + + + + + + + + net.sf.retrotranslator + retrotranslator-runtime + 1.0.8 + + + + + + + commons-logging + commons-logging + 1.0.4 + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-scope.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-scope.pom index efc17bcc..a3cab1a8 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-scope.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies-with-scope.pom @@ -1,50 +1,50 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - odmg - odmg - 3.0 - runtime - - - commons-logging - commons-logging - 1.0.4 - - - cglib - cglib - 2.0.2 - compile - - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + odmg + odmg + 3.0 + runtime + + + commons-logging + commons-logging + 1.0.4 + + + cglib + cglib + 2.0.2 + compile + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies.pom index 900eec34..37c9e142 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-dependencies.pom @@ -1,38 +1,38 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - commons-logging - commons-logging - 1.0.4 - - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + commons-logging + commons-logging + 1.0.4 + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-exclusion.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-exclusion.pom index 9b218f0a..ae2b61e3 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-exclusion.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-exclusion.pom @@ -1,58 +1,58 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - commons-logging - commons-logging - 1.0.4 - - - dom4j - dom4j - 1.6 - - - jaxme - jaxme-api - - - jaxen - jaxen - - - - - cglib - cglib - 2.0.2 - - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + commons-logging + commons-logging + 1.0.4 + + + dom4j + dom4j + 1.6 + + + jaxme + jaxme-api + + + jaxen + jaxen + + + + + cglib + cglib + 2.0.2 + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-optional.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-optional.pom index b5343a10..f95c8910 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-optional.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-optional.pom @@ -1,44 +1,44 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - commons-logging - commons-logging - 1.0.4 - - - - cglib - cglib - 2.0.2 - - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + commons-logging + commons-logging + 1.0.4 + + + + cglib + cglib + 2.0.2 + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-parent.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-parent.pom index 85e70666..32465c67 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-parent.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-parent.pom @@ -1,36 +1,36 @@ - - - - - test-parent - org.apache.parent - 1.0.parent - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - + + + + + test-parent + org.apache.parent + 1.0.parent + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-parent2.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-parent2.pom index 20a49230..7274c69f 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-parent2.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-parent2.pom @@ -1,35 +1,35 @@ - - - - - test-parent - org.apache - 1.0.parent - - 4.0.0 - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - + + + + + test-parent + org.apache + 1.0.parent + + 4.0.0 + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-properties.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-properties.pom index 7ddf7bdc..ec54bd59 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-properties.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-properties.pom @@ -1,32 +1,32 @@ - - - 4.0.0 - drools - drools-smf - Drools :: Semantics Module Framework - 2.0-beta-18 - - - drools - drools-core - ${pom.version} - - - + + + 4.0.0 + drools + drools-smf + Drools :: Semantics Module Framework + 2.0-beta-18 + + + drools + drools-core + ${pom.version} + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-simple.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-simple.pom index 310d2869..6c77b493 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-simple.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-simple.pom @@ -1,31 +1,31 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-version.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-version.pom index f456ca41..1ea3c916 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-version.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-version.pom @@ -1,38 +1,38 @@ - - - - 4.0.0 - org.apache - test-version - Test Module for Ivy M2 parsing - 1.0 - http://incubator.apache.org/ivy - - Apache - http://www.apache.org/ - - - - org.apache - test-other - ${version} - - - + + + + 4.0.0 + org.apache + test-version + Test Module for Ivy M2 parsing + 1.0 + http://incubator.apache.org/ivy + + Apache + http://www.apache.org/ + + + + org.apache + test-other + ${version} + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/test-without-version.pom b/test/java/org/apache/ivy/plugins/parser/m2/test-without-version.pom index 83b081cc..e5fcf3a4 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/test-without-version.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/test-without-version.pom @@ -1,37 +1,37 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - commons-logging - commons-logging - 1.0.4 - - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + commons-logging + commons-logging + 1.0.4 + + + diff --git a/test/java/org/apache/ivy/plugins/parser/m2/wicket-1.3-incubating-SNAPSHOT.pom b/test/java/org/apache/ivy/plugins/parser/m2/wicket-1.3-incubating-SNAPSHOT.pom index 107a5f07..044bd9ba 100644 --- a/test/java/org/apache/ivy/plugins/parser/m2/wicket-1.3-incubating-SNAPSHOT.pom +++ b/test/java/org/apache/ivy/plugins/parser/m2/wicket-1.3-incubating-SNAPSHOT.pom @@ -1,115 +1,115 @@ - - - - - - 4.0.0 - - org.apache.wicket - wicket-parent - 1.3-incubating-SNAPSHOT - ../wicket-parent - - - wicket - jar - Wicket - http://wicketframework.org/${project.artifactId}-1.3 - Wicket is a Java web application framework that takes simplicity, separation of concerns and ease of development to a whole new level. Wicket pages can be mocked up, previewed and later revised using standard WYSIWYG HTML design tools. Dynamic content processing and form handling is all handled in Java code using a first-class component model backed by POJO data beans that can easily be persisted using your favorite technology. - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.4 - 1.4 - - - - org.codehaus.mojo - surefire-report-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - 2.1.3 - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-assembly-plugin - - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - - - - dependencies - project-team - mailing-list - issue-tracking - license - scm - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.codehaus.mojo - surefire-report-maven-plugin - - - - + + + + + + 4.0.0 + + org.apache.wicket + wicket-parent + 1.3-incubating-SNAPSHOT + ../wicket-parent + + + wicket + jar + Wicket + http://wicketframework.org/${project.artifactId}-1.3 + Wicket is a Java web application framework that takes simplicity, separation of concerns and ease of development to a whole new level. Wicket pages can be mocked up, previewed and later revised using standard WYSIWYG HTML design tools. Dynamic content processing and form handling is all handled in Java code using a first-class component model backed by POJO data beans that can easily be persisted using your favorite technology. + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.4 + 1.4 + + + + org.codehaus.mojo + surefire-report-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 2.1.3 + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-assembly-plugin + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + + + + dependencies + project-team + mailing-list + issue-tracking + license + scm + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.codehaus.mojo + surefire-report-maven-plugin + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java index 75e36228..bc447bf4 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java +++ b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java @@ -1,861 +1,861 @@ -/* - * 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.parser.xml; - -import java.io.IOException; -import java.text.ParseException; -import java.util.Arrays; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashSet; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ExcludeRule; -import org.apache.ivy.core.module.descriptor.License; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.descriptor.Configuration.Visibility; -import org.apache.ivy.core.module.id.ModuleId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.conflict.ConflictManager; -import org.apache.ivy.plugins.conflict.FixedConflictManager; -import org.apache.ivy.plugins.conflict.NoConflictManager; -import org.apache.ivy.plugins.matcher.ExactPatternMatcher; -import org.apache.ivy.plugins.matcher.GlobPatternMatcher; -import org.apache.ivy.plugins.matcher.PatternMatcher; -import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParserTester; -import org.apache.ivy.util.XMLHelper; - -/** - * - */ -public class XmlModuleDescriptorParserTest extends AbstractModuleDescriptorParserTester { - // junit test -- DO NOT REMOVE used by ant to know it's a junit test - - private IvySettings _settings = new IvySettings(); - - public void testSimple() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-simple.xml"), true); - assertNotNull(md); - assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); - assertEquals("mymodule", md.getModuleRevisionId().getName()); - assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision()); - assertEquals("integration", md.getStatus()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays - .asList(md.getConfigurations())); - - assertNotNull(md.getArtifacts("default")); - assertEquals(1, md.getArtifacts("default").length); - assertEquals("mymodule", md.getArtifacts("default")[0].getName()); - assertEquals("jar", md.getArtifacts("default")[0].getType()); - - assertNotNull(md.getDependencies()); - assertEquals(0, md.getDependencies().length); - } - - public void testEmptyDependencies() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-empty-dependencies.xml"), true); - assertNotNull(md); - assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); - assertEquals("mymodule", md.getModuleRevisionId().getName()); - assertEquals("myrev", md.getModuleRevisionId().getRevision()); - assertEquals("integration", md.getStatus()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays - .asList(md.getConfigurations())); - - assertNotNull(md.getArtifacts("default")); - assertEquals(1, md.getArtifacts("default").length); - assertEquals("mymodule", md.getArtifacts("default")[0].getName()); - assertEquals("jar", md.getArtifacts("default")[0].getType()); - - assertNotNull(md.getDependencies()); - assertEquals(0, md.getDependencies().length); - } - - public void testBad() throws IOException { - try { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-bad.xml"), true); - fail("bad ivy file raised no error"); - } catch (ParseException ex) { - if (XMLHelper.canUseSchemaValidation()) { - assertTrue("exception message not explicit. It should contain 'modul', but it's:" - + ex.getMessage(), ex.getMessage().indexOf("'modul'") != -1); - } - } - } - - public void testBadOrg() throws IOException { - try { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-bad-org.xml"), true); - if (XMLHelper.canUseSchemaValidation()) { - fail("bad ivy file raised no error"); - } - } catch (ParseException ex) { - if (XMLHelper.canUseSchemaValidation()) { - assertTrue("invalid exception: " + ex.getMessage(), ex.getMessage().indexOf( - "organization") != -1); - } - } - } - - public void testBadConfs() throws IOException { - try { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-bad-confs.xml"), true); - fail("bad ivy file raised no error"); - } catch (ParseException ex) { - assertTrue("invalid exception: " + ex.getMessage(), ex.getMessage().indexOf( - "invalidConf") != -1); - } - } - - public void testNoValidate() throws IOException, ParseException { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-novalidate.xml"), false); - } - - public void testBadVersion() throws IOException { - try { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-bad-version.xml"), true); - fail("bad version ivy file raised no error"); - } catch (ParseException ex) { - // ok - } - } - - public void testFull() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test.xml"), true); - assertNotNull(md); - assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); - assertEquals("mymodule", md.getModuleRevisionId().getName()); - assertEquals("myrev", md.getModuleRevisionId().getRevision()); - assertEquals("integration", md.getStatus()); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - assertEquals(pubdate, md.getPublicationDate()); - - License[] licenses = md.getLicenses(); - assertEquals(1, licenses.length); - assertEquals("MyLicense", licenses[0].getName()); - assertEquals("http://www.my.org/mymodule/mylicense.html", licenses[0].getUrl()); - - assertEquals("http://www.my.org/mymodule/", md.getHomePage()); - - Configuration[] confs = md.getConfigurations(); - assertNotNull(confs); - assertEquals(5, confs.length); - - assertConf(md, "myconf1", "desc 1", Configuration.Visibility.PUBLIC, new String[0]); - assertConf(md, "myconf2", "desc 2", Configuration.Visibility.PUBLIC, new String[0]); - assertConf(md, "myconf3", "desc 3", Configuration.Visibility.PRIVATE, new String[0]); - assertConf(md, "myconf4", "desc 4", Configuration.Visibility.PUBLIC, new String[] { - "myconf1", "myconf2"}); - assertConf(md, "myoldconf", "my old desc", Configuration.Visibility.PUBLIC, new String[0]); - - assertArtifacts(md.getArtifacts("myconf1"), new String[] {"myartifact1", "myartifact2", - "myartifact3", "myartifact4"}); - assertArtifacts(md.getArtifacts("myconf2"), new String[] {"myartifact1", "myartifact3"}); - assertArtifacts(md.getArtifacts("myconf3"), new String[] {"myartifact1", "myartifact3", - "myartifact4"}); - assertArtifacts(md.getArtifacts("myconf4"), new String[] {"myartifact1"}); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(13, dependencies.length); - - // no conf def => equivalent to *->* - DependencyDescriptor dd = getDependency(dependencies, "mymodule2"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - assertFalse(dd.isChanging()); - assertTrue(dd.isTransitive()); - - // changing = true - dd = getDependency(dependencies, "mymodule3"); - assertNotNull(dd); - assertTrue(dd.isChanging()); - assertFalse(dd.isTransitive()); - - // conf="myconf1" => equivalent to myconf1->myconf1 - dd = getDependency(dependencies, "yourmodule1"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("1.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - - // conf="myconf1->yourconf1" - dd = getDependency(dependencies, "yourmodule2"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("2+", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - - // conf="myconf1->yourconf1, yourconf2" - dd = getDependency(dependencies, "yourmodule3"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("3.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - - // conf="myconf1, myconf2->yourconf1, yourconf2" - dd = getDependency(dependencies, "yourmodule4"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("4.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( - Arrays.asList(dd.getModuleConfigurations()))); - assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd - .getDependencyConfigurations("myconf2"))); - assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - - // conf="myconf1->yourconf1;myconf2->yourconf1, yourconf2" - dd = getDependency(dependencies, "yourmodule5"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("5.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( - Arrays.asList(dd.getModuleConfigurations()))); - assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd - .getDependencyConfigurations("myconf2"))); - assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - - // conf="*->@" - dd = getDependency(dependencies, "yourmodule11"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("11.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"*"})), new HashSet(Arrays.asList(dd - .getModuleConfigurations()))); - assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {"myconf2"}), Arrays.asList(dd - .getDependencyConfigurations("myconf2"))); - assertEquals(Arrays.asList(new String[] {"myconf3"}), Arrays.asList(dd - .getDependencyConfigurations("myconf3"))); - assertEquals(Arrays.asList(new String[] {"myconf4"}), Arrays.asList(dd - .getDependencyConfigurations("myconf4"))); - - dd = getDependency(dependencies, "yourmodule6"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("latest.integration", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( - Arrays.asList(dd.getModuleConfigurations()))); - assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd - .getDependencyConfigurations("myconf2"))); - assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - - dd = getDependency(dependencies, "yourmodule7"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("7.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( - Arrays.asList(dd.getModuleConfigurations()))); - assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd - .getDependencyConfigurations("myconf1"))); - assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd - .getDependencyConfigurations("myconf2"))); - assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd - .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", - "myconf4"}, new String[0]); - - dd = getDependency(dependencies, "yourmodule8"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("8.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"*"})), new HashSet(Arrays.asList(dd - .getModuleConfigurations()))); - assertDependencyArtifacts(dd, new String[] {"myconf1"}, new String[] {"yourartifact8-1", - "yourartifact8-2"}); - assertDependencyArtifacts(dd, new String[] {"myconf2"}, new String[] {"yourartifact8-1", - "yourartifact8-2"}); - assertDependencyArtifacts(dd, new String[] {"myconf3"}, new String[] {"yourartifact8-1", - "yourartifact8-2"}); - assertDependencyArtifacts(dd, new String[] {"myconf4"}, new String[] {"yourartifact8-1", - "yourartifact8-2"}); - - dd = getDependency(dependencies, "yourmodule9"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("9.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2", "myconf3"})), - new HashSet(Arrays.asList(dd.getModuleConfigurations()))); - assertDependencyArtifacts(dd, new String[] {"myconf1"}, new String[] {"yourartifact9-1"}); - assertDependencyArtifacts(dd, new String[] {"myconf2"}, new String[] {"yourartifact9-1", - "yourartifact9-2"}); - assertDependencyArtifacts(dd, new String[] {"myconf3"}, new String[] {"yourartifact9-2"}); - assertDependencyArtifacts(dd, new String[] {"myconf4"}, new String[] {}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf1"}, new String[] {}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf2"}, new String[] {}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf3"}, new String[] {}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf4"}, new String[] {}); - - dd = getDependency(dependencies, "yourmodule10"); - assertNotNull(dd); - assertEquals("yourorg", dd.getDependencyId().getOrganisation()); - assertEquals("10.1", dd.getDependencyRevisionId().getRevision()); - assertEquals(new HashSet(Arrays.asList(new String[] {"*"})), new HashSet(Arrays.asList(dd - .getModuleConfigurations()))); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1"}, new String[] {"your.*", - PatternMatcher.ANY_EXPRESSION}); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf2"}, new String[] {"your.*", - PatternMatcher.ANY_EXPRESSION}); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf3"}, new String[] {"your.*", - PatternMatcher.ANY_EXPRESSION}); - assertDependencyArtifactIncludeRules(dd, new String[] {"myconf4"}, new String[] {"your.*", - PatternMatcher.ANY_EXPRESSION}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf1"}, - new String[] {"toexclude"}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf2"}, - new String[] {"toexclude"}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf3"}, - new String[] {"toexclude"}); - assertDependencyArtifactExcludeRules(dd, new String[] {"myconf4"}, - new String[] {"toexclude"}); - - ConflictManager cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule1")); - assertNotNull(cm); - assertTrue(cm instanceof NoConflictManager); - - cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule2")); - assertNotNull(cm); - assertTrue(cm instanceof NoConflictManager); - - cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule1")); - assertNotNull(cm); - assertTrue(cm instanceof FixedConflictManager); - FixedConflictManager fcm = (FixedConflictManager) cm; - assertEquals(2, fcm.getRevs().size()); - assertTrue(fcm.getRevs().contains("1.0")); - assertTrue(fcm.getRevs().contains("1.1")); - - cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule2")); - assertNull(cm); - - ExcludeRule[] rules = md.getAllExcludeRules(); - assertNotNull(rules); - assertEquals(2, rules.length); - assertEquals(GlobPatternMatcher.INSTANCE, rules[0].getMatcher()); - assertEquals(ExactPatternMatcher.INSTANCE, rules[1].getMatcher()); - assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(rules[0] - .getConfigurations())); - assertEquals(Arrays.asList(new String[] {"myconf1", "myconf2", "myconf3", "myconf4", - "myoldconf"}), Arrays.asList(rules[1].getConfigurations())); - } - - public void testBug60() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-bug60.xml"), true); - assertNotNull(md); - assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); - assertEquals("mymodule", md.getModuleRevisionId().getName()); - assertEquals("myrev", md.getModuleRevisionId().getRevision()); - assertEquals("integration", md.getStatus()); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - assertEquals(pubdate, md.getPublicationDate()); - - assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays - .asList(md.getConfigurations())); - - assertArtifacts(md.getArtifacts("default"), new String[] {"myartifact1", "myartifact2"}); - } - - public void testNoArtifact() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-noartifact.xml"), true); - assertNotNull(md); - assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); - assertEquals("mymodule", md.getModuleRevisionId().getName()); - assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision()); - assertEquals("integration", md.getStatus()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays - .asList(md.getConfigurations())); - - assertNotNull(md.getArtifacts("default")); - assertEquals(0, md.getArtifacts("default").length); - - assertNotNull(md.getDependencies()); - assertEquals(0, md.getDependencies().length); - } - - public void testNoPublication() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-nopublication.xml"), true); - assertNotNull(md); - assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); - assertEquals("mymodule", md.getModuleRevisionId().getName()); - assertEquals("myrev", md.getModuleRevisionId().getRevision()); - assertEquals("integration", md.getStatus()); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - assertEquals(pubdate, md.getPublicationDate()); - - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays - .asList(md.getConfigurations())); - - assertNotNull(md.getArtifacts("default")); - assertEquals(1, md.getArtifacts("default").length); - - assertNotNull(md.getDependencies()); - assertEquals(1, md.getDependencies().length); - } - - public void testArtifactsDefaults() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-artifacts-defaults.xml"), true); - assertNotNull(md); - - Artifact[] artifacts = md.getArtifacts("default"); - assertNotNull(artifacts); - assertEquals(3, artifacts.length); - assertArtifactEquals("mymodule", "jar", "jar", artifacts[0]); - assertArtifactEquals("myartifact", "jar", "jar", artifacts[1]); - assertArtifactEquals("mymodule", "dll", "dll", artifacts[2]); - } - - private void assertArtifactEquals(String name, String type, String ext, Artifact artifact) { - assertEquals(name + "/" + type + "/" + ext, artifact.getName() + "/" + artifact.getType() - + "/" + artifact.getExt()); - } - - public void testDefaultConf() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-defaultconf.xml"), true); - assertNotNull(md); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // no conf def => defaults to defaultConf: default - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd - .getDependencyConfigurations("default"))); - - // confs def: *->* - dd = getDependency(dependencies, "mymodule2"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("default"))); - } - - public void testDefaultConf2() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-defaultconf2.xml"), true); - assertNotNull(md); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // no conf def => defaults to defaultConf: *->default - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd - .getDependencyConfigurations("default"))); - assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd - .getDependencyConfigurations("test"))); - - // confs def: test: should not use default conf for the right side (use of - // defaultconfmapping is required for that) => test->test - dd = getDependency(dependencies, "mymodule2"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd - .getDependencyConfigurations("test"))); - } - - public void testDefaultConfMapping() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-defaultconfmapping.xml"), true); - assertNotNull(md); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // no conf def => defaults to defaultConf: *->default - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd - .getDependencyConfigurations("default"))); - assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd - .getDependencyConfigurations("test"))); - - // confs def: test: should use default conf mapping for the right side => test->default - dd = getDependency(dependencies, "mymodule2"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); - assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd - .getDependencyConfigurations("test"))); - } - - public void testExtraAttributes() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-extra-attributes.xml"), false); - assertNotNull(md); - - assertEquals("infoextravalue", md.getAttribute("infoextra")); - assertEquals("infoextravalue", md.getModuleRevisionId().getAttribute("infoextra")); - - assertEquals("confextravalue", md.getConfiguration("default").getAttribute("confextra")); - - Artifact[] artifacts = md.getArtifacts("default"); - assertEquals(1, artifacts.length); - Artifact art = artifacts[0]; - assertEquals("art1", art.getName()); - assertEquals("artextravalue", art.getAttribute("artextra")); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(1, dependencies.length); - - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertNotNull(dd); - assertEquals("myorg", dd.getDependencyId().getOrganisation()); - assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); - assertEquals("depextravalue", dd.getAttribute("depextra")); - assertEquals("depextravalue", dd.getDependencyRevisionId().getAttribute("depextra")); - } - - public void testImportConfigurations1() throws Exception { - // import configurations - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-configurations-import1.xml"), true); - assertNotNull(md); - - // should have imported configurations - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(new Configuration[] { - new Configuration("conf1", Visibility.PUBLIC, "", new String[0]), - new Configuration("conf2", Visibility.PRIVATE, "", new String[0])}), Arrays - .asList(md.getConfigurations())); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // no conf def => defaults to defaultConf: *->* - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("conf1"))); - - // confs def: conf1->* - dd = getDependency(dependencies, "mymodule2"); - assertEquals(Arrays.asList(new String[] {"conf1"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("conf1"))); - } - - public void testImportConfigurations2() throws Exception { - // import configurations and add another one - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-configurations-import2.xml"), true); - assertNotNull(md); - - // should have imported configurations and added the one defined in the file itself - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(new Configuration[] { - new Configuration("conf1", Visibility.PUBLIC, "", new String[0]), - new Configuration("conf2", Visibility.PRIVATE, "", new String[0]), - new Configuration("conf3", Visibility.PUBLIC, "", new String[0])}), Arrays - .asList(md.getConfigurations())); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // no conf def => defaults to defaultConf: *->* - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("conf1"))); - - // confs def: conf2,conf3->* - dd = getDependency(dependencies, "mymodule2"); - assertEquals(new HashSet(Arrays.asList(new String[] {"conf2", "conf3"})), new HashSet( - Arrays.asList(dd.getModuleConfigurations()))); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("conf2"))); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("conf3"))); - } - - public void testImportConfigurations3() throws Exception { - // import configurations and default mapping - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-configurations-import3.xml"), true); - assertNotNull(md); - - // should have imported configurations - assertNotNull(md.getConfigurations()); - assertEquals(Arrays.asList(new Configuration[] { - new Configuration("conf1", Visibility.PUBLIC, "", new String[0]), - new Configuration("conf2", Visibility.PRIVATE, "", new String[0])}), Arrays - .asList(md.getConfigurations())); - - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // no conf def => defaults to defaultConf defined in imported file: *->@ - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"conf1"}), Arrays.asList(dd - .getDependencyConfigurations("conf1"))); - assertEquals(Arrays.asList(new String[] {"conf2"}), Arrays.asList(dd - .getDependencyConfigurations("conf2"))); - - // confs def: conf1->* - dd = getDependency(dependencies, "mymodule2"); - assertEquals(Arrays.asList(new String[] {"conf1"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd - .getDependencyConfigurations("conf1"))); - } - - public void testExtendOtherConfigs() throws Exception { - // import configurations and default mapping - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-configextendsothers1.xml"), true); - assertNotNull(md); - - // has an 'all-public' configuration - Configuration allPublic = md.getConfiguration("all-public"); - assertNotNull(allPublic); - - // 'all-public' extends all other public configurations - String[] allPublicExt = allPublic.getExtends(); - assertEquals(Arrays.asList(new String[] {"default", "test"}), Arrays.asList(allPublicExt)); - } - - public void testImportConfigurationsWithExtendOtherConfigs() throws Exception { - // import configurations and default mapping - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-configextendsothers2.xml"), true); - assertNotNull(md); - - // has an 'all-public' configuration - Configuration allPublic = md.getConfiguration("all-public"); - assertNotNull(allPublic); - - // 'all-public' extends all other public configurations - String[] allPublicExt = allPublic.getExtends(); - assertEquals(Arrays.asList(new String[] {"default", "test", "extra"}), Arrays - .asList(allPublicExt)); - } - - public void testImportConfigurationsWithMappingOverride() throws Exception { - // import configurations and default mapping - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-configurations-import4.xml"), true); - assertNotNull(md); - - // has 2 dependencies - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // confs dep1: conf1->A;conf2->B (mappingoverride = true) - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertEquals(Arrays.asList(new String[] {"conf1", "conf2"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"A"}), Arrays.asList(dd - .getDependencyConfigurations("conf1"))); - assertEquals(Arrays.asList(new String[] {"B"}), Arrays.asList(dd - .getDependencyConfigurations("conf2"))); - - // confs dep2: conf2->B - dd = getDependency(dependencies, "mymodule2"); - assertEquals(Arrays.asList(new String[] {"conf2"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"B"}), Arrays.asList(dd - .getDependencyConfigurations("conf2"))); - } - - public void testImportConfigurationsWithWildcardAndMappingOverride() throws Exception { - // import configurations and default mapping - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-configextendsothers3.xml"), true); - assertNotNull(md); - - // has 2 dependencies - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(2, dependencies.length); - - // confs dep1: all-public->all-public (mappingoverride = true) - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertEquals(Arrays.asList(new String[] {"all-public"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"all-public"}), Arrays.asList(dd - .getDependencyConfigurations("all-public"))); - - // confs dep2: extra->extra;all-public->all-public (mappingoverride = true) - dd = getDependency(dependencies, "mymodule2"); - assertEquals(Arrays.asList(new String[] {"extra", "all-public"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"extra"}), Arrays.asList(dd - .getDependencyConfigurations("extra"))); - assertEquals(Arrays.asList(new String[] {"all-public"}), Arrays.asList(dd - .getDependencyConfigurations("all-public"))); - } - - public void testDefaultConfMappingWithSelectors() throws Exception { - // import configurations and default mapping - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-defaultconfmapping-withselectors.xml"), true); - assertNotNull(md); - - // has 3 dependencies - DependencyDescriptor[] dependencies = md.getDependencies(); - assertNotNull(dependencies); - assertEquals(3, dependencies.length); - - // confs dep1: *->default1,default3 - DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"default1", "default3"}), Arrays.asList(dd - .getDependencyConfigurations("default"))); - - // confs dep2: test->default2,default3 - dd = getDependency(dependencies, "mymodule2"); - assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd - .getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"default2", "default3"}), Arrays.asList(dd - .getDependencyConfigurations("test"))); - - // confs dep3: *->default4 - dd = getDependency(dependencies, "mymodule3"); - assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); - assertEquals(Arrays.asList(new String[] {"default4"}), Arrays.asList(dd - .getDependencyConfigurations("bla"))); - } - - public void testWithNonExistingConfigInDependency() throws Exception { - // IVY-442 - try { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-incorrectconf1.xml"), true); - fail("ParseException hasn't been thrown"); - } catch (ParseException e) { - // expected - } - } - - public void testWithNonExistingConfigInPublications() throws Exception { - try { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-incorrectconf2.xml"), true); - fail("ParseException hasn't been thrown"); - } catch (ParseException e) { - // expected - } - } - - public void testWithExistingConfigsInPublicationsSeparatedBySemiColon() throws Exception { - // IVY-441 - try { - XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, - getClass().getResource("test-incorrectconf3.xml"), true); - fail("ParseException hasn't been thrown"); - } catch (ParseException e) { - // expected - } - } -} +/* + * 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.parser.xml; + +import java.io.IOException; +import java.text.ParseException; +import java.util.Arrays; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ExcludeRule; +import org.apache.ivy.core.module.descriptor.License; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.descriptor.Configuration.Visibility; +import org.apache.ivy.core.module.id.ModuleId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.conflict.ConflictManager; +import org.apache.ivy.plugins.conflict.FixedConflictManager; +import org.apache.ivy.plugins.conflict.NoConflictManager; +import org.apache.ivy.plugins.matcher.ExactPatternMatcher; +import org.apache.ivy.plugins.matcher.GlobPatternMatcher; +import org.apache.ivy.plugins.matcher.PatternMatcher; +import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParserTester; +import org.apache.ivy.util.XMLHelper; + +/** + * + */ +public class XmlModuleDescriptorParserTest extends AbstractModuleDescriptorParserTester { + // junit test -- DO NOT REMOVE used by ant to know it's a junit test + + private IvySettings _settings = new IvySettings(); + + public void testSimple() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-simple.xml"), true); + assertNotNull(md); + assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); + assertEquals("mymodule", md.getModuleRevisionId().getName()); + assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision()); + assertEquals("integration", md.getStatus()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays + .asList(md.getConfigurations())); + + assertNotNull(md.getArtifacts("default")); + assertEquals(1, md.getArtifacts("default").length); + assertEquals("mymodule", md.getArtifacts("default")[0].getName()); + assertEquals("jar", md.getArtifacts("default")[0].getType()); + + assertNotNull(md.getDependencies()); + assertEquals(0, md.getDependencies().length); + } + + public void testEmptyDependencies() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-empty-dependencies.xml"), true); + assertNotNull(md); + assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); + assertEquals("mymodule", md.getModuleRevisionId().getName()); + assertEquals("myrev", md.getModuleRevisionId().getRevision()); + assertEquals("integration", md.getStatus()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays + .asList(md.getConfigurations())); + + assertNotNull(md.getArtifacts("default")); + assertEquals(1, md.getArtifacts("default").length); + assertEquals("mymodule", md.getArtifacts("default")[0].getName()); + assertEquals("jar", md.getArtifacts("default")[0].getType()); + + assertNotNull(md.getDependencies()); + assertEquals(0, md.getDependencies().length); + } + + public void testBad() throws IOException { + try { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-bad.xml"), true); + fail("bad ivy file raised no error"); + } catch (ParseException ex) { + if (XMLHelper.canUseSchemaValidation()) { + assertTrue("exception message not explicit. It should contain 'modul', but it's:" + + ex.getMessage(), ex.getMessage().indexOf("'modul'") != -1); + } + } + } + + public void testBadOrg() throws IOException { + try { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-bad-org.xml"), true); + if (XMLHelper.canUseSchemaValidation()) { + fail("bad ivy file raised no error"); + } + } catch (ParseException ex) { + if (XMLHelper.canUseSchemaValidation()) { + assertTrue("invalid exception: " + ex.getMessage(), ex.getMessage().indexOf( + "organization") != -1); + } + } + } + + public void testBadConfs() throws IOException { + try { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-bad-confs.xml"), true); + fail("bad ivy file raised no error"); + } catch (ParseException ex) { + assertTrue("invalid exception: " + ex.getMessage(), ex.getMessage().indexOf( + "invalidConf") != -1); + } + } + + public void testNoValidate() throws IOException, ParseException { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-novalidate.xml"), false); + } + + public void testBadVersion() throws IOException { + try { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-bad-version.xml"), true); + fail("bad version ivy file raised no error"); + } catch (ParseException ex) { + // ok + } + } + + public void testFull() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test.xml"), true); + assertNotNull(md); + assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); + assertEquals("mymodule", md.getModuleRevisionId().getName()); + assertEquals("myrev", md.getModuleRevisionId().getRevision()); + assertEquals("integration", md.getStatus()); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + assertEquals(pubdate, md.getPublicationDate()); + + License[] licenses = md.getLicenses(); + assertEquals(1, licenses.length); + assertEquals("MyLicense", licenses[0].getName()); + assertEquals("http://www.my.org/mymodule/mylicense.html", licenses[0].getUrl()); + + assertEquals("http://www.my.org/mymodule/", md.getHomePage()); + + Configuration[] confs = md.getConfigurations(); + assertNotNull(confs); + assertEquals(5, confs.length); + + assertConf(md, "myconf1", "desc 1", Configuration.Visibility.PUBLIC, new String[0]); + assertConf(md, "myconf2", "desc 2", Configuration.Visibility.PUBLIC, new String[0]); + assertConf(md, "myconf3", "desc 3", Configuration.Visibility.PRIVATE, new String[0]); + assertConf(md, "myconf4", "desc 4", Configuration.Visibility.PUBLIC, new String[] { + "myconf1", "myconf2"}); + assertConf(md, "myoldconf", "my old desc", Configuration.Visibility.PUBLIC, new String[0]); + + assertArtifacts(md.getArtifacts("myconf1"), new String[] {"myartifact1", "myartifact2", + "myartifact3", "myartifact4"}); + assertArtifacts(md.getArtifacts("myconf2"), new String[] {"myartifact1", "myartifact3"}); + assertArtifacts(md.getArtifacts("myconf3"), new String[] {"myartifact1", "myartifact3", + "myartifact4"}); + assertArtifacts(md.getArtifacts("myconf4"), new String[] {"myartifact1"}); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(13, dependencies.length); + + // no conf def => equivalent to *->* + DependencyDescriptor dd = getDependency(dependencies, "mymodule2"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + assertFalse(dd.isChanging()); + assertTrue(dd.isTransitive()); + + // changing = true + dd = getDependency(dependencies, "mymodule3"); + assertNotNull(dd); + assertTrue(dd.isChanging()); + assertFalse(dd.isTransitive()); + + // conf="myconf1" => equivalent to myconf1->myconf1 + dd = getDependency(dependencies, "yourmodule1"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("1.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + + // conf="myconf1->yourconf1" + dd = getDependency(dependencies, "yourmodule2"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("2+", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + + // conf="myconf1->yourconf1, yourconf2" + dd = getDependency(dependencies, "yourmodule3"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("3.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf2", "myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + + // conf="myconf1, myconf2->yourconf1, yourconf2" + dd = getDependency(dependencies, "yourmodule4"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("4.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( + Arrays.asList(dd.getModuleConfigurations()))); + assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd + .getDependencyConfigurations("myconf2"))); + assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + + // conf="myconf1->yourconf1;myconf2->yourconf1, yourconf2" + dd = getDependency(dependencies, "yourmodule5"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("5.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( + Arrays.asList(dd.getModuleConfigurations()))); + assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd + .getDependencyConfigurations("myconf2"))); + assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + + // conf="*->@" + dd = getDependency(dependencies, "yourmodule11"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("11.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"*"})), new HashSet(Arrays.asList(dd + .getModuleConfigurations()))); + assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {"myconf2"}), Arrays.asList(dd + .getDependencyConfigurations("myconf2"))); + assertEquals(Arrays.asList(new String[] {"myconf3"}), Arrays.asList(dd + .getDependencyConfigurations("myconf3"))); + assertEquals(Arrays.asList(new String[] {"myconf4"}), Arrays.asList(dd + .getDependencyConfigurations("myconf4"))); + + dd = getDependency(dependencies, "yourmodule6"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("latest.integration", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( + Arrays.asList(dd.getModuleConfigurations()))); + assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd + .getDependencyConfigurations("myconf2"))); + assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + + dd = getDependency(dependencies, "yourmodule7"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("7.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2"})), new HashSet( + Arrays.asList(dd.getModuleConfigurations()))); + assertEquals(Arrays.asList(new String[] {"yourconf1"}), Arrays.asList(dd + .getDependencyConfigurations("myconf1"))); + assertEquals(Arrays.asList(new String[] {"yourconf1", "yourconf2"}), Arrays.asList(dd + .getDependencyConfigurations("myconf2"))); + assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd + .getDependencyConfigurations(new String[] {"myconf3", "myconf4"}))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1", "myconf2", "myconf3", + "myconf4"}, new String[0]); + + dd = getDependency(dependencies, "yourmodule8"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("8.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"*"})), new HashSet(Arrays.asList(dd + .getModuleConfigurations()))); + assertDependencyArtifacts(dd, new String[] {"myconf1"}, new String[] {"yourartifact8-1", + "yourartifact8-2"}); + assertDependencyArtifacts(dd, new String[] {"myconf2"}, new String[] {"yourartifact8-1", + "yourartifact8-2"}); + assertDependencyArtifacts(dd, new String[] {"myconf3"}, new String[] {"yourartifact8-1", + "yourartifact8-2"}); + assertDependencyArtifacts(dd, new String[] {"myconf4"}, new String[] {"yourartifact8-1", + "yourartifact8-2"}); + + dd = getDependency(dependencies, "yourmodule9"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("9.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"myconf1", "myconf2", "myconf3"})), + new HashSet(Arrays.asList(dd.getModuleConfigurations()))); + assertDependencyArtifacts(dd, new String[] {"myconf1"}, new String[] {"yourartifact9-1"}); + assertDependencyArtifacts(dd, new String[] {"myconf2"}, new String[] {"yourartifact9-1", + "yourartifact9-2"}); + assertDependencyArtifacts(dd, new String[] {"myconf3"}, new String[] {"yourartifact9-2"}); + assertDependencyArtifacts(dd, new String[] {"myconf4"}, new String[] {}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf1"}, new String[] {}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf2"}, new String[] {}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf3"}, new String[] {}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf4"}, new String[] {}); + + dd = getDependency(dependencies, "yourmodule10"); + assertNotNull(dd); + assertEquals("yourorg", dd.getDependencyId().getOrganisation()); + assertEquals("10.1", dd.getDependencyRevisionId().getRevision()); + assertEquals(new HashSet(Arrays.asList(new String[] {"*"})), new HashSet(Arrays.asList(dd + .getModuleConfigurations()))); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf1"}, new String[] {"your.*", + PatternMatcher.ANY_EXPRESSION}); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf2"}, new String[] {"your.*", + PatternMatcher.ANY_EXPRESSION}); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf3"}, new String[] {"your.*", + PatternMatcher.ANY_EXPRESSION}); + assertDependencyArtifactIncludeRules(dd, new String[] {"myconf4"}, new String[] {"your.*", + PatternMatcher.ANY_EXPRESSION}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf1"}, + new String[] {"toexclude"}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf2"}, + new String[] {"toexclude"}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf3"}, + new String[] {"toexclude"}); + assertDependencyArtifactExcludeRules(dd, new String[] {"myconf4"}, + new String[] {"toexclude"}); + + ConflictManager cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule1")); + assertNotNull(cm); + assertTrue(cm instanceof NoConflictManager); + + cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule2")); + assertNotNull(cm); + assertTrue(cm instanceof NoConflictManager); + + cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule1")); + assertNotNull(cm); + assertTrue(cm instanceof FixedConflictManager); + FixedConflictManager fcm = (FixedConflictManager) cm; + assertEquals(2, fcm.getRevs().size()); + assertTrue(fcm.getRevs().contains("1.0")); + assertTrue(fcm.getRevs().contains("1.1")); + + cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule2")); + assertNull(cm); + + ExcludeRule[] rules = md.getAllExcludeRules(); + assertNotNull(rules); + assertEquals(2, rules.length); + assertEquals(GlobPatternMatcher.INSTANCE, rules[0].getMatcher()); + assertEquals(ExactPatternMatcher.INSTANCE, rules[1].getMatcher()); + assertEquals(Arrays.asList(new String[] {"myconf1"}), Arrays.asList(rules[0] + .getConfigurations())); + assertEquals(Arrays.asList(new String[] {"myconf1", "myconf2", "myconf3", "myconf4", + "myoldconf"}), Arrays.asList(rules[1].getConfigurations())); + } + + public void testBug60() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-bug60.xml"), true); + assertNotNull(md); + assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); + assertEquals("mymodule", md.getModuleRevisionId().getName()); + assertEquals("myrev", md.getModuleRevisionId().getRevision()); + assertEquals("integration", md.getStatus()); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + assertEquals(pubdate, md.getPublicationDate()); + + assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays + .asList(md.getConfigurations())); + + assertArtifacts(md.getArtifacts("default"), new String[] {"myartifact1", "myartifact2"}); + } + + public void testNoArtifact() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-noartifact.xml"), true); + assertNotNull(md); + assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); + assertEquals("mymodule", md.getModuleRevisionId().getName()); + assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision()); + assertEquals("integration", md.getStatus()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays + .asList(md.getConfigurations())); + + assertNotNull(md.getArtifacts("default")); + assertEquals(0, md.getArtifacts("default").length); + + assertNotNull(md.getDependencies()); + assertEquals(0, md.getDependencies().length); + } + + public void testNoPublication() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-nopublication.xml"), true); + assertNotNull(md); + assertEquals("myorg", md.getModuleRevisionId().getOrganisation()); + assertEquals("mymodule", md.getModuleRevisionId().getName()); + assertEquals("myrev", md.getModuleRevisionId().getRevision()); + assertEquals("integration", md.getStatus()); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + assertEquals(pubdate, md.getPublicationDate()); + + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(new Configuration[] {new Configuration("default")}), Arrays + .asList(md.getConfigurations())); + + assertNotNull(md.getArtifacts("default")); + assertEquals(1, md.getArtifacts("default").length); + + assertNotNull(md.getDependencies()); + assertEquals(1, md.getDependencies().length); + } + + public void testArtifactsDefaults() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-artifacts-defaults.xml"), true); + assertNotNull(md); + + Artifact[] artifacts = md.getArtifacts("default"); + assertNotNull(artifacts); + assertEquals(3, artifacts.length); + assertArtifactEquals("mymodule", "jar", "jar", artifacts[0]); + assertArtifactEquals("myartifact", "jar", "jar", artifacts[1]); + assertArtifactEquals("mymodule", "dll", "dll", artifacts[2]); + } + + private void assertArtifactEquals(String name, String type, String ext, Artifact artifact) { + assertEquals(name + "/" + type + "/" + ext, artifact.getName() + "/" + artifact.getType() + + "/" + artifact.getExt()); + } + + public void testDefaultConf() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-defaultconf.xml"), true); + assertNotNull(md); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // no conf def => defaults to defaultConf: default + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd + .getDependencyConfigurations("default"))); + + // confs def: *->* + dd = getDependency(dependencies, "mymodule2"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("default"))); + } + + public void testDefaultConf2() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-defaultconf2.xml"), true); + assertNotNull(md); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // no conf def => defaults to defaultConf: *->default + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd + .getDependencyConfigurations("default"))); + assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd + .getDependencyConfigurations("test"))); + + // confs def: test: should not use default conf for the right side (use of + // defaultconfmapping is required for that) => test->test + dd = getDependency(dependencies, "mymodule2"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd + .getDependencyConfigurations("test"))); + } + + public void testDefaultConfMapping() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-defaultconfmapping.xml"), true); + assertNotNull(md); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // no conf def => defaults to defaultConf: *->default + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd + .getDependencyConfigurations("default"))); + assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd + .getDependencyConfigurations("test"))); + + // confs def: test: should use default conf mapping for the right side => test->default + dd = getDependency(dependencies, "mymodule2"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("2.0", dd.getDependencyRevisionId().getRevision()); + assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"default"}), Arrays.asList(dd + .getDependencyConfigurations("test"))); + } + + public void testExtraAttributes() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-extra-attributes.xml"), false); + assertNotNull(md); + + assertEquals("infoextravalue", md.getAttribute("infoextra")); + assertEquals("infoextravalue", md.getModuleRevisionId().getAttribute("infoextra")); + + assertEquals("confextravalue", md.getConfiguration("default").getAttribute("confextra")); + + Artifact[] artifacts = md.getArtifacts("default"); + assertEquals(1, artifacts.length); + Artifact art = artifacts[0]; + assertEquals("art1", art.getName()); + assertEquals("artextravalue", art.getAttribute("artextra")); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(1, dependencies.length); + + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertNotNull(dd); + assertEquals("myorg", dd.getDependencyId().getOrganisation()); + assertEquals("1.0", dd.getDependencyRevisionId().getRevision()); + assertEquals("depextravalue", dd.getAttribute("depextra")); + assertEquals("depextravalue", dd.getDependencyRevisionId().getAttribute("depextra")); + } + + public void testImportConfigurations1() throws Exception { + // import configurations + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-configurations-import1.xml"), true); + assertNotNull(md); + + // should have imported configurations + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(new Configuration[] { + new Configuration("conf1", Visibility.PUBLIC, "", new String[0]), + new Configuration("conf2", Visibility.PRIVATE, "", new String[0])}), Arrays + .asList(md.getConfigurations())); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // no conf def => defaults to defaultConf: *->* + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("conf1"))); + + // confs def: conf1->* + dd = getDependency(dependencies, "mymodule2"); + assertEquals(Arrays.asList(new String[] {"conf1"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("conf1"))); + } + + public void testImportConfigurations2() throws Exception { + // import configurations and add another one + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-configurations-import2.xml"), true); + assertNotNull(md); + + // should have imported configurations and added the one defined in the file itself + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(new Configuration[] { + new Configuration("conf1", Visibility.PUBLIC, "", new String[0]), + new Configuration("conf2", Visibility.PRIVATE, "", new String[0]), + new Configuration("conf3", Visibility.PUBLIC, "", new String[0])}), Arrays + .asList(md.getConfigurations())); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // no conf def => defaults to defaultConf: *->* + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("conf1"))); + + // confs def: conf2,conf3->* + dd = getDependency(dependencies, "mymodule2"); + assertEquals(new HashSet(Arrays.asList(new String[] {"conf2", "conf3"})), new HashSet( + Arrays.asList(dd.getModuleConfigurations()))); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("conf2"))); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("conf3"))); + } + + public void testImportConfigurations3() throws Exception { + // import configurations and default mapping + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-configurations-import3.xml"), true); + assertNotNull(md); + + // should have imported configurations + assertNotNull(md.getConfigurations()); + assertEquals(Arrays.asList(new Configuration[] { + new Configuration("conf1", Visibility.PUBLIC, "", new String[0]), + new Configuration("conf2", Visibility.PRIVATE, "", new String[0])}), Arrays + .asList(md.getConfigurations())); + + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // no conf def => defaults to defaultConf defined in imported file: *->@ + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"conf1"}), Arrays.asList(dd + .getDependencyConfigurations("conf1"))); + assertEquals(Arrays.asList(new String[] {"conf2"}), Arrays.asList(dd + .getDependencyConfigurations("conf2"))); + + // confs def: conf1->* + dd = getDependency(dependencies, "mymodule2"); + assertEquals(Arrays.asList(new String[] {"conf1"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd + .getDependencyConfigurations("conf1"))); + } + + public void testExtendOtherConfigs() throws Exception { + // import configurations and default mapping + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-configextendsothers1.xml"), true); + assertNotNull(md); + + // has an 'all-public' configuration + Configuration allPublic = md.getConfiguration("all-public"); + assertNotNull(allPublic); + + // 'all-public' extends all other public configurations + String[] allPublicExt = allPublic.getExtends(); + assertEquals(Arrays.asList(new String[] {"default", "test"}), Arrays.asList(allPublicExt)); + } + + public void testImportConfigurationsWithExtendOtherConfigs() throws Exception { + // import configurations and default mapping + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-configextendsothers2.xml"), true); + assertNotNull(md); + + // has an 'all-public' configuration + Configuration allPublic = md.getConfiguration("all-public"); + assertNotNull(allPublic); + + // 'all-public' extends all other public configurations + String[] allPublicExt = allPublic.getExtends(); + assertEquals(Arrays.asList(new String[] {"default", "test", "extra"}), Arrays + .asList(allPublicExt)); + } + + public void testImportConfigurationsWithMappingOverride() throws Exception { + // import configurations and default mapping + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-configurations-import4.xml"), true); + assertNotNull(md); + + // has 2 dependencies + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // confs dep1: conf1->A;conf2->B (mappingoverride = true) + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertEquals(Arrays.asList(new String[] {"conf1", "conf2"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"A"}), Arrays.asList(dd + .getDependencyConfigurations("conf1"))); + assertEquals(Arrays.asList(new String[] {"B"}), Arrays.asList(dd + .getDependencyConfigurations("conf2"))); + + // confs dep2: conf2->B + dd = getDependency(dependencies, "mymodule2"); + assertEquals(Arrays.asList(new String[] {"conf2"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"B"}), Arrays.asList(dd + .getDependencyConfigurations("conf2"))); + } + + public void testImportConfigurationsWithWildcardAndMappingOverride() throws Exception { + // import configurations and default mapping + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-configextendsothers3.xml"), true); + assertNotNull(md); + + // has 2 dependencies + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(2, dependencies.length); + + // confs dep1: all-public->all-public (mappingoverride = true) + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertEquals(Arrays.asList(new String[] {"all-public"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"all-public"}), Arrays.asList(dd + .getDependencyConfigurations("all-public"))); + + // confs dep2: extra->extra;all-public->all-public (mappingoverride = true) + dd = getDependency(dependencies, "mymodule2"); + assertEquals(Arrays.asList(new String[] {"extra", "all-public"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"extra"}), Arrays.asList(dd + .getDependencyConfigurations("extra"))); + assertEquals(Arrays.asList(new String[] {"all-public"}), Arrays.asList(dd + .getDependencyConfigurations("all-public"))); + } + + public void testDefaultConfMappingWithSelectors() throws Exception { + // import configurations and default mapping + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-defaultconfmapping-withselectors.xml"), true); + assertNotNull(md); + + // has 3 dependencies + DependencyDescriptor[] dependencies = md.getDependencies(); + assertNotNull(dependencies); + assertEquals(3, dependencies.length); + + // confs dep1: *->default1,default3 + DependencyDescriptor dd = getDependency(dependencies, "mymodule1"); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"default1", "default3"}), Arrays.asList(dd + .getDependencyConfigurations("default"))); + + // confs dep2: test->default2,default3 + dd = getDependency(dependencies, "mymodule2"); + assertEquals(Arrays.asList(new String[] {"test"}), Arrays.asList(dd + .getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"default2", "default3"}), Arrays.asList(dd + .getDependencyConfigurations("test"))); + + // confs dep3: *->default4 + dd = getDependency(dependencies, "mymodule3"); + assertEquals(Arrays.asList(new String[] {"*"}), Arrays.asList(dd.getModuleConfigurations())); + assertEquals(Arrays.asList(new String[] {"default4"}), Arrays.asList(dd + .getDependencyConfigurations("bla"))); + } + + public void testWithNonExistingConfigInDependency() throws Exception { + // IVY-442 + try { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-incorrectconf1.xml"), true); + fail("ParseException hasn't been thrown"); + } catch (ParseException e) { + // expected + } + } + + public void testWithNonExistingConfigInPublications() throws Exception { + try { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-incorrectconf2.xml"), true); + fail("ParseException hasn't been thrown"); + } catch (ParseException e) { + // expected + } + } + + public void testWithExistingConfigsInPublicationsSeparatedBySemiColon() throws Exception { + // IVY-441 + try { + XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, + getClass().getResource("test-incorrectconf3.xml"), true); + fail("ParseException hasn't been thrown"); + } catch (ParseException e) { + // expected + } + } +} diff --git a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java index dfcc4edb..ca4493bc 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java +++ b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriterTest.java @@ -1,111 +1,111 @@ -/* - * 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.parser.xml; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.GregorianCalendar; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.util.FileUtil; - -public class XmlModuleDescriptorWriterTest extends TestCase { - private static String LICENSE; - static { - try { - LICENSE = FileUtil.readEntirely(new BufferedReader(new InputStreamReader( - XmlModuleDescriptorWriterTest.class.getResourceAsStream("license.xml")))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private File _dest = new File("build/test/test-write.xml"); - - public void testSimple() throws Exception { - DefaultModuleDescriptor md = (DefaultModuleDescriptor) XmlModuleDescriptorParser - .getInstance().parseDescriptor(new IvySettings(), - XmlModuleDescriptorWriterTest.class.getResource("test-simple.xml"), true); - md.setResolvedPublicationDate(new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime()); - md.setResolvedModuleRevisionId(new ModuleRevisionId(md.getModuleRevisionId().getModuleId(), - "NONE")); - XmlModuleDescriptorWriter.write(md, LICENSE, _dest); - - assertTrue(_dest.exists()); - String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest))).replaceAll( - "\r\n", "\n").replace('\r', '\n'); - String expected = readEntirely("test-write-simple.xml").replaceAll("\r\n", "\n").replace( - '\r', '\n'); - assertEquals(expected, wrote); - } - - public void testDependencies() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), - XmlModuleDescriptorWriterTest.class.getResource("test-dependencies.xml"), true); - XmlModuleDescriptorWriter.write(md, LICENSE, _dest); - - assertTrue(_dest.exists()); - String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest))).replaceAll( - "\r\n", "\n").replace('\r', '\n'); - String expected = readEntirely("test-write-dependencies.xml").replaceAll("\r\n", "\n") - .replace('\r', '\n'); - assertEquals(expected, wrote); - } - - public void testFull() throws Exception { - ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( - new IvySettings(), XmlModuleDescriptorWriterTest.class.getResource("test.xml"), true); - XmlModuleDescriptorWriter.write(md, LICENSE, _dest); - - assertTrue(_dest.exists()); - String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest))).replaceAll( - "\r\n", "\n").replace('\r', '\n'); - String expected = readEntirely("test-write-full.xml").replaceAll("\r\n", "\n").replace( - '\r', '\n'); - assertEquals(expected, wrote); - } - - private String readEntirely(String resource) throws IOException { - return FileUtil.readEntirely(new BufferedReader(new InputStreamReader( - XmlModuleDescriptorWriterTest.class.getResource(resource).openStream()))); - } - - public void setUp() { - if (_dest.exists()) { - _dest.delete(); - } - if (!_dest.getParentFile().exists()) { - _dest.getParentFile().mkdirs(); - } - } - - protected void tearDown() throws Exception { - if (_dest.exists()) { - _dest.delete(); - } - } -} +/* + * 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.parser.xml; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.util.FileUtil; + +public class XmlModuleDescriptorWriterTest extends TestCase { + private static String LICENSE; + static { + try { + LICENSE = FileUtil.readEntirely(new BufferedReader(new InputStreamReader( + XmlModuleDescriptorWriterTest.class.getResourceAsStream("license.xml")))); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private File _dest = new File("build/test/test-write.xml"); + + public void testSimple() throws Exception { + DefaultModuleDescriptor md = (DefaultModuleDescriptor) XmlModuleDescriptorParser + .getInstance().parseDescriptor(new IvySettings(), + XmlModuleDescriptorWriterTest.class.getResource("test-simple.xml"), true); + md.setResolvedPublicationDate(new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime()); + md.setResolvedModuleRevisionId(new ModuleRevisionId(md.getModuleRevisionId().getModuleId(), + "NONE")); + XmlModuleDescriptorWriter.write(md, LICENSE, _dest); + + assertTrue(_dest.exists()); + String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest))).replaceAll( + "\r\n", "\n").replace('\r', '\n'); + String expected = readEntirely("test-write-simple.xml").replaceAll("\r\n", "\n").replace( + '\r', '\n'); + assertEquals(expected, wrote); + } + + public void testDependencies() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), + XmlModuleDescriptorWriterTest.class.getResource("test-dependencies.xml"), true); + XmlModuleDescriptorWriter.write(md, LICENSE, _dest); + + assertTrue(_dest.exists()); + String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest))).replaceAll( + "\r\n", "\n").replace('\r', '\n'); + String expected = readEntirely("test-write-dependencies.xml").replaceAll("\r\n", "\n") + .replace('\r', '\n'); + assertEquals(expected, wrote); + } + + public void testFull() throws Exception { + ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor( + new IvySettings(), XmlModuleDescriptorWriterTest.class.getResource("test.xml"), true); + XmlModuleDescriptorWriter.write(md, LICENSE, _dest); + + assertTrue(_dest.exists()); + String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(_dest))).replaceAll( + "\r\n", "\n").replace('\r', '\n'); + String expected = readEntirely("test-write-full.xml").replaceAll("\r\n", "\n").replace( + '\r', '\n'); + assertEquals(expected, wrote); + } + + private String readEntirely(String resource) throws IOException { + return FileUtil.readEntirely(new BufferedReader(new InputStreamReader( + XmlModuleDescriptorWriterTest.class.getResource(resource).openStream()))); + } + + public void setUp() { + if (_dest.exists()) { + _dest.delete(); + } + if (!_dest.getParentFile().exists()) { + _dest.getParentFile().mkdirs(); + } + } + + protected void tearDown() throws Exception { + if (_dest.exists()) { + _dest.delete(); + } + } +} diff --git a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java index f7041eee..ea0730a4 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java +++ b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java @@ -1,207 +1,207 @@ -/* - * 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.parser.xml; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileReader; -import java.io.InputStreamReader; -import java.util.Arrays; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.Configuration; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.plugins.repository.BasicResource; -import org.apache.ivy.util.FileUtil; -import org.xml.sax.SAXParseException; - -public class XmlModuleUpdaterTest extends TestCase { - - public void testUpdate() throws Exception { - /* - * For updated file to be equals to updated.xml, we have to fix the line separator to the - * one used in updated.xml, in order for this test to works in all platforms (default line - * separator used in updater being platform dependent - */ - XmlModuleDescriptorUpdater.LINE_SEPARATOR = "\n"; - File dest = new File("build/updated-test.xml"); - dest.deleteOnExit(); - Map resolvedRevisions = new HashMap(); - resolvedRevisions.put(ModuleRevisionId.newInstance("yourorg", "yourmodule2", "2+"), "2.5"); - resolvedRevisions.put(ModuleRevisionId.newInstance("yourorg", "yourmodule6", - "latest.integration"), "6.3"); - - GregorianCalendar cal = new GregorianCalendar(); - cal.set(2005, 2, 22, 14, 32, 54); - - Ivy ivy = Ivy.newInstance(); - ivy.setVariable("myvar", "myconf1"); - XmlModuleDescriptorUpdater.update(ivy.getSettings(), XmlModuleUpdaterTest.class - .getResource("test-update.xml"), dest, resolvedRevisions, "release", "mynewrev", - cal.getTime(), null, true, null); - - assertTrue(dest.exists()); - String expected = FileUtil.readEntirely(new BufferedReader(new InputStreamReader( - XmlModuleUpdaterTest.class.getResourceAsStream("updated.xml")))); - String updated = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))); - assertEquals(expected, updated); - } - - public void testUpdateWithImportedMappingOverride() throws Exception { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class - .getResourceAsStream("test-configurations-import4.xml"), buffer, new HashMap(), - "release", "mynewrev", new Date(), null, true); - - String updatedXml = buffer.toString(); - - // just make sure that 'confmappingoverride="true"' is declared somewhere in the XML. - assertTrue("Updated XML doesn't define the confmappingoverride attribute", updatedXml - .indexOf("confmappingoverride=\"true\"") != -1); - } - - public void testUpdateWithExcludeConfigurations1() throws Exception { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class - .getResourceAsStream("test-update-excludedconfs1.xml"), buffer, new HashMap(), - "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); - - XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); - ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), - new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, - false), true); - - // test the number of configurations - Configuration[] configs = updatedMd.getConfigurations(); - assertNotNull("Configurations shouldn't be null", configs); - assertEquals("Number of configurations incorrect", 3, configs.length); - - // test that the correct configuration has been removed - assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2")); - - // test that the other configurations aren't removed - assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1")); - assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3")); - assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4")); - } - - public void testUpdateWithExcludeConfigurations2() throws Exception { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - try { - XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class - .getResourceAsStream("test-update-excludedconfs2.xml"), buffer, new HashMap(), - "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); - fail("IllegalArgumentException hasn't been thrown"); - } catch (IllegalArgumentException e) { - // this is ok - } catch (SAXParseException e) { - // this is ok too - } - } - - public void testUpdateWithExcludeConfigurations3() throws Exception { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class - .getResourceAsStream("test-update-excludedconfs3.xml"), buffer, new HashMap(), - "release", "mynewrev", new Date(), null, true, new String[] {"myconf2", "conf2"}); - - XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); - ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), - new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, - false), true); - - // test the number of configurations - Configuration[] configs = updatedMd.getConfigurations(); - assertNotNull("Configurations shouldn't be null", configs); - assertEquals("Number of configurations incorrect", 4, configs.length); - - // test that the correct configuration has been removed - assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2")); - assertNull("conf2 hasn't been removed", updatedMd.getConfiguration("conf2")); - - // test that the other configurations aren't removed - assertNotNull("conf1 has been removed", updatedMd.getConfiguration("conf1")); - assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1")); - assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3")); - assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4")); - } - - public void testUpdateWithExcludeConfigurations4() throws Exception { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class - .getResourceAsStream("test-update-excludedconfs4.xml"), buffer, new HashMap(), - "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); - - XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); - ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), - new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, - false), true); - - // test the number of configurations - Artifact[] artifacts = updatedMd.getAllArtifacts(); - assertNotNull("Published artifacts shouldn't be null", artifacts); - assertEquals("Number of published artifacts incorrect", 4, artifacts.length); - - // test that the correct configuration has been removed - for (int i = 0; i < artifacts.length; i++) { - Artifact current = artifacts[i]; - List currentConfs = Arrays.asList(current.getConfigurations()); - assertTrue("myconf2 hasn't been removed for artifact " + current.getName(), - !currentConfs.contains("myconf2")); - } - } - - public void testUpdateWithExcludeConfigurations5() throws Exception { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class - .getResourceAsStream("test-update-excludedconfs5.xml"), buffer, new HashMap(), - "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); - - XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); - ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), - new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, - false), true); - - DependencyDescriptor[] deps = updatedMd.getDependencies(); - assertNotNull("Dependencies shouldn't be null", deps); - assertEquals("Number of dependencies is incorrect", 8, deps.length); - - // check that none of the dependencies contains myconf2 - for (int i = 0; i < deps.length; i++) { - String name = deps[i].getDependencyId().getName(); - assertFalse("Dependency " + name + " shouldn't have myconf2 as module configuration", - Arrays.asList(deps[i].getModuleConfigurations()).contains("myconf2")); - assertEquals("Dependency " + name - + " shouldn't have a dependency artifact for configuration myconf2", 0, deps[i] - .getDependencyArtifacts("myconf2").length); - } - } -} +/* + * 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.parser.xml; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.Configuration; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.plugins.repository.BasicResource; +import org.apache.ivy.util.FileUtil; +import org.xml.sax.SAXParseException; + +public class XmlModuleUpdaterTest extends TestCase { + + public void testUpdate() throws Exception { + /* + * For updated file to be equals to updated.xml, we have to fix the line separator to the + * one used in updated.xml, in order for this test to works in all platforms (default line + * separator used in updater being platform dependent + */ + XmlModuleDescriptorUpdater.LINE_SEPARATOR = "\n"; + File dest = new File("build/updated-test.xml"); + dest.deleteOnExit(); + Map resolvedRevisions = new HashMap(); + resolvedRevisions.put(ModuleRevisionId.newInstance("yourorg", "yourmodule2", "2+"), "2.5"); + resolvedRevisions.put(ModuleRevisionId.newInstance("yourorg", "yourmodule6", + "latest.integration"), "6.3"); + + GregorianCalendar cal = new GregorianCalendar(); + cal.set(2005, 2, 22, 14, 32, 54); + + Ivy ivy = Ivy.newInstance(); + ivy.setVariable("myvar", "myconf1"); + XmlModuleDescriptorUpdater.update(ivy.getSettings(), XmlModuleUpdaterTest.class + .getResource("test-update.xml"), dest, resolvedRevisions, "release", "mynewrev", + cal.getTime(), null, true, null); + + assertTrue(dest.exists()); + String expected = FileUtil.readEntirely(new BufferedReader(new InputStreamReader( + XmlModuleUpdaterTest.class.getResourceAsStream("updated.xml")))); + String updated = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))); + assertEquals(expected, updated); + } + + public void testUpdateWithImportedMappingOverride() throws Exception { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class + .getResourceAsStream("test-configurations-import4.xml"), buffer, new HashMap(), + "release", "mynewrev", new Date(), null, true); + + String updatedXml = buffer.toString(); + + // just make sure that 'confmappingoverride="true"' is declared somewhere in the XML. + assertTrue("Updated XML doesn't define the confmappingoverride attribute", updatedXml + .indexOf("confmappingoverride=\"true\"") != -1); + } + + public void testUpdateWithExcludeConfigurations1() throws Exception { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class + .getResourceAsStream("test-update-excludedconfs1.xml"), buffer, new HashMap(), + "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); + + XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); + ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), + new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, + false), true); + + // test the number of configurations + Configuration[] configs = updatedMd.getConfigurations(); + assertNotNull("Configurations shouldn't be null", configs); + assertEquals("Number of configurations incorrect", 3, configs.length); + + // test that the correct configuration has been removed + assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2")); + + // test that the other configurations aren't removed + assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1")); + assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3")); + assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4")); + } + + public void testUpdateWithExcludeConfigurations2() throws Exception { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + try { + XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class + .getResourceAsStream("test-update-excludedconfs2.xml"), buffer, new HashMap(), + "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); + fail("IllegalArgumentException hasn't been thrown"); + } catch (IllegalArgumentException e) { + // this is ok + } catch (SAXParseException e) { + // this is ok too + } + } + + public void testUpdateWithExcludeConfigurations3() throws Exception { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class + .getResourceAsStream("test-update-excludedconfs3.xml"), buffer, new HashMap(), + "release", "mynewrev", new Date(), null, true, new String[] {"myconf2", "conf2"}); + + XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); + ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), + new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, + false), true); + + // test the number of configurations + Configuration[] configs = updatedMd.getConfigurations(); + assertNotNull("Configurations shouldn't be null", configs); + assertEquals("Number of configurations incorrect", 4, configs.length); + + // test that the correct configuration has been removed + assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2")); + assertNull("conf2 hasn't been removed", updatedMd.getConfiguration("conf2")); + + // test that the other configurations aren't removed + assertNotNull("conf1 has been removed", updatedMd.getConfiguration("conf1")); + assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1")); + assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3")); + assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4")); + } + + public void testUpdateWithExcludeConfigurations4() throws Exception { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class + .getResourceAsStream("test-update-excludedconfs4.xml"), buffer, new HashMap(), + "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); + + XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); + ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), + new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, + false), true); + + // test the number of configurations + Artifact[] artifacts = updatedMd.getAllArtifacts(); + assertNotNull("Published artifacts shouldn't be null", artifacts); + assertEquals("Number of published artifacts incorrect", 4, artifacts.length); + + // test that the correct configuration has been removed + for (int i = 0; i < artifacts.length; i++) { + Artifact current = artifacts[i]; + List currentConfs = Arrays.asList(current.getConfigurations()); + assertTrue("myconf2 hasn't been removed for artifact " + current.getName(), + !currentConfs.contains("myconf2")); + } + } + + public void testUpdateWithExcludeConfigurations5() throws Exception { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + XmlModuleDescriptorUpdater.update(new IvySettings(), XmlModuleUpdaterTest.class + .getResourceAsStream("test-update-excludedconfs5.xml"), buffer, new HashMap(), + "release", "mynewrev", new Date(), null, true, new String[] {"myconf2"}); + + XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance(); + ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), + new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, + false), true); + + DependencyDescriptor[] deps = updatedMd.getDependencies(); + assertNotNull("Dependencies shouldn't be null", deps); + assertEquals("Number of dependencies is incorrect", 8, deps.length); + + // check that none of the dependencies contains myconf2 + for (int i = 0; i < deps.length; i++) { + String name = deps[i].getDependencyId().getName(); + assertFalse("Dependency " + name + " shouldn't have myconf2 as module configuration", + Arrays.asList(deps[i].getModuleConfigurations()).contains("myconf2")); + assertEquals("Dependency " + name + + " shouldn't have a dependency artifact for configuration myconf2", 0, deps[i] + .getDependencyArtifacts("myconf2").length); + } + } +} diff --git a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mapping.xml b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mapping.xml index eccc08cc..ec405f6a 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mapping.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mapping.xml @@ -1,22 +1,22 @@ - - - - - + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mappingoverride.xml b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mappingoverride.xml index 2ba78eca..e13ec711 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mappingoverride.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-mappingoverride.xml @@ -1,22 +1,22 @@ - - - - - + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-wildcard.xml b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-wildcard.xml index 1f347e1c..0ba8f816 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-wildcard.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations-with-wildcard.xml @@ -1,23 +1,23 @@ - - - - - - + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations.xml b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations.xml index 4f7785c1..9ca58549 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/imported-configurations.xml @@ -1,22 +1,22 @@ - - - - - + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/license.xml b/test/java/org/apache/ivy/plugins/parser/xml/license.xml index 84312b7a..1c1b8cf7 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/license.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/license.xml @@ -1,18 +1,18 @@ - + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-artifacts-defaults.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-artifacts-defaults.xml index 9b307c55..b57b30f0 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-artifacts-defaults.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-artifacts-defaults.xml @@ -1,28 +1,28 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-bad-confs.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-bad-confs.xml index f02e3de5..7287882d 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-bad-confs.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-bad-confs.xml @@ -1,27 +1,27 @@ - - - - - - - + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-bad-org.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-bad-org.xml index a62a062b..dc9afbb8 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-bad-org.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-bad-org.xml @@ -1,24 +1,24 @@ - - - - + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-bad-version.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-bad-version.xml index f7116e8c..4b859017 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-bad-version.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-bad-version.xml @@ -1,24 +1,24 @@ - - - - + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-bad.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-bad.xml index f3916b4a..12c680d7 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-bad.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-bad.xml @@ -1,24 +1,24 @@ - - - - + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-bug60.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-bug60.xml index bcf03553..1c53e6cb 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-bug60.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-bug60.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers1.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers1.xml index da31c517..5d5a46cc 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers1.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers1.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers2.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers2.xml index a45dde98..de8b0800 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers2.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers2.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers3.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers3.xml index 12990e2f..ce5fecd7 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers3.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-configextendsothers3.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import1.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import1.xml index a32c58b3..65500931 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import1.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import1.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import2.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import2.xml index db644b06..7040c743 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import2.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import2.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import3.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import3.xml index fabf84a3..8984dcb3 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import3.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import3.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import4.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import4.xml index 4a5aa630..3c4dbf97 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import4.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-configurations-import4.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf.xml index 7599e814..c1892608 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf.xml @@ -1,31 +1,31 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf2.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf2.xml index 03f1a975..925cf753 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf2.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconf2.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping-withselectors.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping-withselectors.xml index fcf1a3fb..e10b9378 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping-withselectors.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping-withselectors.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping.xml index 8c7ea875..742efb19 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-defaultconfmapping.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-dependencies.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-dependencies.xml index 355414dc..55aae183 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-dependencies.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-dependencies.xml @@ -1,31 +1,31 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-empty-dependencies.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-empty-dependencies.xml index 6818302b..3240dc4f 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-empty-dependencies.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-empty-dependencies.xml @@ -1,28 +1,28 @@ - - - - - - + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-extra-attributes.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-extra-attributes.xml index f7381fe9..5d3023f3 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-extra-attributes.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-extra-attributes.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf1.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf1.xml index e95da1dd..a26dfdbc 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf1.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf1.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf2.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf2.xml index 2eaa8d4a..502e956e 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf2.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf2.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf3.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf3.xml index 376ecf5a..635f7120 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf3.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-incorrectconf3.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-noartifact.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-noartifact.xml index 8c294de4..e09b89cd 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-noartifact.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-noartifact.xml @@ -1,24 +1,24 @@ - - - - - + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-nopublication.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-nopublication.xml index c7ed6fa1..212d5051 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-nopublication.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-nopublication.xml @@ -1,32 +1,32 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-novalidate.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-novalidate.xml index 8191599f..cfa28162 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-novalidate.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-novalidate.xml @@ -1,27 +1,27 @@ - - - - - - + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-simple.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-simple.xml index e8feca4e..844cd499 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-simple.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-simple.xml @@ -1,23 +1,23 @@ - - - - + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs1.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs1.xml index aa4c3ec0..62bd9d1a 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs1.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs1.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs2.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs2.xml index e5edbc8c..07e4edc8 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs2.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs2.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml index 8d04216f..3f26e35f 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs3.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs4.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs4.xml index 2c34d254..68ad6882 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs4.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs4.xml @@ -1,48 +1,48 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs5.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs5.xml index 06880f3a..35089e61 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs5.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update-excludedconfs5.xml @@ -1,83 +1,83 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml index 7e96400a..4142a890 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-update.xml @@ -1,111 +1,111 @@ - - - - - - - - - - - - - - - - - This module is great !
      - You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. -
      -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      + + + + + + + + + + + + + + + + + This module is great !
      + You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-write-dependencies.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-write-dependencies.xml index 00f373f9..433d87e5 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-write-dependencies.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-write-dependencies.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml index 9714602c..7489eac1 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-write-full.xml @@ -1,65 +1,65 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test-write-simple.xml b/test/java/org/apache/ivy/plugins/parser/xml/test-write-simple.xml index a8c53fb9..fd565e74 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test-write-simple.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test-write-simple.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/parser/xml/test.xml b/test/java/org/apache/ivy/plugins/parser/xml/test.xml index a1ce814d..091dc30a 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/test.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/test.xml @@ -1,107 +1,107 @@ - - - - - - - - - - - - - - This module is great !
      - You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. -
      -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      + + + + + + + + + + + + + + This module is great !
      + You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      diff --git a/test/java/org/apache/ivy/plugins/parser/xml/updated.xml b/test/java/org/apache/ivy/plugins/parser/xml/updated.xml index 2cf6c0a1..cf85a9ea 100644 --- a/test/java/org/apache/ivy/plugins/parser/xml/updated.xml +++ b/test/java/org/apache/ivy/plugins/parser/xml/updated.xml @@ -1,108 +1,108 @@ - - - - - - - - - - - - - - - - - This module is great !
      - You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. -
      -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      + + + + + + + + + + + + + + + + + This module is great !
      + You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too. +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      diff --git a/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java b/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java index d4b173c0..7e6d0cd2 100644 --- a/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java +++ b/test/java/org/apache/ivy/plugins/report/XmlReportOutputterTest.java @@ -1,114 +1,114 @@ -/* - * 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.report; - -import java.io.ByteArrayOutputStream; -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class XmlReportOutputterTest extends TestCase { - private final Ivy _ivy; - - private File _cache; - - public XmlReportOutputterTest() throws Exception { - _ivy = new Ivy(); - _ivy.configure(new File("test/repositories/ivysettings.xml")); - } - - protected void setUp() throws Exception { - createCache(); - } - - 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(); - } - - public void testWriteOrigin() throws Exception { - ResolveReport report = _ivy.resolve(new File( - "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), - getResolveOptions(new String[] {"default"})); - assertNotNull(report); - - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - XmlReportOutputter outputter = new XmlReportOutputter(); - outputter.output(report.getConfigurationReport("default"), buffer); - buffer.flush(); - String xml = buffer.toString(); - - String expectedLocation = "location=\"" - + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath() - + "\""; - String expectedIsLocal = "is-local=\"true\""; - - assertTrue("XML doesn't contain artifact location attribute", - xml.indexOf(expectedLocation) != -1); - assertTrue("XML doesn't contain artifact is-local attribute", - xml.indexOf(expectedIsLocal) != -1); - } - - public void testWriteModuleInfo() throws Exception { - ResolveReport report = _ivy.resolve(new File( - "test/java/org/apache/ivy/plugins/report/ivy-with-info.xml").toURL(), - getResolveOptions(new String[] {"default"}).setValidate(false)); - assertNotNull(report); - - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - XmlReportOutputter outputter = new XmlReportOutputter(); - outputter.output(report.getConfigurationReport("default"), buffer); - buffer.flush(); - String xml = buffer.toString(); - - String orgAttribute = "organisation=\"org1\""; - String modAttribute = "module=\"mod1\""; - String revAttribute = "revision=\"1.0\""; - String extra1Attribute = "extra-blabla=\"abc\""; - String extra2Attribute = "extra-blabla2=\"123\""; - - assertTrue("XML doesn't contain organisation attribute", xml.indexOf(orgAttribute) != -1); - assertTrue("XML doesn't contain module attribute", xml.indexOf(modAttribute) != -1); - assertTrue("XML doesn't contain revision attribute", xml.indexOf(revAttribute) != -1); - assertTrue("XML doesn't contain extra attribute 1", xml.indexOf(extra1Attribute) != -1); - assertTrue("XML doesn't contain extra attribute 2", xml.indexOf(extra2Attribute) != -1); - } - - private ResolveOptions getResolveOptions(String[] confs) { - return new ResolveOptions().setConfs(confs).setCache( - CacheManager.getInstance(_ivy.getSettings(), _cache)); - } -} +/* + * 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.report; + +import java.io.ByteArrayOutputStream; +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class XmlReportOutputterTest extends TestCase { + private final Ivy _ivy; + + private File _cache; + + public XmlReportOutputterTest() throws Exception { + _ivy = new Ivy(); + _ivy.configure(new File("test/repositories/ivysettings.xml")); + } + + protected void setUp() throws Exception { + createCache(); + } + + 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(); + } + + public void testWriteOrigin() throws Exception { + ResolveReport report = _ivy.resolve(new File( + "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), + getResolveOptions(new String[] {"default"})); + assertNotNull(report); + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + XmlReportOutputter outputter = new XmlReportOutputter(); + outputter.output(report.getConfigurationReport("default"), buffer); + buffer.flush(); + String xml = buffer.toString(); + + String expectedLocation = "location=\"" + + new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath() + + "\""; + String expectedIsLocal = "is-local=\"true\""; + + assertTrue("XML doesn't contain artifact location attribute", + xml.indexOf(expectedLocation) != -1); + assertTrue("XML doesn't contain artifact is-local attribute", + xml.indexOf(expectedIsLocal) != -1); + } + + public void testWriteModuleInfo() throws Exception { + ResolveReport report = _ivy.resolve(new File( + "test/java/org/apache/ivy/plugins/report/ivy-with-info.xml").toURL(), + getResolveOptions(new String[] {"default"}).setValidate(false)); + assertNotNull(report); + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + XmlReportOutputter outputter = new XmlReportOutputter(); + outputter.output(report.getConfigurationReport("default"), buffer); + buffer.flush(); + String xml = buffer.toString(); + + String orgAttribute = "organisation=\"org1\""; + String modAttribute = "module=\"mod1\""; + String revAttribute = "revision=\"1.0\""; + String extra1Attribute = "extra-blabla=\"abc\""; + String extra2Attribute = "extra-blabla2=\"123\""; + + assertTrue("XML doesn't contain organisation attribute", xml.indexOf(orgAttribute) != -1); + assertTrue("XML doesn't contain module attribute", xml.indexOf(modAttribute) != -1); + assertTrue("XML doesn't contain revision attribute", xml.indexOf(revAttribute) != -1); + assertTrue("XML doesn't contain extra attribute 1", xml.indexOf(extra1Attribute) != -1); + assertTrue("XML doesn't contain extra attribute 2", xml.indexOf(extra2Attribute) != -1); + } + + private ResolveOptions getResolveOptions(String[] confs) { + return new ResolveOptions().setConfs(confs).setCache( + CacheManager.getInstance(_ivy.getSettings(), _cache)); + } +} diff --git a/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java b/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java index fd8456f4..6831ff3a 100644 --- a/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java +++ b/test/java/org/apache/ivy/plugins/report/XmlReportParserTest.java @@ -1,83 +1,83 @@ -/* - * 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.report; - -import java.io.File; - -import junit.framework.TestCase; - -import org.apache.ivy.Ivy; -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ResolveReport; -import org.apache.ivy.core.resolve.ResolveOptions; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -public class XmlReportParserTest extends TestCase { - private final Ivy _ivy; - - private File _cache; - - public XmlReportParserTest() throws Exception { - _ivy = new Ivy(); - _ivy.configure(new File("test/repositories/ivysettings.xml")); - } - - protected void setUp() throws Exception { - createCache(); - } - - 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(); - } - - public void testGetResolvedModule() throws Exception { - ResolveReport report = _ivy.resolve(new File( - "test/java/org/apache/ivy/plugins/report/ivy-with-info.xml").toURL(), - getResolveOptions(new String[] {"default"}).setValidate(false).setResolveId( - "testGetResolvedModule")); - assertNotNull(report); - - ModuleRevisionId modRevId = report.getModuleDescriptor().getModuleRevisionId(); - - XmlReportParser parser = new XmlReportParser(); - parser.parse(_ivy.getCacheManager(_cache).getConfigurationResolveReportInCache( - "testGetResolvedModule", "default")); - ModuleRevisionId parsedModRevId = parser.getResolvedModule(); - - assertEquals("Resolved module doesn't equals parsed module", modRevId, parsedModRevId); - } - - private ResolveOptions getResolveOptions(String[] confs) { - return new ResolveOptions().setConfs(confs).setCache( - CacheManager.getInstance(_ivy.getSettings(), _cache)); - } -} +/* + * 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.report; + +import java.io.File; + +import junit.framework.TestCase; + +import org.apache.ivy.Ivy; +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.core.resolve.ResolveOptions; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +public class XmlReportParserTest extends TestCase { + private final Ivy _ivy; + + private File _cache; + + public XmlReportParserTest() throws Exception { + _ivy = new Ivy(); + _ivy.configure(new File("test/repositories/ivysettings.xml")); + } + + protected void setUp() throws Exception { + createCache(); + } + + 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(); + } + + public void testGetResolvedModule() throws Exception { + ResolveReport report = _ivy.resolve(new File( + "test/java/org/apache/ivy/plugins/report/ivy-with-info.xml").toURL(), + getResolveOptions(new String[] {"default"}).setValidate(false).setResolveId( + "testGetResolvedModule")); + assertNotNull(report); + + ModuleRevisionId modRevId = report.getModuleDescriptor().getModuleRevisionId(); + + XmlReportParser parser = new XmlReportParser(); + parser.parse(_ivy.getCacheManager(_cache).getConfigurationResolveReportInCache( + "testGetResolvedModule", "default")); + ModuleRevisionId parsedModRevId = parser.getResolvedModule(); + + assertEquals("Resolved module doesn't equals parsed module", modRevId, parsedModRevId); + } + + private ResolveOptions getResolveOptions(String[] confs) { + return new ResolveOptions().setConfs(confs).setCache( + CacheManager.getInstance(_ivy.getSettings(), _cache)); + } +} diff --git a/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml b/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml index 5cbdf858..0bb797d1 100644 --- a/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml +++ b/test/java/org/apache/ivy/plugins/report/ivy-with-info.xml @@ -1,28 +1,28 @@ - - - - + + + + diff --git a/test/java/org/apache/ivy/plugins/resolver/ChainResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/ChainResolverTest.java index 67698993..6550adb7 100644 --- a/test/java/org/apache/ivy/plugins/resolver/ChainResolverTest.java +++ b/test/java/org/apache/ivy/plugins/resolver/ChainResolverTest.java @@ -1,449 +1,449 @@ -/* - * 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.util.Arrays; -import java.util.GregorianCalendar; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -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.settings.XmlSettingsParser; -import org.apache.ivy.core.sort.SortEngine; -import org.apache.ivy.plugins.latest.LatestRevisionStrategy; -import org.apache.ivy.plugins.latest.LatestTimeStrategy; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -/** - * Tests ChainResolver - */ -public class ChainResolverTest extends TestCase { - private IvySettings _settings; - - private ResolveEngine _engine; - - private ResolveData _data; - - private File _cache; - - 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().setCache(CacheManager.getInstance( - _settings, _cache))); - _cache.mkdirs(); - _settings.setDefaultCache(_cache); - } - - protected void tearDown() throws Exception { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - public void testOrderFromConf() throws Exception { - new XmlSettingsParser(_settings).parse(ChainResolverTest.class - .getResource("chainresolverconf.xml")); - DependencyResolver resolver = _settings.getResolver("chain"); - assertNotNull(resolver); - assertTrue(resolver instanceof ChainResolver); - ChainResolver chain = (ChainResolver) resolver; - assertResolversSizeAndNames(chain, 3); - } - - private void assertResolversSizeAndNames(ChainResolver chain, int size) { - List resolvers = chain.getResolvers(); - assertEquals(size, resolvers.size()); - for (int i = 0; i < resolvers.size(); i++) { - DependencyResolver r = (DependencyResolver) resolvers.get(i); - assertEquals(String.valueOf(i + 1), r.getName()); - } - } - - public void testName() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setSettings(_settings); - chain.setName("chain"); - assertEquals("chain", chain.getName()); - } - - public void testResolveOrder() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", false, null), - MockResolver.buildMockResolver("2", true, null), - MockResolver.buildMockResolver("3", true, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "rev"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("2", rmr.getResolver().getName()); - assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), resolvers[0].askedDeps); - assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), resolvers[1].askedDeps); - assertTrue(resolvers[2].askedDeps.isEmpty()); - } - - public void testLatestTimeResolve() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setLatestStrategy(new LatestTimeStrategy()); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", true, new GregorianCalendar(2005, 1, 20) - .getTime()), - MockResolver.buildMockResolver("2", false, null), - MockResolver.buildMockResolver("3", true, new GregorianCalendar(2005, 1, 25) - .getTime()), // younger -> should the one kept - MockResolver.buildMockResolver("4", false, null), - MockResolver.buildMockResolver("5", true, new GregorianCalendar(2005, 1, 22) - .getTime()), - MockResolver.buildMockResolver("6", true, new GregorianCalendar(2005, 1, 18) - .getTime()), MockResolver.buildMockResolver("7", false, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "latest.integration"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("3", rmr.getResolver().getName()); - List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); - for (int i = 0; i < resolvers.length; i++) { - assertEquals(ddAsList, resolvers[i].askedDeps); - } - } - - public void testLatestRevisionResolve() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setLatestStrategy(new LatestRevisionStrategy()); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", true, ModuleRevisionId.newInstance("org", - "mod", "1"), new GregorianCalendar(2005, 1, 20).getTime()), - MockResolver.buildMockResolver("2", false, null), - MockResolver.buildMockResolver("3", true, ModuleRevisionId.newInstance("org", - "mod", "2"), new GregorianCalendar(2005, 1, 25).getTime()), - MockResolver.buildMockResolver("4", false, null), - MockResolver.buildMockResolver("5", true, ModuleRevisionId.newInstance("org", - "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // latest -> - // should the - // one kept - MockResolver.buildMockResolver("6", true, ModuleRevisionId.newInstance("org", - "mod", "3"), new GregorianCalendar(2005, 1, 18).getTime()), - MockResolver.buildMockResolver("7", false, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "latest.integration"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("5", rmr.getResolver().getName()); - List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); - for (int i = 0; i < resolvers.length; i++) { - assertEquals(ddAsList, resolvers[i].askedDeps); - } - } - - public void testWithDefault() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setLatestStrategy(new LatestRevisionStrategy()); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", false, null), - MockResolver.buildMockResolver("2", true, ModuleRevisionId.newInstance("org", - "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime(), true), // latest - // -> - // but - // default - MockResolver.buildMockResolver("3", false, null), - MockResolver.buildMockResolver("4", false, null), - MockResolver.buildMockResolver("5", true, ModuleRevisionId.newInstance("org", - "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // latest -> - // should the - // one kept - MockResolver.buildMockResolver("6", false, null), - MockResolver.buildMockResolver("7", false, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "4"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("5", rmr.getResolver().getName()); - List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); - for (int i = 0; i < 5; i++) { - assertEquals(ddAsList, resolvers[i].askedDeps); - } - for (int i = 5; i < resolvers.length; i++) { - assertTrue(resolvers[i].askedDeps.isEmpty()); - } - } - - public void testLatestWithDefault() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setLatestStrategy(new LatestRevisionStrategy()); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", true, ModuleRevisionId.newInstance("org", - "mod", "1"), new GregorianCalendar(2005, 1, 20).getTime()), - MockResolver.buildMockResolver("2", true, ModuleRevisionId.newInstance("org", - "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime(), true), // latest - // -> - // but - // default - MockResolver.buildMockResolver("3", true, ModuleRevisionId.newInstance("org", - "mod", "2"), new GregorianCalendar(2005, 1, 25).getTime()), - MockResolver.buildMockResolver("4", false, null), - MockResolver.buildMockResolver("5", true, ModuleRevisionId.newInstance("org", - "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // latest -> - // should the - // one kept - MockResolver.buildMockResolver("6", true, ModuleRevisionId.newInstance("org", - "mod", "3"), new GregorianCalendar(2005, 1, 18).getTime()), - MockResolver.buildMockResolver("7", false, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "latest.integration"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("5", rmr.getResolver().getName()); - List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); - for (int i = 0; i < resolvers.length; i++) { - assertEquals(ddAsList, resolvers[i].askedDeps); - } - } - - public void testFixedWithDefault() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setLatestStrategy(new LatestRevisionStrategy()); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", false, null), - MockResolver.buildMockResolver("2", true, ModuleRevisionId.newInstance("org", - "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime(), true), // default - MockResolver.buildMockResolver("3", false, null), - MockResolver.buildMockResolver("4", true, ModuleRevisionId.newInstance("org", - "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // not default - // -> should the - // one kept - MockResolver.buildMockResolver("5", false, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "4"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("4", rmr.getResolver().getName()); - List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); - for (int i = 0; i < 4; i++) { - assertEquals("invalid asked dependencies for " + resolvers[i], ddAsList, - resolvers[i].askedDeps); - } - for (int i = 4; i < resolvers.length; i++) { - assertTrue("invalid asked dependencies for " + resolvers[i], resolvers[i].askedDeps - .isEmpty()); - } - } - - public void testFixedWithDefaultAndRealResolver() throws Exception { - // test case for IVY-206 - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - - // no ivy pattern for first resolver: will only find a 'default' module - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("1"); - resolver.setSettings(_settings); - - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - chain.add(resolver); - - // second resolver has an ivy pattern and will thus find the real module, which should be - // kept - resolver = new FileSystemResolver(); - resolver.setName("2"); - resolver.setSettings(_settings); - - resolver - .addIvyPattern("test/repositories/1/[organisation]/[module]/ivys/ivy-[revision].xml"); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - chain.add(resolver); - - _settings.addResolver(chain); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org1", "mod1.1", "1.0"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("2", rmr.getResolver().getName()); - } - - public void testReturnFirst() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setReturnFirst(true); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", true, new GregorianCalendar(2005, 1, 20) - .getTime()), - MockResolver.buildMockResolver("2", false, null), - MockResolver.buildMockResolver("3", true, new GregorianCalendar(2005, 1, 25) - .getTime()), // younger -> should the one kept - MockResolver.buildMockResolver("4", false, null), - MockResolver.buildMockResolver("5", true, new GregorianCalendar(2005, 1, 22) - .getTime()), - MockResolver.buildMockResolver("6", true, new GregorianCalendar(2005, 1, 18) - .getTime()), MockResolver.buildMockResolver("7", false, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "latest.integration"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("1", rmr.getResolver().getName()); - for (int i = 1; i < resolvers.length; i++) { - assertTrue(resolvers[i].askedDeps.isEmpty()); - } - } - - public void testReturnFirstWithDefaultAndCacheAndRealResolver() throws Exception { - // test case for IVY-207 - - // 1 ---- we first do a first resolve which puts a default file in cache - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - - // no ivy pattern for resolver: will only find a 'default' module - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("old"); - resolver.setSettings(_settings); - - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - chain.add(resolver); - - _settings.addResolver(chain); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org1", "mod1.1", "1.0"), false); - chain.getDependency(dd, _data); - - // 2 ---- now we ask to resolve dependencies with a chain in return first mode, in which the - // first resolver - // is not able to find the module, but the second is - - chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setReturnFirst(true); - - // no pattern for first resolver: will not find the module - resolver = new FileSystemResolver(); - resolver.setName("1"); - resolver.setSettings(_settings); - - chain.add(resolver); - - // second resolver will find the real module, which should be kept - resolver = new FileSystemResolver(); - resolver.setName("2"); - resolver.setSettings(_settings); - - resolver - .addIvyPattern("test/repositories/1/[organisation]/[module]/ivys/ivy-[revision].xml"); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - chain.add(resolver); - - _settings.addResolver(chain); - - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("2", rmr.getResolver().getName()); - } - - public void testDual() throws Exception { - ChainResolver chain = new ChainResolver(); - chain.setName("chain"); - chain.setSettings(_settings); - chain.setDual(true); - MockResolver[] resolvers = new MockResolver[] { - MockResolver.buildMockResolver("1", false, null), - MockResolver.buildMockResolver("2", true, null), - MockResolver.buildMockResolver("3", true, null)}; - for (int i = 0; i < resolvers.length; i++) { - chain.add(resolvers[i]); - } - assertResolversSizeAndNames(chain, resolvers.length); - - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "rev"), false); - ResolvedModuleRevision rmr = chain.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals("2", rmr.getResolver().getName()); - assertEquals("chain", rmr.getArtifactResolver().getName()); - } - -} +/* + * 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.util.Arrays; +import java.util.GregorianCalendar; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +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.settings.XmlSettingsParser; +import org.apache.ivy.core.sort.SortEngine; +import org.apache.ivy.plugins.latest.LatestRevisionStrategy; +import org.apache.ivy.plugins.latest.LatestTimeStrategy; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +/** + * Tests ChainResolver + */ +public class ChainResolverTest extends TestCase { + private IvySettings _settings; + + private ResolveEngine _engine; + + private ResolveData _data; + + private File _cache; + + 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().setCache(CacheManager.getInstance( + _settings, _cache))); + _cache.mkdirs(); + _settings.setDefaultCache(_cache); + } + + protected void tearDown() throws Exception { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + public void testOrderFromConf() throws Exception { + new XmlSettingsParser(_settings).parse(ChainResolverTest.class + .getResource("chainresolverconf.xml")); + DependencyResolver resolver = _settings.getResolver("chain"); + assertNotNull(resolver); + assertTrue(resolver instanceof ChainResolver); + ChainResolver chain = (ChainResolver) resolver; + assertResolversSizeAndNames(chain, 3); + } + + private void assertResolversSizeAndNames(ChainResolver chain, int size) { + List resolvers = chain.getResolvers(); + assertEquals(size, resolvers.size()); + for (int i = 0; i < resolvers.size(); i++) { + DependencyResolver r = (DependencyResolver) resolvers.get(i); + assertEquals(String.valueOf(i + 1), r.getName()); + } + } + + public void testName() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setSettings(_settings); + chain.setName("chain"); + assertEquals("chain", chain.getName()); + } + + public void testResolveOrder() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", false, null), + MockResolver.buildMockResolver("2", true, null), + MockResolver.buildMockResolver("3", true, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "rev"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("2", rmr.getResolver().getName()); + assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), resolvers[0].askedDeps); + assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), resolvers[1].askedDeps); + assertTrue(resolvers[2].askedDeps.isEmpty()); + } + + public void testLatestTimeResolve() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setLatestStrategy(new LatestTimeStrategy()); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", true, new GregorianCalendar(2005, 1, 20) + .getTime()), + MockResolver.buildMockResolver("2", false, null), + MockResolver.buildMockResolver("3", true, new GregorianCalendar(2005, 1, 25) + .getTime()), // younger -> should the one kept + MockResolver.buildMockResolver("4", false, null), + MockResolver.buildMockResolver("5", true, new GregorianCalendar(2005, 1, 22) + .getTime()), + MockResolver.buildMockResolver("6", true, new GregorianCalendar(2005, 1, 18) + .getTime()), MockResolver.buildMockResolver("7", false, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "latest.integration"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("3", rmr.getResolver().getName()); + List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); + for (int i = 0; i < resolvers.length; i++) { + assertEquals(ddAsList, resolvers[i].askedDeps); + } + } + + public void testLatestRevisionResolve() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setLatestStrategy(new LatestRevisionStrategy()); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", true, ModuleRevisionId.newInstance("org", + "mod", "1"), new GregorianCalendar(2005, 1, 20).getTime()), + MockResolver.buildMockResolver("2", false, null), + MockResolver.buildMockResolver("3", true, ModuleRevisionId.newInstance("org", + "mod", "2"), new GregorianCalendar(2005, 1, 25).getTime()), + MockResolver.buildMockResolver("4", false, null), + MockResolver.buildMockResolver("5", true, ModuleRevisionId.newInstance("org", + "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // latest -> + // should the + // one kept + MockResolver.buildMockResolver("6", true, ModuleRevisionId.newInstance("org", + "mod", "3"), new GregorianCalendar(2005, 1, 18).getTime()), + MockResolver.buildMockResolver("7", false, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "latest.integration"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("5", rmr.getResolver().getName()); + List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); + for (int i = 0; i < resolvers.length; i++) { + assertEquals(ddAsList, resolvers[i].askedDeps); + } + } + + public void testWithDefault() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setLatestStrategy(new LatestRevisionStrategy()); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", false, null), + MockResolver.buildMockResolver("2", true, ModuleRevisionId.newInstance("org", + "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime(), true), // latest + // -> + // but + // default + MockResolver.buildMockResolver("3", false, null), + MockResolver.buildMockResolver("4", false, null), + MockResolver.buildMockResolver("5", true, ModuleRevisionId.newInstance("org", + "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // latest -> + // should the + // one kept + MockResolver.buildMockResolver("6", false, null), + MockResolver.buildMockResolver("7", false, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "4"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("5", rmr.getResolver().getName()); + List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); + for (int i = 0; i < 5; i++) { + assertEquals(ddAsList, resolvers[i].askedDeps); + } + for (int i = 5; i < resolvers.length; i++) { + assertTrue(resolvers[i].askedDeps.isEmpty()); + } + } + + public void testLatestWithDefault() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setLatestStrategy(new LatestRevisionStrategy()); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", true, ModuleRevisionId.newInstance("org", + "mod", "1"), new GregorianCalendar(2005, 1, 20).getTime()), + MockResolver.buildMockResolver("2", true, ModuleRevisionId.newInstance("org", + "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime(), true), // latest + // -> + // but + // default + MockResolver.buildMockResolver("3", true, ModuleRevisionId.newInstance("org", + "mod", "2"), new GregorianCalendar(2005, 1, 25).getTime()), + MockResolver.buildMockResolver("4", false, null), + MockResolver.buildMockResolver("5", true, ModuleRevisionId.newInstance("org", + "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // latest -> + // should the + // one kept + MockResolver.buildMockResolver("6", true, ModuleRevisionId.newInstance("org", + "mod", "3"), new GregorianCalendar(2005, 1, 18).getTime()), + MockResolver.buildMockResolver("7", false, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "latest.integration"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("5", rmr.getResolver().getName()); + List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); + for (int i = 0; i < resolvers.length; i++) { + assertEquals(ddAsList, resolvers[i].askedDeps); + } + } + + public void testFixedWithDefault() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setLatestStrategy(new LatestRevisionStrategy()); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", false, null), + MockResolver.buildMockResolver("2", true, ModuleRevisionId.newInstance("org", + "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime(), true), // default + MockResolver.buildMockResolver("3", false, null), + MockResolver.buildMockResolver("4", true, ModuleRevisionId.newInstance("org", + "mod", "4"), new GregorianCalendar(2005, 1, 22).getTime()), // not default + // -> should the + // one kept + MockResolver.buildMockResolver("5", false, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "4"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("4", rmr.getResolver().getName()); + List ddAsList = Arrays.asList(new DependencyDescriptor[] {dd}); + for (int i = 0; i < 4; i++) { + assertEquals("invalid asked dependencies for " + resolvers[i], ddAsList, + resolvers[i].askedDeps); + } + for (int i = 4; i < resolvers.length; i++) { + assertTrue("invalid asked dependencies for " + resolvers[i], resolvers[i].askedDeps + .isEmpty()); + } + } + + public void testFixedWithDefaultAndRealResolver() throws Exception { + // test case for IVY-206 + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + + // no ivy pattern for first resolver: will only find a 'default' module + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("1"); + resolver.setSettings(_settings); + + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + chain.add(resolver); + + // second resolver has an ivy pattern and will thus find the real module, which should be + // kept + resolver = new FileSystemResolver(); + resolver.setName("2"); + resolver.setSettings(_settings); + + resolver + .addIvyPattern("test/repositories/1/[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + chain.add(resolver); + + _settings.addResolver(chain); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org1", "mod1.1", "1.0"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("2", rmr.getResolver().getName()); + } + + public void testReturnFirst() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setReturnFirst(true); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", true, new GregorianCalendar(2005, 1, 20) + .getTime()), + MockResolver.buildMockResolver("2", false, null), + MockResolver.buildMockResolver("3", true, new GregorianCalendar(2005, 1, 25) + .getTime()), // younger -> should the one kept + MockResolver.buildMockResolver("4", false, null), + MockResolver.buildMockResolver("5", true, new GregorianCalendar(2005, 1, 22) + .getTime()), + MockResolver.buildMockResolver("6", true, new GregorianCalendar(2005, 1, 18) + .getTime()), MockResolver.buildMockResolver("7", false, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "latest.integration"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("1", rmr.getResolver().getName()); + for (int i = 1; i < resolvers.length; i++) { + assertTrue(resolvers[i].askedDeps.isEmpty()); + } + } + + public void testReturnFirstWithDefaultAndCacheAndRealResolver() throws Exception { + // test case for IVY-207 + + // 1 ---- we first do a first resolve which puts a default file in cache + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + + // no ivy pattern for resolver: will only find a 'default' module + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("old"); + resolver.setSettings(_settings); + + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + chain.add(resolver); + + _settings.addResolver(chain); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org1", "mod1.1", "1.0"), false); + chain.getDependency(dd, _data); + + // 2 ---- now we ask to resolve dependencies with a chain in return first mode, in which the + // first resolver + // is not able to find the module, but the second is + + chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setReturnFirst(true); + + // no pattern for first resolver: will not find the module + resolver = new FileSystemResolver(); + resolver.setName("1"); + resolver.setSettings(_settings); + + chain.add(resolver); + + // second resolver will find the real module, which should be kept + resolver = new FileSystemResolver(); + resolver.setName("2"); + resolver.setSettings(_settings); + + resolver + .addIvyPattern("test/repositories/1/[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + chain.add(resolver); + + _settings.addResolver(chain); + + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("2", rmr.getResolver().getName()); + } + + public void testDual() throws Exception { + ChainResolver chain = new ChainResolver(); + chain.setName("chain"); + chain.setSettings(_settings); + chain.setDual(true); + MockResolver[] resolvers = new MockResolver[] { + MockResolver.buildMockResolver("1", false, null), + MockResolver.buildMockResolver("2", true, null), + MockResolver.buildMockResolver("3", true, null)}; + for (int i = 0; i < resolvers.length; i++) { + chain.add(resolvers[i]); + } + assertResolversSizeAndNames(chain, resolvers.length); + + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "rev"), false); + ResolvedModuleRevision rmr = chain.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals("2", rmr.getResolver().getName()); + assertEquals("chain", rmr.getArtifactResolver().getName()); + } + +} diff --git a/test/java/org/apache/ivy/plugins/resolver/DualResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/DualResolverTest.java index f54e0d97..b2b2410a 100644 --- a/test/java/org/apache/ivy/plugins/resolver/DualResolverTest.java +++ b/test/java/org/apache/ivy/plugins/resolver/DualResolverTest.java @@ -1,157 +1,157 @@ -/* - * 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.util.Arrays; -import java.util.GregorianCalendar; - -import junit.framework.TestCase; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -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.settings.XmlSettingsParser; -import org.apache.ivy.core.sort.SortEngine; - -/** - * Test for DualResolver - */ -public class DualResolverTest extends TestCase { - private IvySettings _settings; - - private ResolveEngine _engine; - - private ResolveData _data; - - private File _cache; - - 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().setCache(CacheManager.getInstance( - _settings, _cache))); - _cache.mkdirs(); - _settings.setDefaultCache(_cache); - } - - public void testFromConf() throws Exception { - new XmlSettingsParser(_settings).parse(DualResolverTest.class - .getResource("dualresolverconf.xml")); - - DependencyResolver resolver = _settings.getResolver("dualok"); - assertNotNull(resolver); - assertTrue(resolver instanceof DualResolver); - DualResolver dual = (DualResolver) resolver; - assertNotNull(dual.getIvyResolver()); - assertEquals("ivy", dual.getIvyResolver().getName()); - assertNotNull(dual.getArtifactResolver()); - assertEquals("artifact", dual.getArtifactResolver().getName()); - - resolver = _settings.getResolver("dualnotenough"); - assertNotNull(resolver); - assertTrue(resolver instanceof DualResolver); - dual = (DualResolver) resolver; - assertNotNull(dual.getIvyResolver()); - assertNull(dual.getArtifactResolver()); - } - - public void testFromBadConf() throws Exception { - try { - new XmlSettingsParser(_settings).parse(DualResolverTest.class - .getResource("dualresolverconf-bad.xml")); - fail("bad dual resolver configuration should raise exception"); - } catch (Exception ex) { - // ok -> bad conf has raised an exception - } - } - - public void testBad() throws Exception { - DualResolver dual = new DualResolver(); - dual.setIvyResolver(new IBiblioResolver()); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "rev"), false); - try { - dual.getDependency(dd, _data); - fail("bad dual resolver configuration should raise exception"); - } catch (Exception ex) { - // ok -> should have raised an exception - } - } - - public void testResolve() throws Exception { - DualResolver dual = new DualResolver(); - MockResolver ivyResolver = MockResolver.buildMockResolver("ivy", true, - new GregorianCalendar(2005, 1, 20).getTime()); - MockResolver artifactResolver = MockResolver.buildMockResolver("artifact", false, - new GregorianCalendar(2005, 1, 20).getTime()); - dual.setIvyResolver(ivyResolver); - dual.setArtifactResolver(artifactResolver); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "rev"), false); - ResolvedModuleRevision rmr = dual.getDependency(dd, _data); - - assertNotNull(rmr); - assertEquals(dual, rmr.getArtifactResolver()); - assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), ivyResolver.askedDeps); - assertTrue(artifactResolver.askedDeps.isEmpty()); - } - - public void testResolveFromArtifact() throws Exception { - DualResolver dual = new DualResolver(); - MockResolver ivyResolver = MockResolver.buildMockResolver("ivy", false, - new GregorianCalendar(2005, 1, 20).getTime()); - MockResolver artifactResolver = MockResolver.buildMockResolver("artifact", true, - new GregorianCalendar(2005, 1, 20).getTime()); - dual.setIvyResolver(ivyResolver); - dual.setArtifactResolver(artifactResolver); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "rev"), false); - ResolvedModuleRevision rmr = dual.getDependency(dd, _data); - - assertNotNull(rmr); - assertEquals(artifactResolver, rmr.getResolver()); - assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), ivyResolver.askedDeps); - assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), artifactResolver.askedDeps); - } - - public void testResolveFail() throws Exception { - DualResolver dual = new DualResolver(); - MockResolver ivyResolver = MockResolver.buildMockResolver("ivy", false, - new GregorianCalendar(2005, 1, 20).getTime()); - MockResolver artifactResolver = MockResolver.buildMockResolver("artifact", false, - new GregorianCalendar(2005, 1, 20).getTime()); - dual.setIvyResolver(ivyResolver); - dual.setArtifactResolver(artifactResolver); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("org", "mod", "rev"), false); - ResolvedModuleRevision rmr = dual.getDependency(dd, _data); - - assertNull(rmr); - assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), ivyResolver.askedDeps); - assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), artifactResolver.askedDeps); - } -} +/* + * 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.util.Arrays; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +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.settings.XmlSettingsParser; +import org.apache.ivy.core.sort.SortEngine; + +/** + * Test for DualResolver + */ +public class DualResolverTest extends TestCase { + private IvySettings _settings; + + private ResolveEngine _engine; + + private ResolveData _data; + + private File _cache; + + 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().setCache(CacheManager.getInstance( + _settings, _cache))); + _cache.mkdirs(); + _settings.setDefaultCache(_cache); + } + + public void testFromConf() throws Exception { + new XmlSettingsParser(_settings).parse(DualResolverTest.class + .getResource("dualresolverconf.xml")); + + DependencyResolver resolver = _settings.getResolver("dualok"); + assertNotNull(resolver); + assertTrue(resolver instanceof DualResolver); + DualResolver dual = (DualResolver) resolver; + assertNotNull(dual.getIvyResolver()); + assertEquals("ivy", dual.getIvyResolver().getName()); + assertNotNull(dual.getArtifactResolver()); + assertEquals("artifact", dual.getArtifactResolver().getName()); + + resolver = _settings.getResolver("dualnotenough"); + assertNotNull(resolver); + assertTrue(resolver instanceof DualResolver); + dual = (DualResolver) resolver; + assertNotNull(dual.getIvyResolver()); + assertNull(dual.getArtifactResolver()); + } + + public void testFromBadConf() throws Exception { + try { + new XmlSettingsParser(_settings).parse(DualResolverTest.class + .getResource("dualresolverconf-bad.xml")); + fail("bad dual resolver configuration should raise exception"); + } catch (Exception ex) { + // ok -> bad conf has raised an exception + } + } + + public void testBad() throws Exception { + DualResolver dual = new DualResolver(); + dual.setIvyResolver(new IBiblioResolver()); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "rev"), false); + try { + dual.getDependency(dd, _data); + fail("bad dual resolver configuration should raise exception"); + } catch (Exception ex) { + // ok -> should have raised an exception + } + } + + public void testResolve() throws Exception { + DualResolver dual = new DualResolver(); + MockResolver ivyResolver = MockResolver.buildMockResolver("ivy", true, + new GregorianCalendar(2005, 1, 20).getTime()); + MockResolver artifactResolver = MockResolver.buildMockResolver("artifact", false, + new GregorianCalendar(2005, 1, 20).getTime()); + dual.setIvyResolver(ivyResolver); + dual.setArtifactResolver(artifactResolver); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "rev"), false); + ResolvedModuleRevision rmr = dual.getDependency(dd, _data); + + assertNotNull(rmr); + assertEquals(dual, rmr.getArtifactResolver()); + assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), ivyResolver.askedDeps); + assertTrue(artifactResolver.askedDeps.isEmpty()); + } + + public void testResolveFromArtifact() throws Exception { + DualResolver dual = new DualResolver(); + MockResolver ivyResolver = MockResolver.buildMockResolver("ivy", false, + new GregorianCalendar(2005, 1, 20).getTime()); + MockResolver artifactResolver = MockResolver.buildMockResolver("artifact", true, + new GregorianCalendar(2005, 1, 20).getTime()); + dual.setIvyResolver(ivyResolver); + dual.setArtifactResolver(artifactResolver); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "rev"), false); + ResolvedModuleRevision rmr = dual.getDependency(dd, _data); + + assertNotNull(rmr); + assertEquals(artifactResolver, rmr.getResolver()); + assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), ivyResolver.askedDeps); + assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), artifactResolver.askedDeps); + } + + public void testResolveFail() throws Exception { + DualResolver dual = new DualResolver(); + MockResolver ivyResolver = MockResolver.buildMockResolver("ivy", false, + new GregorianCalendar(2005, 1, 20).getTime()); + MockResolver artifactResolver = MockResolver.buildMockResolver("artifact", false, + new GregorianCalendar(2005, 1, 20).getTime()); + dual.setIvyResolver(ivyResolver); + dual.setArtifactResolver(artifactResolver); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("org", "mod", "rev"), false); + ResolvedModuleRevision rmr = dual.getDependency(dd, _data); + + assertNull(rmr); + assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), ivyResolver.askedDeps); + assertEquals(Arrays.asList(new DependencyDescriptor[] {dd}), artifactResolver.askedDeps); + } +} diff --git a/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java index 145acf89..ac8e0fa8 100644 --- a/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java +++ b/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java @@ -1,631 +1,631 @@ -/* - * 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.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.Date; -import java.util.GregorianCalendar; - -import junit.framework.TestCase; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DownloadOptions; -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.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.core.sort.SortEngine; -import org.apache.ivy.plugins.latest.LatestRevisionStrategy; -import org.apache.ivy.plugins.latest.LatestTimeStrategy; -import org.apache.ivy.util.FileUtil; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -/** - * - */ -public class FileSystemResolverTest extends TestCase { - - private static final String FS = System.getProperty("file.separator"); - - private static final String IVY_PATTERN = "test" + FS + "repositories" + FS + "1" + FS - + "[organisation]" + FS + "[module]" + FS + "ivys" + FS + "ivy-[revision].xml"; - - private IvySettings _settings; - - private ResolveEngine _engine; - - private ResolveData _data; - - private File _cache; - - private CacheManager _cacheManager; - - public FileSystemResolverTest() { - setupLastModified(); - } - - 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().setCache(CacheManager.getInstance( - _settings, _cache))); - _cache.mkdirs(); - _cacheManager = new CacheManager(_settings, _cache); - _settings.setDefaultCache(_cache); - } - - private void setupLastModified() { - // change important last modified dates cause svn doesn't keep them - long minute = 60 * 1000; - long time = new GregorianCalendar().getTimeInMillis() - (4 * minute); - new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").setLastModified(time); - time += minute; - new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.1.xml").setLastModified(time); - time += minute; - new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.1.xml").setLastModified(time); - time += minute; - new File("test/repositories/1/org1/mod1.1/ivys/ivy-2.0.xml").setLastModified(time); - } - - protected void tearDown() throws Exception { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - public void testFixedRevision() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(IVY_PATTERN); - resolver - .addArtifactPattern("test/repositories/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); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - - // test to ask to download - DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {artifact}, - getDownloadOptions(false)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - report = resolver.download(new Artifact[] {artifact}, getDownloadOptions(false)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } - - private DownloadOptions getDownloadOptions(boolean useOrigin) { - return new DownloadOptions(_settings, _cacheManager, null, useOrigin); - } - - public void testMaven2() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - resolver.setM2compatible(true); - assertEquals("test", resolver.getName()); - - resolver - .addIvyPattern("test/repositories/m2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"); - resolver - .addArtifactPattern("test/repositories/m2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - - mrid = ModuleRevisionId.newInstance("org.apache.unknown", "test", "1.0"); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNull(rmr); - resolver.reportFailure(); - } - - public void testChecksum() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - - resolver.addIvyPattern("test/repositories/checksums/[module]/[artifact]-[revision].[ext]"); - resolver - .addArtifactPattern("test/repositories/checksums/[module]/[artifact]-[revision].[ext]"); - - resolver.setChecksums("sha1, md5"); - ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), - getDownloadOptions(false)); - assertEquals(2, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length); - - resolver.setChecksums("md5"); - mrid = ModuleRevisionId.newInstance("test", "badivycs", "1.0"); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNull(rmr); - resolver.setChecksums("none"); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNotNull(rmr); - dr = resolver.download(new Artifact[] {new DefaultArtifact(mrid, rmr.getPublicationDate(), - mrid.getName(), "jar", "jar")}, getDownloadOptions(false)); - assertEquals(1, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length); - - resolver.setChecksums("md5"); - mrid = ModuleRevisionId.newInstance("test", "badartcs", "1.0"); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNotNull(rmr); - dr = resolver.download(new Artifact[] {new DefaultArtifact(mrid, rmr.getPublicationDate(), - mrid.getName(), "jar", "jar")}, getDownloadOptions(false)); - assertEquals(1, dr.getArtifactsReports(DownloadStatus.FAILED).length); - - resolver.setChecksums(""); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNotNull(rmr); - dr = resolver.download(new Artifact[] {new DefaultArtifact(mrid, rmr.getPublicationDate(), - mrid.getName(), "jar", "jar")}, getDownloadOptions(false)); - assertEquals(1, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length); - } - - public void testCheckModified() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - _settings.addResolver(resolver); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern("test" + FS + "repositories" + FS + "checkmodified" + FS - + "ivy-[revision].xml"); - File modify = new File("test/repositories/checkmodified/ivy-1.0.xml"); - FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-before.xml"), modify, null, - true); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - modify.setLastModified(pubdate.getTime()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - assertEquals(pubdate, rmr.getPublicationDate()); - - // updates ivy file in repository - FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-after.xml"), modify, null, - true); - pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime(); - modify.setLastModified(pubdate.getTime()); - - // should not get the new version - resolver.setCheckmodified(false); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(), rmr - .getPublicationDate()); - - // should now get the new version - resolver.setCheckmodified(true); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - assertEquals(pubdate, rmr.getPublicationDate()); - } - - public void testNoRevision() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - _settings.addResolver(resolver); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern("test" + FS + "repositories" + FS + "norevision" + FS - + "ivy-[module].xml"); - resolver.addArtifactPattern("test" + FS + "repositories" + FS + "norevision" + FS - + "[artifact].[ext]"); - File modify = new File("test/repositories/norevision/ivy-mod1.1.xml"); - File artifact = new File("test/repositories/norevision/mod1.1.jar"); - - // 'publish' 'before' version - FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-before.xml"), modify, null, - true); - FileUtil.copy(new File("test/repositories/norevision/mod1.1-before.jar"), artifact, null, - true); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - modify.setLastModified(pubdate.getTime()); - - ModuleRevisionId mrid = ModuleRevisionId - .newInstance("org1", "mod1.1", "latest.integration"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), rmr.getId()); - assertEquals(pubdate, rmr.getPublicationDate()); - - Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default"); - File archiveFileInCache = _cacheManager.getArchiveFileInCache(artifacts[0]); - resolver.download(artifacts, getDownloadOptions(false)); - assertTrue(archiveFileInCache.exists()); - BufferedReader r = new BufferedReader(new FileReader(archiveFileInCache)); - assertEquals("before", r.readLine()); - r.close(); - - // updates ivy file and artifact in repository - FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-after.xml"), modify, null, - true); - FileUtil.copy(new File("test/repositories/norevision/mod1.1-after.jar"), artifact, null, - true); - pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime(); - modify.setLastModified(pubdate.getTime()); - // no need to update new artifact timestamp cause it isn't used - - // should get the new version even if checkModified is false, beacause we ask a - // latest.integration - resolver.setCheckmodified(false); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNotNull(rmr); - - assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"), rmr.getId()); - assertEquals(pubdate, rmr.getPublicationDate()); - - artifacts = rmr.getDescriptor().getArtifacts("default"); - archiveFileInCache = _cacheManager.getArchiveFileInCache(artifacts[0]); - - assertFalse(archiveFileInCache.exists()); - - // should download the new artifact - artifacts = rmr.getDescriptor().getArtifacts("default"); - resolver.download(artifacts, getDownloadOptions(false)); - assertTrue(archiveFileInCache.exists()); - r = new BufferedReader(new FileReader(archiveFileInCache)); - assertEquals("after", r.readLine()); - r.close(); - } - - public void testChanging() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - _settings.addResolver(resolver); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern("test" + FS + "repositories" + FS + "checkmodified" + FS - + "ivy-[revision].xml"); - resolver.addArtifactPattern("test" + FS + "repositories" + FS + "checkmodified" + FS - + "[artifact]-[revision].[ext]"); - File modify = new File("test/repositories/checkmodified/ivy-1.0.xml"); - File artifact = new File("test/repositories/checkmodified/mod1.1-1.0.jar"); - - // 'publish' 'before' version - FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-before.xml"), modify, null, - true); - FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-before.jar"), artifact, - null, true); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - modify.setLastModified(pubdate.getTime()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - assertEquals(pubdate, rmr.getPublicationDate()); - - Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default"); - resolver.download(artifacts, getDownloadOptions(false)); - File archiveFileInCache = _cacheManager.getArchiveFileInCache(artifacts[0]); - assertTrue(archiveFileInCache.exists()); - BufferedReader r = new BufferedReader(new FileReader(archiveFileInCache)); - assertEquals("before", r.readLine()); - r.close(); - - // updates ivy file and artifact in repository - FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-after.xml"), modify, null, - true); - FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-after.jar"), artifact, - null, true); - pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime(); - modify.setLastModified(pubdate.getTime()); - // no need to update new artifact timestamp cause it isn't used - - // should not get the new version: checkmodified is false and edpendency is not told to be a - // changing one - resolver.setCheckmodified(false); - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(), rmr - .getPublicationDate()); - - assertTrue(archiveFileInCache.exists()); - r = new BufferedReader(new FileReader(archiveFileInCache)); - assertEquals("before", r.readLine()); - r.close(); - - // should now get the new version cause we say it's a changing one - rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false, true), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - assertEquals(pubdate, rmr.getPublicationDate()); - - assertFalse(archiveFileInCache.exists()); - - artifacts = rmr.getDescriptor().getArtifacts("default"); - resolver.download(artifacts, getDownloadOptions(false)); - assertTrue(archiveFileInCache.exists()); - r = new BufferedReader(new FileReader(archiveFileInCache)); - assertEquals("after", r.readLine()); - r.close(); - } - - public void testLatestTime() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(IVY_PATTERN); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - - resolver.setLatestStrategy(new LatestTimeStrategy()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); - ResolvedModuleRevision rmr = resolver - .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", - "mod1.1", "latest.integration"), false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - } - - public void testLatestRevision() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(IVY_PATTERN); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - - resolver.setLatestStrategy(new LatestRevisionStrategy()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); - ResolvedModuleRevision rmr = resolver - .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", - "mod1.1", "latest.integration"), false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - } - - public void testRelativePath() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(new File("src/java").getAbsolutePath() + "/../../" + IVY_PATTERN); - resolver - .addArtifactPattern("src/../test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - - resolver.setLatestStrategy(new LatestRevisionStrategy()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); - ResolvedModuleRevision rmr = resolver - .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", - "mod1.1", "latest.integration"), false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - } - - public void testFormattedLatestTime() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(IVY_PATTERN); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - - resolver.setLatestStrategy(new LatestTimeStrategy()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor( - ModuleRevisionId.newInstance("org1", "mod1.1", "1+"), false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - } - - public void testFormattedLatestRevision() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(IVY_PATTERN); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - - resolver.setLatestStrategy(new LatestRevisionStrategy()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor( - ModuleRevisionId.newInstance("org1", "mod1.1", "1+"), false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - } - - public void testPublish() throws Exception { - try { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern("test" + FS + "repositories" + FS + "1" + FS + "[organisation]" - + FS + "[module]" + FS + "[revision]" + FS + "[artifact].[ext]"); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision"); - Artifact ivyArtifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml"); - Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype", - "myext"); - File src = new File("test/repositories/ivysettings.xml"); - resolver.publish(ivyArtifact, src, false); - resolver.publish(artifact, src, false); - - assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists()); - assertTrue(new File( - "test/repositories/1/myorg/mymodule/mytypes/myartifact-myrevision.myext") - .exists()); - } finally { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("test/repositories/1/myorg")); - del.execute(); - } - } - - public void testListing() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(IVY_PATTERN); - resolver - .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"); - - OrganisationEntry[] orgs = resolver.listOrganisations(); - ResolverTestHelper.assertOrganisationEntries(resolver, new String[] {"org1", "org2", - "org6", "org9", "orgfailure", "yourorg"}, orgs); - - OrganisationEntry org = ResolverTestHelper.getEntry(orgs, "org1"); - ModuleEntry[] mods = resolver.listModules(org); - ResolverTestHelper.assertModuleEntries(resolver, org, new String[] {"mod1.1", "mod1.2", - "mod1.3", "mod1.4", "mod1.5", "mod1.6"}, mods); - - ModuleEntry mod = ResolverTestHelper.getEntry(mods, "mod1.1"); - RevisionEntry[] revs = resolver.listRevisions(mod); - ResolverTestHelper.assertRevisionEntries(resolver, mod, new String[] {"1.0", "1.0.1", - "1.1", "2.0"}, revs); - - mod = ResolverTestHelper.getEntry(mods, "mod1.2"); - revs = resolver.listRevisions(mod); - ResolverTestHelper.assertRevisionEntries(resolver, mod, new String[] {"1.0", "1.1", "2.0", - "2.1", "2.2"}, revs); - } - - public void testDownloadWithUseOriginIsTrue() throws Exception { - FileSystemResolver resolver = new FileSystemResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - resolver.addIvyPattern(IVY_PATTERN); - resolver - .addArtifactPattern("test/repositories/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); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - - // test to ask to download - DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {artifact}, - getDownloadOptions(true)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } -} +/* + * 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.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.Date; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DownloadOptions; +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.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.core.sort.SortEngine; +import org.apache.ivy.plugins.latest.LatestRevisionStrategy; +import org.apache.ivy.plugins.latest.LatestTimeStrategy; +import org.apache.ivy.util.FileUtil; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +/** + * + */ +public class FileSystemResolverTest extends TestCase { + + private static final String FS = System.getProperty("file.separator"); + + private static final String IVY_PATTERN = "test" + FS + "repositories" + FS + "1" + FS + + "[organisation]" + FS + "[module]" + FS + "ivys" + FS + "ivy-[revision].xml"; + + private IvySettings _settings; + + private ResolveEngine _engine; + + private ResolveData _data; + + private File _cache; + + private CacheManager _cacheManager; + + public FileSystemResolverTest() { + setupLastModified(); + } + + 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().setCache(CacheManager.getInstance( + _settings, _cache))); + _cache.mkdirs(); + _cacheManager = new CacheManager(_settings, _cache); + _settings.setDefaultCache(_cache); + } + + private void setupLastModified() { + // change important last modified dates cause svn doesn't keep them + long minute = 60 * 1000; + long time = new GregorianCalendar().getTimeInMillis() - (4 * minute); + new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").setLastModified(time); + time += minute; + new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.1.xml").setLastModified(time); + time += minute; + new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.1.xml").setLastModified(time); + time += minute; + new File("test/repositories/1/org1/mod1.1/ivys/ivy-2.0.xml").setLastModified(time); + } + + protected void tearDown() throws Exception { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + public void testFixedRevision() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(IVY_PATTERN); + resolver + .addArtifactPattern("test/repositories/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); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + + // test to ask to download + DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {artifact}, + getDownloadOptions(false)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + report = resolver.download(new Artifact[] {artifact}, getDownloadOptions(false)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } + + private DownloadOptions getDownloadOptions(boolean useOrigin) { + return new DownloadOptions(_settings, _cacheManager, null, useOrigin); + } + + public void testMaven2() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + resolver.setM2compatible(true); + assertEquals("test", resolver.getName()); + + resolver + .addIvyPattern("test/repositories/m2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"); + resolver + .addArtifactPattern("test/repositories/m2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + + mrid = ModuleRevisionId.newInstance("org.apache.unknown", "test", "1.0"); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNull(rmr); + resolver.reportFailure(); + } + + public void testChecksum() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + + resolver.addIvyPattern("test/repositories/checksums/[module]/[artifact]-[revision].[ext]"); + resolver + .addArtifactPattern("test/repositories/checksums/[module]/[artifact]-[revision].[ext]"); + + resolver.setChecksums("sha1, md5"); + ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), + getDownloadOptions(false)); + assertEquals(2, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length); + + resolver.setChecksums("md5"); + mrid = ModuleRevisionId.newInstance("test", "badivycs", "1.0"); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNull(rmr); + resolver.setChecksums("none"); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNotNull(rmr); + dr = resolver.download(new Artifact[] {new DefaultArtifact(mrid, rmr.getPublicationDate(), + mrid.getName(), "jar", "jar")}, getDownloadOptions(false)); + assertEquals(1, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length); + + resolver.setChecksums("md5"); + mrid = ModuleRevisionId.newInstance("test", "badartcs", "1.0"); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNotNull(rmr); + dr = resolver.download(new Artifact[] {new DefaultArtifact(mrid, rmr.getPublicationDate(), + mrid.getName(), "jar", "jar")}, getDownloadOptions(false)); + assertEquals(1, dr.getArtifactsReports(DownloadStatus.FAILED).length); + + resolver.setChecksums(""); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNotNull(rmr); + dr = resolver.download(new Artifact[] {new DefaultArtifact(mrid, rmr.getPublicationDate(), + mrid.getName(), "jar", "jar")}, getDownloadOptions(false)); + assertEquals(1, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length); + } + + public void testCheckModified() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + _settings.addResolver(resolver); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern("test" + FS + "repositories" + FS + "checkmodified" + FS + + "ivy-[revision].xml"); + File modify = new File("test/repositories/checkmodified/ivy-1.0.xml"); + FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-before.xml"), modify, null, + true); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + modify.setLastModified(pubdate.getTime()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + assertEquals(pubdate, rmr.getPublicationDate()); + + // updates ivy file in repository + FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-after.xml"), modify, null, + true); + pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime(); + modify.setLastModified(pubdate.getTime()); + + // should not get the new version + resolver.setCheckmodified(false); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(), rmr + .getPublicationDate()); + + // should now get the new version + resolver.setCheckmodified(true); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + assertEquals(pubdate, rmr.getPublicationDate()); + } + + public void testNoRevision() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + _settings.addResolver(resolver); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern("test" + FS + "repositories" + FS + "norevision" + FS + + "ivy-[module].xml"); + resolver.addArtifactPattern("test" + FS + "repositories" + FS + "norevision" + FS + + "[artifact].[ext]"); + File modify = new File("test/repositories/norevision/ivy-mod1.1.xml"); + File artifact = new File("test/repositories/norevision/mod1.1.jar"); + + // 'publish' 'before' version + FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-before.xml"), modify, null, + true); + FileUtil.copy(new File("test/repositories/norevision/mod1.1-before.jar"), artifact, null, + true); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + modify.setLastModified(pubdate.getTime()); + + ModuleRevisionId mrid = ModuleRevisionId + .newInstance("org1", "mod1.1", "latest.integration"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), rmr.getId()); + assertEquals(pubdate, rmr.getPublicationDate()); + + Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default"); + File archiveFileInCache = _cacheManager.getArchiveFileInCache(artifacts[0]); + resolver.download(artifacts, getDownloadOptions(false)); + assertTrue(archiveFileInCache.exists()); + BufferedReader r = new BufferedReader(new FileReader(archiveFileInCache)); + assertEquals("before", r.readLine()); + r.close(); + + // updates ivy file and artifact in repository + FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-after.xml"), modify, null, + true); + FileUtil.copy(new File("test/repositories/norevision/mod1.1-after.jar"), artifact, null, + true); + pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime(); + modify.setLastModified(pubdate.getTime()); + // no need to update new artifact timestamp cause it isn't used + + // should get the new version even if checkModified is false, beacause we ask a + // latest.integration + resolver.setCheckmodified(false); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNotNull(rmr); + + assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"), rmr.getId()); + assertEquals(pubdate, rmr.getPublicationDate()); + + artifacts = rmr.getDescriptor().getArtifacts("default"); + archiveFileInCache = _cacheManager.getArchiveFileInCache(artifacts[0]); + + assertFalse(archiveFileInCache.exists()); + + // should download the new artifact + artifacts = rmr.getDescriptor().getArtifacts("default"); + resolver.download(artifacts, getDownloadOptions(false)); + assertTrue(archiveFileInCache.exists()); + r = new BufferedReader(new FileReader(archiveFileInCache)); + assertEquals("after", r.readLine()); + r.close(); + } + + public void testChanging() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + _settings.addResolver(resolver); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern("test" + FS + "repositories" + FS + "checkmodified" + FS + + "ivy-[revision].xml"); + resolver.addArtifactPattern("test" + FS + "repositories" + FS + "checkmodified" + FS + + "[artifact]-[revision].[ext]"); + File modify = new File("test/repositories/checkmodified/ivy-1.0.xml"); + File artifact = new File("test/repositories/checkmodified/mod1.1-1.0.jar"); + + // 'publish' 'before' version + FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-before.xml"), modify, null, + true); + FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-before.jar"), artifact, + null, true); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + modify.setLastModified(pubdate.getTime()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + assertEquals(pubdate, rmr.getPublicationDate()); + + Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default"); + resolver.download(artifacts, getDownloadOptions(false)); + File archiveFileInCache = _cacheManager.getArchiveFileInCache(artifacts[0]); + assertTrue(archiveFileInCache.exists()); + BufferedReader r = new BufferedReader(new FileReader(archiveFileInCache)); + assertEquals("before", r.readLine()); + r.close(); + + // updates ivy file and artifact in repository + FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-after.xml"), modify, null, + true); + FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-after.jar"), artifact, + null, true); + pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime(); + modify.setLastModified(pubdate.getTime()); + // no need to update new artifact timestamp cause it isn't used + + // should not get the new version: checkmodified is false and edpendency is not told to be a + // changing one + resolver.setCheckmodified(false); + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(), rmr + .getPublicationDate()); + + assertTrue(archiveFileInCache.exists()); + r = new BufferedReader(new FileReader(archiveFileInCache)); + assertEquals("before", r.readLine()); + r.close(); + + // should now get the new version cause we say it's a changing one + rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false, true), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + assertEquals(pubdate, rmr.getPublicationDate()); + + assertFalse(archiveFileInCache.exists()); + + artifacts = rmr.getDescriptor().getArtifacts("default"); + resolver.download(artifacts, getDownloadOptions(false)); + assertTrue(archiveFileInCache.exists()); + r = new BufferedReader(new FileReader(archiveFileInCache)); + assertEquals("after", r.readLine()); + r.close(); + } + + public void testLatestTime() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(IVY_PATTERN); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + + resolver.setLatestStrategy(new LatestTimeStrategy()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); + ResolvedModuleRevision rmr = resolver + .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", + "mod1.1", "latest.integration"), false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + } + + public void testLatestRevision() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(IVY_PATTERN); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + + resolver.setLatestStrategy(new LatestRevisionStrategy()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); + ResolvedModuleRevision rmr = resolver + .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", + "mod1.1", "latest.integration"), false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + } + + public void testRelativePath() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(new File("src/java").getAbsolutePath() + "/../../" + IVY_PATTERN); + resolver + .addArtifactPattern("src/../test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + + resolver.setLatestStrategy(new LatestRevisionStrategy()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); + ResolvedModuleRevision rmr = resolver + .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", + "mod1.1", "latest.integration"), false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + } + + public void testFormattedLatestTime() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(IVY_PATTERN); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + + resolver.setLatestStrategy(new LatestTimeStrategy()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor( + ModuleRevisionId.newInstance("org1", "mod1.1", "1+"), false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + } + + public void testFormattedLatestRevision() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(IVY_PATTERN); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + + resolver.setLatestStrategy(new LatestRevisionStrategy()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor( + ModuleRevisionId.newInstance("org1", "mod1.1", "1+"), false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + } + + public void testPublish() throws Exception { + try { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern("test" + FS + "repositories" + FS + "1" + FS + "[organisation]" + + FS + "[module]" + FS + "[revision]" + FS + "[artifact].[ext]"); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision"); + Artifact ivyArtifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml"); + Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype", + "myext"); + File src = new File("test/repositories/ivysettings.xml"); + resolver.publish(ivyArtifact, src, false); + resolver.publish(artifact, src, false); + + assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists()); + assertTrue(new File( + "test/repositories/1/myorg/mymodule/mytypes/myartifact-myrevision.myext") + .exists()); + } finally { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(new File("test/repositories/1/myorg")); + del.execute(); + } + } + + public void testListing() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(IVY_PATTERN); + resolver + .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"); + + OrganisationEntry[] orgs = resolver.listOrganisations(); + ResolverTestHelper.assertOrganisationEntries(resolver, new String[] {"org1", "org2", + "org6", "org9", "orgfailure", "yourorg"}, orgs); + + OrganisationEntry org = ResolverTestHelper.getEntry(orgs, "org1"); + ModuleEntry[] mods = resolver.listModules(org); + ResolverTestHelper.assertModuleEntries(resolver, org, new String[] {"mod1.1", "mod1.2", + "mod1.3", "mod1.4", "mod1.5", "mod1.6"}, mods); + + ModuleEntry mod = ResolverTestHelper.getEntry(mods, "mod1.1"); + RevisionEntry[] revs = resolver.listRevisions(mod); + ResolverTestHelper.assertRevisionEntries(resolver, mod, new String[] {"1.0", "1.0.1", + "1.1", "2.0"}, revs); + + mod = ResolverTestHelper.getEntry(mods, "mod1.2"); + revs = resolver.listRevisions(mod); + ResolverTestHelper.assertRevisionEntries(resolver, mod, new String[] {"1.0", "1.1", "2.0", + "2.1", "2.2"}, revs); + } + + public void testDownloadWithUseOriginIsTrue() throws Exception { + FileSystemResolver resolver = new FileSystemResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + resolver.addIvyPattern(IVY_PATTERN); + resolver + .addArtifactPattern("test/repositories/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); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + + // test to ask to download + DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {artifact}, + getDownloadOptions(true)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } +} diff --git a/test/java/org/apache/ivy/plugins/resolver/IBiblioHelper.java b/test/java/org/apache/ivy/plugins/resolver/IBiblioHelper.java index d36fd632..f0784076 100644 --- a/test/java/org/apache/ivy/plugins/resolver/IBiblioHelper.java +++ b/test/java/org/apache/ivy/plugins/resolver/IBiblioHelper.java @@ -1,74 +1,74 @@ -/* - * 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.net.URL; - -import org.apache.ivy.util.url.URLHandler; -import org.apache.ivy.util.url.URLHandlerRegistry; - -/** - * TODO write javadoc - */ -public class IBiblioHelper { - private static boolean _checked = false; - - private static String _mirror = null; - - private static URLHandler handler = URLHandlerRegistry.getHttp(); - - public static String getIBiblioMirror() throws Exception { - if (!_checked) { - String[] mirrors = new String[] {"http://repo1.maven.org/maven/REPOSITORY-V1.txt", - "http://mirrors.sunsite.dk/maven", "http://public.planetmirror.com/pub/maven", - "http://www.ibiblio.org/maven"}; - String[] mirrorsRoot = new String[] {"http://repo1.maven.org/maven", - "http://mirrors.sunsite.dk/maven", "http://public.planetmirror.com/pub/maven", - "http://www.ibiblio.org/maven"}; - - long best = -1; - for (int i = 0; i < mirrors.length; i++) { - long start = System.currentTimeMillis(); - if (handler.isReachable(new URL(mirrors[i]), 300)) { - long took = System.currentTimeMillis() - start; - System.out.println("reached " + mirrors[i] + " in " + took + "ms"); - if (best == -1 || took < best) { - best = took; - _mirror = mirrorsRoot[i]; - if (took < 400) { - // this mirror is good enough - break; - } - } - } - } - if (_mirror == null) { - System.out.println("No ibiblio mirror available: no ibiblio test done"); - } - } - return _mirror; - } - - public static void main(String[] args) throws Exception { - long start = System.currentTimeMillis(); - String biblioMirror = getIBiblioMirror(); - System.out.println("best mirror is " + biblioMirror + " - found in " - + (System.currentTimeMillis() - start) + "ms"); - } - -} +/* + * 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.net.URL; + +import org.apache.ivy.util.url.URLHandler; +import org.apache.ivy.util.url.URLHandlerRegistry; + +/** + * TODO write javadoc + */ +public class IBiblioHelper { + private static boolean _checked = false; + + private static String _mirror = null; + + private static URLHandler handler = URLHandlerRegistry.getHttp(); + + public static String getIBiblioMirror() throws Exception { + if (!_checked) { + String[] mirrors = new String[] {"http://repo1.maven.org/maven/REPOSITORY-V1.txt", + "http://mirrors.sunsite.dk/maven", "http://public.planetmirror.com/pub/maven", + "http://www.ibiblio.org/maven"}; + String[] mirrorsRoot = new String[] {"http://repo1.maven.org/maven", + "http://mirrors.sunsite.dk/maven", "http://public.planetmirror.com/pub/maven", + "http://www.ibiblio.org/maven"}; + + long best = -1; + for (int i = 0; i < mirrors.length; i++) { + long start = System.currentTimeMillis(); + if (handler.isReachable(new URL(mirrors[i]), 300)) { + long took = System.currentTimeMillis() - start; + System.out.println("reached " + mirrors[i] + " in " + took + "ms"); + if (best == -1 || took < best) { + best = took; + _mirror = mirrorsRoot[i]; + if (took < 400) { + // this mirror is good enough + break; + } + } + } + } + if (_mirror == null) { + System.out.println("No ibiblio mirror available: no ibiblio test done"); + } + } + return _mirror; + } + + public static void main(String[] args) throws Exception { + long start = System.currentTimeMillis(); + String biblioMirror = getIBiblioMirror(); + System.out.println("best mirror is " + biblioMirror + " - found in " + + (System.currentTimeMillis() - start) + "ms"); + } + +} diff --git a/test/java/org/apache/ivy/plugins/resolver/IBiblioResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/IBiblioResolverTest.java index 2961596a..296e2fc4 100644 --- a/test/java/org/apache/ivy/plugins/resolver/IBiblioResolverTest.java +++ b/test/java/org/apache/ivy/plugins/resolver/IBiblioResolverTest.java @@ -1,305 +1,305 @@ -/* - * 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.util.List; - -import junit.framework.TestCase; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultIncludeRule; -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DownloadOptions; -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.plugins.matcher.ExactPatternMatcher; -import org.apache.ivy.util.Message; -import org.apache.ivy.util.MockMessageImpl; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -/** - * - */ -public class IBiblioResolverTest extends TestCase { - // remote.test - - private IvySettings _settings; - - private ResolveEngine _engine; - - private ResolveData _data; - - private File _cache; - - 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().setCache(CacheManager.getInstance( - _settings, _cache))); - _cache.mkdirs(); - _settings.setDefaultCache(_cache); - } - - protected void tearDown() throws Exception { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - public void testDefaults() { - IBiblioResolver resolver = new IBiblioResolver(); - _settings.setVariable("ivy.ibiblio.default.artifact.root", - "http://www.ibiblio.org/mymaven/"); - _settings.setVariable("ivy.ibiblio.default.artifact.pattern", - "[module]/jars/[artifact]-[revision].jar"); - resolver.setSettings(_settings); - List l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar", l - .get(0)); - } - - public void testInitFromConf() throws Exception { - _settings.setVariable("ivy.ibiblio.default.artifact.root", "http://www.ibiblio.org/maven/"); - _settings.setVariable("ivy.ibiblio.default.artifact.pattern", - "[module]/jars/[artifact]-[revision].jar"); - _settings.setVariable("my.ibiblio.root", "http://www.ibiblio.org/mymaven/"); - _settings.setVariable("my.ibiblio.pattern", "[module]/[artifact]-[revision].jar"); - _settings.load(IBiblioResolverTest.class.getResource("ibiblioresolverconf.xml")); - IBiblioResolver resolver = (IBiblioResolver) _settings.getResolver("ibiblioA"); - assertNotNull(resolver); - List l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals("http://www.ibiblio.org/mymaven/[module]/[artifact]-[revision].jar", l.get(0)); - - resolver = (IBiblioResolver) _settings.getResolver("ibiblioB"); - assertNotNull(resolver); - l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals( - "http://www.ibiblio.org/mymaven/[organisation]/jars/[artifact]-[revision].jar", l - .get(0)); - - resolver = (IBiblioResolver) _settings.getResolver("ibiblioC"); - assertTrue(resolver.isM2compatible()); - assertNotNull(resolver); - l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals( - "http://repo1.maven.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", - l.get(0)); - - resolver = (IBiblioResolver) _settings.getResolver("ibiblioD"); - assertFalse(resolver.isM2compatible()); - assertNotNull(resolver); - l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals("http://www.ibiblio.org/maven/[module]/jars/[artifact]-[revision].jar", l - .get(0)); - - resolver = (IBiblioResolver) _settings.getResolver("ibiblioE"); - assertTrue(resolver.isM2compatible()); - assertNotNull(resolver); - l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals( - "http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", - l.get(0)); - - resolver = (IBiblioResolver) _settings.getResolver("ibiblioF"); - assertTrue(resolver.isM2compatible()); - assertNotNull(resolver); - l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals( - "http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", - l.get(0)); - } - - public void testIBiblio() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - IBiblioResolver resolver = new IBiblioResolver(); - resolver.setRoot(ibiblioRoot); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-fileupload", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - assertEquals(mrid, rmr.getId()); - - DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), - "commons-fileupload", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( - _settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - report = resolver.download(new Artifact[] {artifact}, - new DownloadOptions(_settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } - - public void testErrorReport() throws Exception { - IBiblioResolver resolver = new IBiblioResolver(); - resolver.setRoot("http://unknown.host.comx/"); - resolver.setName("test"); - resolver.setM2compatible(true); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - MockMessageImpl mockMessageImpl = new MockMessageImpl(); - Message.setImpl(mockMessageImpl); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload", - "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNull(rmr); - - mockMessageImpl - .assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.pom"); - mockMessageImpl - .assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar"); - } - - public void testIBiblioArtifacts() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - IBiblioResolver resolver = new IBiblioResolver(); - resolver.setRoot(ibiblioRoot); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "nanning", "0.9"); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false); - dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), - "nanning-profiler", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); - dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), - "nanning-trace", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); - ResolvedModuleRevision rmr = resolver.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals(mrid, rmr.getId()); - - DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), - "nanning-profiler", "jar", "jar"); - DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), - "nanning-trace", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {profiler, trace}, - new DownloadOptions(_settings, _cache)); - assertNotNull(report); - - assertEquals(2, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(profiler); - assertNotNull(ar); - - assertEquals(profiler, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - ar = report.getArtifactReport(trace); - assertNotNull(ar); - - assertEquals(trace, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - report = resolver.download(new Artifact[] {profiler, trace}, new DownloadOptions(_settings, - _cache)); - assertNotNull(report); - - assertEquals(2, report.getArtifactsReports().length); - - ar = report.getArtifactReport(profiler); - assertNotNull(ar); - - assertEquals(profiler, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - - ar = report.getArtifactReport(trace); - assertNotNull(ar); - - assertEquals(trace, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } - - public void testUnknown() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - IBiblioResolver resolver = new IBiblioResolver(); - resolver.setRoot(ibiblioRoot); - resolver.setName("test"); - resolver.setSettings(_settings); - - assertNull(resolver.getDependency(new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("unknown", "unknown", "1.0"), false), _data)); - } - -} +/* + * 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.util.List; + +import junit.framework.TestCase; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultIncludeRule; +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DownloadOptions; +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.plugins.matcher.ExactPatternMatcher; +import org.apache.ivy.util.Message; +import org.apache.ivy.util.MockMessageImpl; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +/** + * + */ +public class IBiblioResolverTest extends TestCase { + // remote.test + + private IvySettings _settings; + + private ResolveEngine _engine; + + private ResolveData _data; + + private File _cache; + + 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().setCache(CacheManager.getInstance( + _settings, _cache))); + _cache.mkdirs(); + _settings.setDefaultCache(_cache); + } + + protected void tearDown() throws Exception { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + public void testDefaults() { + IBiblioResolver resolver = new IBiblioResolver(); + _settings.setVariable("ivy.ibiblio.default.artifact.root", + "http://www.ibiblio.org/mymaven/"); + _settings.setVariable("ivy.ibiblio.default.artifact.pattern", + "[module]/jars/[artifact]-[revision].jar"); + resolver.setSettings(_settings); + List l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar", l + .get(0)); + } + + public void testInitFromConf() throws Exception { + _settings.setVariable("ivy.ibiblio.default.artifact.root", "http://www.ibiblio.org/maven/"); + _settings.setVariable("ivy.ibiblio.default.artifact.pattern", + "[module]/jars/[artifact]-[revision].jar"); + _settings.setVariable("my.ibiblio.root", "http://www.ibiblio.org/mymaven/"); + _settings.setVariable("my.ibiblio.pattern", "[module]/[artifact]-[revision].jar"); + _settings.load(IBiblioResolverTest.class.getResource("ibiblioresolverconf.xml")); + IBiblioResolver resolver = (IBiblioResolver) _settings.getResolver("ibiblioA"); + assertNotNull(resolver); + List l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals("http://www.ibiblio.org/mymaven/[module]/[artifact]-[revision].jar", l.get(0)); + + resolver = (IBiblioResolver) _settings.getResolver("ibiblioB"); + assertNotNull(resolver); + l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals( + "http://www.ibiblio.org/mymaven/[organisation]/jars/[artifact]-[revision].jar", l + .get(0)); + + resolver = (IBiblioResolver) _settings.getResolver("ibiblioC"); + assertTrue(resolver.isM2compatible()); + assertNotNull(resolver); + l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals( + "http://repo1.maven.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", + l.get(0)); + + resolver = (IBiblioResolver) _settings.getResolver("ibiblioD"); + assertFalse(resolver.isM2compatible()); + assertNotNull(resolver); + l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals("http://www.ibiblio.org/maven/[module]/jars/[artifact]-[revision].jar", l + .get(0)); + + resolver = (IBiblioResolver) _settings.getResolver("ibiblioE"); + assertTrue(resolver.isM2compatible()); + assertNotNull(resolver); + l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals( + "http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", + l.get(0)); + + resolver = (IBiblioResolver) _settings.getResolver("ibiblioF"); + assertTrue(resolver.isM2compatible()); + assertNotNull(resolver); + l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals( + "http://www.ibiblio.org/mymaven/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]", + l.get(0)); + } + + public void testIBiblio() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + IBiblioResolver resolver = new IBiblioResolver(); + resolver.setRoot(ibiblioRoot); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-fileupload", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + assertEquals(mrid, rmr.getId()); + + DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), + "commons-fileupload", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( + _settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + report = resolver.download(new Artifact[] {artifact}, + new DownloadOptions(_settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } + + public void testErrorReport() throws Exception { + IBiblioResolver resolver = new IBiblioResolver(); + resolver.setRoot("http://unknown.host.comx/"); + resolver.setName("test"); + resolver.setM2compatible(true); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + MockMessageImpl mockMessageImpl = new MockMessageImpl(); + Message.setImpl(mockMessageImpl); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "commons-fileupload", + "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNull(rmr); + + mockMessageImpl + .assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.pom"); + mockMessageImpl + .assertLogContains("tried http://unknown.host.comx/org/apache/commons-fileupload/1.0/commons-fileupload-1.0.jar"); + } + + public void testIBiblioArtifacts() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + IBiblioResolver resolver = new IBiblioResolver(); + resolver.setRoot(ibiblioRoot); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "nanning", "0.9"); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false); + dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), + "nanning-profiler", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); + dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), + "nanning-trace", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); + ResolvedModuleRevision rmr = resolver.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals(mrid, rmr.getId()); + + DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), + "nanning-profiler", "jar", "jar"); + DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), + "nanning-trace", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {profiler, trace}, + new DownloadOptions(_settings, _cache)); + assertNotNull(report); + + assertEquals(2, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(profiler); + assertNotNull(ar); + + assertEquals(profiler, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + ar = report.getArtifactReport(trace); + assertNotNull(ar); + + assertEquals(trace, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + report = resolver.download(new Artifact[] {profiler, trace}, new DownloadOptions(_settings, + _cache)); + assertNotNull(report); + + assertEquals(2, report.getArtifactsReports().length); + + ar = report.getArtifactReport(profiler); + assertNotNull(ar); + + assertEquals(profiler, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + + ar = report.getArtifactReport(trace); + assertNotNull(ar); + + assertEquals(trace, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } + + public void testUnknown() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + IBiblioResolver resolver = new IBiblioResolver(); + resolver.setRoot(ibiblioRoot); + resolver.setName("test"); + resolver.setSettings(_settings); + + assertNull(resolver.getDependency(new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("unknown", "unknown", "1.0"), false), _data)); + } + +} diff --git a/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java index b94aeb98..923cc415 100644 --- a/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java +++ b/test/java/org/apache/ivy/plugins/resolver/IvyRepResolverTest.java @@ -1,179 +1,179 @@ -/* - * 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.util.List; - -import junit.framework.TestCase; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DownloadOptions; -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.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; -import org.apache.ivy.core.settings.IvySettings; -import org.apache.ivy.core.sort.SortEngine; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -/** - * - */ -public class IvyRepResolverTest extends TestCase { - // remote.test - - private IvySettings _settings; - - private ResolveEngine _engine; - - private ResolveData _data; - - private File _cache; - - 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().setCache(CacheManager.getInstance( - _settings, _cache))); - _cache.mkdirs(); - _settings.setDefaultCache(_cache); - } - - protected void tearDown() throws Exception { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - public void testDefaults() { - IvyRepResolver resolver = new IvyRepResolver(); - _settings.setVariable("ivy.ivyrep.default.ivy.root", "http://www.jayasoft.fr/myivyrep/"); - _settings.setVariable("ivy.ivyrep.default.ivy.pattern", - "[organisation]/[module]/ivy-[revision].[ext]"); - _settings - .setVariable("ivy.ivyrep.default.artifact.root", "http://www.ibiblio.org/mymaven/"); - _settings.setVariable("ivy.ivyrep.default.artifact.pattern", - "[module]/jars/[artifact]-[revision].jar"); - resolver.setSettings(_settings); - List l = resolver.getIvyPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals( - "http://www.jayasoft.fr/myivyrep/[organisation]/[module]/ivy-[revision].[ext]", l - .get(0)); - l = resolver.getArtifactPatterns(); - assertNotNull(l); - assertEquals(1, l.size()); - assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar", l - .get(0)); - } - - public void testIvyRep() throws Exception { - IvyRepResolver resolver = new IvyRepResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-cli", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - assertEquals(mrid, rmr.getId()); - assertEquals(2, rmr.getDescriptor().getDependencies().length); - - DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), - "commons-cli", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( - _settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - report = resolver.download(new Artifact[] {artifact}, - new DownloadOptions(_settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } - - /* - * Tests IvyRepResolver with a root path given as 'file:/path_to_root' - */ - public void testIvyRepLocalURL() throws Exception { - IvyRepResolver resolver = new IvyRepResolver(); - String rootpath = new File("test/repositories/1").getAbsolutePath(); - - resolver.setName("testLocal"); - resolver.setIvyroot("file:" + rootpath); - resolver.setIvypattern("[organisation]/[module]/ivys/ivy-[revision].xml"); - resolver.setSettings(_settings); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - } - - public void testListing() { - IvyRepResolver resolver = new IvyRepResolver(); - resolver.setName("test"); - resolver.setSettings(_settings); - - OrganisationEntry[] orgs = resolver.listOrganisations(); - ResolverTestHelper.assertOrganisationEntriesContains(resolver, new String[] {"hibernate", - "apache"}, orgs); - - OrganisationEntry org = ResolverTestHelper.getEntry(orgs, "apache"); - ModuleEntry[] mods = resolver.listModules(org); - ResolverTestHelper.assertModuleEntriesContains(resolver, org, new String[] { - "commons-logging", "commons-lang"}, mods); - - ModuleEntry mod = ResolverTestHelper.getEntry(mods, "commons-logging"); - RevisionEntry[] revs = resolver.listRevisions(mod); - ResolverTestHelper.assertRevisionEntriesContains(resolver, mod, new String[] {"1.0", - "1.0.2", "1.0.3", "1.0.4"}, revs); - } -} +/* + * 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.util.List; + +import junit.framework.TestCase; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DownloadOptions; +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.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; +import org.apache.ivy.core.settings.IvySettings; +import org.apache.ivy.core.sort.SortEngine; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +/** + * + */ +public class IvyRepResolverTest extends TestCase { + // remote.test + + private IvySettings _settings; + + private ResolveEngine _engine; + + private ResolveData _data; + + private File _cache; + + 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().setCache(CacheManager.getInstance( + _settings, _cache))); + _cache.mkdirs(); + _settings.setDefaultCache(_cache); + } + + protected void tearDown() throws Exception { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + public void testDefaults() { + IvyRepResolver resolver = new IvyRepResolver(); + _settings.setVariable("ivy.ivyrep.default.ivy.root", "http://www.jayasoft.fr/myivyrep/"); + _settings.setVariable("ivy.ivyrep.default.ivy.pattern", + "[organisation]/[module]/ivy-[revision].[ext]"); + _settings + .setVariable("ivy.ivyrep.default.artifact.root", "http://www.ibiblio.org/mymaven/"); + _settings.setVariable("ivy.ivyrep.default.artifact.pattern", + "[module]/jars/[artifact]-[revision].jar"); + resolver.setSettings(_settings); + List l = resolver.getIvyPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals( + "http://www.jayasoft.fr/myivyrep/[organisation]/[module]/ivy-[revision].[ext]", l + .get(0)); + l = resolver.getArtifactPatterns(); + assertNotNull(l); + assertEquals(1, l.size()); + assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar", l + .get(0)); + } + + public void testIvyRep() throws Exception { + IvyRepResolver resolver = new IvyRepResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-cli", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + assertEquals(mrid, rmr.getId()); + assertEquals(2, rmr.getDescriptor().getDependencies().length); + + DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), + "commons-cli", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( + _settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + report = resolver.download(new Artifact[] {artifact}, + new DownloadOptions(_settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } + + /* + * Tests IvyRepResolver with a root path given as 'file:/path_to_root' + */ + public void testIvyRepLocalURL() throws Exception { + IvyRepResolver resolver = new IvyRepResolver(); + String rootpath = new File("test/repositories/1").getAbsolutePath(); + + resolver.setName("testLocal"); + resolver.setIvyroot("file:" + rootpath); + resolver.setIvypattern("[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver.setSettings(_settings); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + } + + public void testListing() { + IvyRepResolver resolver = new IvyRepResolver(); + resolver.setName("test"); + resolver.setSettings(_settings); + + OrganisationEntry[] orgs = resolver.listOrganisations(); + ResolverTestHelper.assertOrganisationEntriesContains(resolver, new String[] {"hibernate", + "apache"}, orgs); + + OrganisationEntry org = ResolverTestHelper.getEntry(orgs, "apache"); + ModuleEntry[] mods = resolver.listModules(org); + ResolverTestHelper.assertModuleEntriesContains(resolver, org, new String[] { + "commons-logging", "commons-lang"}, mods); + + ModuleEntry mod = ResolverTestHelper.getEntry(mods, "commons-logging"); + RevisionEntry[] revs = resolver.listRevisions(mod); + ResolverTestHelper.assertRevisionEntriesContains(resolver, mod, new String[] {"1.0", + "1.0.2", "1.0.3", "1.0.4"}, revs); + } +} diff --git a/test/java/org/apache/ivy/plugins/resolver/MockResolver.java b/test/java/org/apache/ivy/plugins/resolver/MockResolver.java index 50cfbc9b..21f9e46f 100644 --- a/test/java/org/apache/ivy/plugins/resolver/MockResolver.java +++ b/test/java/org/apache/ivy/plugins/resolver/MockResolver.java @@ -1,109 +1,109 @@ -/* - * 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.URL; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; -import org.apache.ivy.core.module.descriptor.DependencyDescriptor; -import org.apache.ivy.core.module.descriptor.ModuleDescriptor; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.resolve.DownloadOptions; -import org.apache.ivy.core.resolve.ResolveData; -import org.apache.ivy.core.resolve.ResolvedModuleRevision; - -public class MockResolver extends AbstractResolver { - static MockResolver buildMockResolver(String name, boolean findRevision, - final Date publicationDate) { - return buildMockResolver(name, findRevision, ModuleRevisionId.newInstance("test", "test", - "test"), publicationDate); - } - - static MockResolver buildMockResolver(String name, boolean findRevision, - final ModuleRevisionId mrid, final Date publicationDate) { - return buildMockResolver(name, findRevision, mrid, publicationDate, false); - } - - static MockResolver buildMockResolver(String name, boolean findRevision, - final ModuleRevisionId mrid, final Date publicationDate, final boolean isdefault) { - final MockResolver r = new MockResolver(); - r.setName(name); - if (findRevision) { - r.rmr = new ResolvedModuleRevision() { - public DependencyResolver getResolver() { - return r; - } - - public ModuleRevisionId getId() { - return mrid; - } - - public Date getPublicationDate() { - return publicationDate; - } - - public ModuleDescriptor getDescriptor() { - return new DefaultModuleDescriptor(mrid, "integration", new Date(), isdefault); - } - - public boolean isDownloaded() { - return true; - } - - public boolean isSearched() { - return true; - } - - public DependencyResolver getArtifactResolver() { - return r; - } - - public URL getLocalMDUrl() { - return null; - } - }; - } - return r; - } - - List askedDeps = new ArrayList(); - - ResolvedModuleRevision rmr; - - public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) - throws ParseException { - askedDeps.add(dd); - return rmr; - } - - public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { - return null; - } - - public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { - } - -} +/* + * 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.URL; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor; +import org.apache.ivy.core.module.descriptor.DependencyDescriptor; +import org.apache.ivy.core.module.descriptor.ModuleDescriptor; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.resolve.DownloadOptions; +import org.apache.ivy.core.resolve.ResolveData; +import org.apache.ivy.core.resolve.ResolvedModuleRevision; + +public class MockResolver extends AbstractResolver { + static MockResolver buildMockResolver(String name, boolean findRevision, + final Date publicationDate) { + return buildMockResolver(name, findRevision, ModuleRevisionId.newInstance("test", "test", + "test"), publicationDate); + } + + static MockResolver buildMockResolver(String name, boolean findRevision, + final ModuleRevisionId mrid, final Date publicationDate) { + return buildMockResolver(name, findRevision, mrid, publicationDate, false); + } + + static MockResolver buildMockResolver(String name, boolean findRevision, + final ModuleRevisionId mrid, final Date publicationDate, final boolean isdefault) { + final MockResolver r = new MockResolver(); + r.setName(name); + if (findRevision) { + r.rmr = new ResolvedModuleRevision() { + public DependencyResolver getResolver() { + return r; + } + + public ModuleRevisionId getId() { + return mrid; + } + + public Date getPublicationDate() { + return publicationDate; + } + + public ModuleDescriptor getDescriptor() { + return new DefaultModuleDescriptor(mrid, "integration", new Date(), isdefault); + } + + public boolean isDownloaded() { + return true; + } + + public boolean isSearched() { + return true; + } + + public DependencyResolver getArtifactResolver() { + return r; + } + + public URL getLocalMDUrl() { + return null; + } + }; + } + return r; + } + + List askedDeps = new ArrayList(); + + ResolvedModuleRevision rmr; + + public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) + throws ParseException { + askedDeps.add(dd); + return rmr; + } + + public DownloadReport download(Artifact[] artifacts, DownloadOptions options) { + return null; + } + + public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { + } + +} diff --git a/test/java/org/apache/ivy/plugins/resolver/ResolverTestHelper.java b/test/java/org/apache/ivy/plugins/resolver/ResolverTestHelper.java index 5de136ae..bb29db31 100644 --- a/test/java/org/apache/ivy/plugins/resolver/ResolverTestHelper.java +++ b/test/java/org/apache/ivy/plugins/resolver/ResolverTestHelper.java @@ -1,118 +1,118 @@ -/* - * 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 junit.framework.Assert; - -import org.apache.ivy.core.search.ModuleEntry; -import org.apache.ivy.core.search.OrganisationEntry; -import org.apache.ivy.core.search.RevisionEntry; - -/** - * - */ -public class ResolverTestHelper { - static void assertOrganisationEntries(DependencyResolver resolver, String[] orgNames, - OrganisationEntry[] orgs) { - Assert.assertNotNull(orgs); - Assert.assertEquals(orgNames.length, orgs.length); - assertOrganisationEntriesContains(resolver, orgNames, orgs); - } - - static void assertOrganisationEntriesContains(DependencyResolver resolver, String[] orgNames, - OrganisationEntry[] orgs) { - Assert.assertNotNull(orgs); - for (int i = 0; i < orgNames.length; i++) { - boolean found = false; - for (int j = 0; j < orgs.length; j++) { - if (orgNames[i].equals(orgs[j].getOrganisation())) { - found = true; - Assert.assertEquals(resolver, orgs[j].getResolver()); - } - } - Assert.assertTrue("organisation not found: " + orgNames[i], found); - } - } - - static void assertModuleEntries(DependencyResolver resolver, OrganisationEntry org, - String[] names, ModuleEntry[] mods) { - Assert.assertNotNull(mods); - Assert.assertEquals(names.length, mods.length); - assertModuleEntriesContains(resolver, org, names, mods); - } - - static void assertModuleEntriesContains(DependencyResolver resolver, OrganisationEntry org, - String[] names, ModuleEntry[] mods) { - Assert.assertNotNull(mods); - for (int i = 0; i < names.length; i++) { - boolean found = false; - for (int j = 0; j < mods.length; j++) { - if (names[i].equals(mods[j].getModule())) { - found = true; - Assert.assertEquals(resolver, mods[j].getResolver()); - Assert.assertEquals(org, mods[j].getOrganisationEntry()); - } - } - Assert.assertTrue("module not found: " + names[i], found); - } - } - - static void assertRevisionEntries(DependencyResolver resolver, ModuleEntry mod, String[] names, - RevisionEntry[] revs) { - Assert.assertNotNull(revs); - Assert.assertEquals(names.length, revs.length); - assertRevisionEntriesContains(resolver, mod, names, revs); - } - - static void assertRevisionEntriesContains(DependencyResolver resolver, ModuleEntry mod, - String[] names, RevisionEntry[] revs) { - Assert.assertNotNull(revs); - for (int i = 0; i < names.length; i++) { - boolean found = false; - for (int j = 0; j < revs.length; j++) { - if (names[i].equals(revs[j].getRevision())) { - found = true; - Assert.assertEquals(resolver, revs[j].getResolver()); - Assert.assertEquals(mod, revs[j].getModuleEntry()); - } - } - Assert.assertTrue("revision not found: " + names[i], found); - } - } - - static OrganisationEntry getEntry(OrganisationEntry[] orgs, String name) { - for (int i = 0; i < orgs.length; i++) { - if (name.equals(orgs[i].getOrganisation())) { - return orgs[i]; - } - } - Assert.fail("organisation not found: " + name); - return null; // for compilation only - } - - static ModuleEntry getEntry(ModuleEntry[] mods, String name) { - for (int i = 0; i < mods.length; i++) { - if (name.equals(mods[i].getModule())) { - return mods[i]; - } - } - Assert.fail("module not found: " + name); - return null; // for compilation only - } - -} +/* + * 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 junit.framework.Assert; + +import org.apache.ivy.core.search.ModuleEntry; +import org.apache.ivy.core.search.OrganisationEntry; +import org.apache.ivy.core.search.RevisionEntry; + +/** + * + */ +public class ResolverTestHelper { + static void assertOrganisationEntries(DependencyResolver resolver, String[] orgNames, + OrganisationEntry[] orgs) { + Assert.assertNotNull(orgs); + Assert.assertEquals(orgNames.length, orgs.length); + assertOrganisationEntriesContains(resolver, orgNames, orgs); + } + + static void assertOrganisationEntriesContains(DependencyResolver resolver, String[] orgNames, + OrganisationEntry[] orgs) { + Assert.assertNotNull(orgs); + for (int i = 0; i < orgNames.length; i++) { + boolean found = false; + for (int j = 0; j < orgs.length; j++) { + if (orgNames[i].equals(orgs[j].getOrganisation())) { + found = true; + Assert.assertEquals(resolver, orgs[j].getResolver()); + } + } + Assert.assertTrue("organisation not found: " + orgNames[i], found); + } + } + + static void assertModuleEntries(DependencyResolver resolver, OrganisationEntry org, + String[] names, ModuleEntry[] mods) { + Assert.assertNotNull(mods); + Assert.assertEquals(names.length, mods.length); + assertModuleEntriesContains(resolver, org, names, mods); + } + + static void assertModuleEntriesContains(DependencyResolver resolver, OrganisationEntry org, + String[] names, ModuleEntry[] mods) { + Assert.assertNotNull(mods); + for (int i = 0; i < names.length; i++) { + boolean found = false; + for (int j = 0; j < mods.length; j++) { + if (names[i].equals(mods[j].getModule())) { + found = true; + Assert.assertEquals(resolver, mods[j].getResolver()); + Assert.assertEquals(org, mods[j].getOrganisationEntry()); + } + } + Assert.assertTrue("module not found: " + names[i], found); + } + } + + static void assertRevisionEntries(DependencyResolver resolver, ModuleEntry mod, String[] names, + RevisionEntry[] revs) { + Assert.assertNotNull(revs); + Assert.assertEquals(names.length, revs.length); + assertRevisionEntriesContains(resolver, mod, names, revs); + } + + static void assertRevisionEntriesContains(DependencyResolver resolver, ModuleEntry mod, + String[] names, RevisionEntry[] revs) { + Assert.assertNotNull(revs); + for (int i = 0; i < names.length; i++) { + boolean found = false; + for (int j = 0; j < revs.length; j++) { + if (names[i].equals(revs[j].getRevision())) { + found = true; + Assert.assertEquals(resolver, revs[j].getResolver()); + Assert.assertEquals(mod, revs[j].getModuleEntry()); + } + } + Assert.assertTrue("revision not found: " + names[i], found); + } + } + + static OrganisationEntry getEntry(OrganisationEntry[] orgs, String name) { + for (int i = 0; i < orgs.length; i++) { + if (name.equals(orgs[i].getOrganisation())) { + return orgs[i]; + } + } + Assert.fail("organisation not found: " + name); + return null; // for compilation only + } + + static ModuleEntry getEntry(ModuleEntry[] mods, String name) { + for (int i = 0; i < mods.length; i++) { + if (name.equals(mods[i].getModule())) { + return mods[i]; + } + } + Assert.fail("module not found: " + name); + return null; // for compilation only + } + +} diff --git a/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java index 69df1afd..ebf65d0b 100644 --- a/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java +++ b/test/java/org/apache/ivy/plugins/resolver/URLResolverTest.java @@ -1,362 +1,362 @@ -/* - * 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.util.Date; -import java.util.GregorianCalendar; - -import junit.framework.TestCase; - -import org.apache.ivy.core.cache.CacheManager; -import org.apache.ivy.core.event.EventManager; -import org.apache.ivy.core.module.descriptor.Artifact; -import org.apache.ivy.core.module.descriptor.DefaultArtifact; -import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; -import org.apache.ivy.core.module.descriptor.DefaultIncludeRule; -import org.apache.ivy.core.module.id.ArtifactId; -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.core.report.ArtifactDownloadReport; -import org.apache.ivy.core.report.DownloadReport; -import org.apache.ivy.core.report.DownloadStatus; -import org.apache.ivy.core.resolve.DownloadOptions; -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.plugins.matcher.ExactPatternMatcher; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; - -/** - * Tests URLResolver. Http tests are based upon ibiblio site. - */ -public class URLResolverTest extends TestCase { - // remote.test - private IvySettings _settings; - - private ResolveEngine _engine; - - private ResolveData _data; - - private File _cache; - - 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().setCache(CacheManager.getInstance( - _settings, _cache))); - _cache.mkdirs(); - _settings.setDefaultCache(_cache); - } - - protected void tearDown() throws Exception { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(_cache); - del.execute(); - } - - public void testFile() throws Exception { - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - String rootpath = new File("test/repositories/1").getAbsolutePath(); - resolver.addIvyPattern("file:" + rootpath - + "/[organisation]/[module]/ivys/ivy-[revision].xml"); - resolver.addArtifactPattern("file:" + rootpath - + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - - // test to ask to download - DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( - _settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - report = resolver.download(new Artifact[] {artifact}, - new DownloadOptions(_settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } - - public void testLatestFile() throws Exception { - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - String rootpath = new File("test/repositories/1").getAbsolutePath().replaceAll("\\\\", "/"); - resolver.addIvyPattern("file:" + rootpath - + "/[organisation]/[module]/ivys/ivy-[revision].xml"); - resolver.addArtifactPattern("file:" + rootpath - + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); - ResolvedModuleRevision rmr = resolver - .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", - "mod1.1", "latest.integration"), false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - } - - public void testIBiblio() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-fileupload", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - assertEquals(mrid, rmr.getId()); - - DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), - "commons-fileupload", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( - _settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - report = resolver.download(new Artifact[] {artifact}, - new DownloadOptions(_settings, _cache)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } - - public void testIBiblioArtifacts() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "nanning", "0.9"); - DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false); - dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), - "nanning-profiler", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); - dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), - "nanning-trace", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); - ResolvedModuleRevision rmr = resolver.getDependency(dd, _data); - assertNotNull(rmr); - assertEquals(mrid, rmr.getId()); - - DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), - "nanning-profiler", "jar", "jar"); - DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), - "nanning-trace", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {profiler, trace}, - new DownloadOptions(_settings, _cache)); - assertNotNull(report); - - assertEquals(2, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(profiler); - assertNotNull(ar); - - assertEquals(profiler, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - ar = report.getArtifactReport(trace); - assertNotNull(ar); - - assertEquals(trace, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - report = resolver.download(new Artifact[] {profiler, trace}, new DownloadOptions(_settings, - _cache)); - assertNotNull(report); - - assertEquals(2, report.getArtifactsReports().length); - - ar = report.getArtifactReport(profiler); - assertNotNull(ar); - - assertEquals(profiler, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - - ar = report.getArtifactReport(trace); - assertNotNull(ar); - - assertEquals(trace, ar.getArtifact()); - assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - } - - public void testLatestIBiblio() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("objectweb", "asm", "1.4+"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - assertEquals("1.4.3", rmr.getId().getRevision()); - } - - public void testVersionRangeIBiblio() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - resolver.setAlwaysCheckExactRevision(true); - resolver.addIvyPattern(ibiblioRoot + "/[module]/poms/[module]-[revision].pom"); - resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("asm", "asm", "[1.4,1.5]"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - assertEquals("1.4.4", rmr.getId().getRevision()); - } - - public void testUnknown() throws Exception { - String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); - if (ibiblioRoot == null) { - return; - } - - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - resolver.addIvyPattern(ibiblioRoot + "/[module]/ivys/ivy-[revision].xml"); - resolver.addArtifactPattern(ibiblioRoot - + "/maven/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - - assertNull(resolver.getDependency(new DefaultDependencyDescriptor(ModuleRevisionId - .newInstance("unknown", "unknown", "1.0"), false), _data)); - } - - public void testDownloadWithUseOriginIsTrue() throws Exception { - URLResolver resolver = new URLResolver(); - resolver.setSettings(_settings); - String rootpath = new File("test/repositories/1").getAbsolutePath(); - resolver.addIvyPattern("file:" + rootpath - + "/[organisation]/[module]/ivys/ivy-[revision].xml"); - resolver.addArtifactPattern("file:" + rootpath - + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); - resolver.setName("test"); - assertEquals("test", resolver.getName()); - - ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); - ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, - false), _data); - assertNotNull(rmr); - - assertEquals(mrid, rmr.getId()); - Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); - assertEquals(pubdate, rmr.getPublicationDate()); - - // test to ask to download - DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); - DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( - _settings, new CacheManager(_settings, _cache), null, true)); - assertNotNull(report); - - assertEquals(1, report.getArtifactsReports().length); - - ArtifactDownloadReport ar = report.getArtifactReport(artifact); - assertNotNull(ar); - - assertEquals(artifact, ar.getArtifact()); - assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); - - // test to ask to download again, should use cache - // report = resolver.download(new Artifact[] {artifact}, _data.getIvy(), _cache); - // assertNotNull(report); - // - // assertEquals(1, report.getArtifactsReports().length); - // - // ar = report.getArtifactReport(artifact); - // assertNotNull(ar); - // - // assertEquals(artifact, ar.getArtifact()); - // assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); - // - } -} +/* + * 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.util.Date; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +import org.apache.ivy.core.cache.CacheManager; +import org.apache.ivy.core.event.EventManager; +import org.apache.ivy.core.module.descriptor.Artifact; +import org.apache.ivy.core.module.descriptor.DefaultArtifact; +import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor; +import org.apache.ivy.core.module.descriptor.DefaultIncludeRule; +import org.apache.ivy.core.module.id.ArtifactId; +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.core.report.ArtifactDownloadReport; +import org.apache.ivy.core.report.DownloadReport; +import org.apache.ivy.core.report.DownloadStatus; +import org.apache.ivy.core.resolve.DownloadOptions; +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.plugins.matcher.ExactPatternMatcher; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; + +/** + * Tests URLResolver. Http tests are based upon ibiblio site. + */ +public class URLResolverTest extends TestCase { + // remote.test + private IvySettings _settings; + + private ResolveEngine _engine; + + private ResolveData _data; + + private File _cache; + + 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().setCache(CacheManager.getInstance( + _settings, _cache))); + _cache.mkdirs(); + _settings.setDefaultCache(_cache); + } + + protected void tearDown() throws Exception { + Delete del = new Delete(); + del.setProject(new Project()); + del.setDir(_cache); + del.execute(); + } + + public void testFile() throws Exception { + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + String rootpath = new File("test/repositories/1").getAbsolutePath(); + resolver.addIvyPattern("file:" + rootpath + + "/[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver.addArtifactPattern("file:" + rootpath + + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + + // test to ask to download + DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( + _settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + report = resolver.download(new Artifact[] {artifact}, + new DownloadOptions(_settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } + + public void testLatestFile() throws Exception { + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + String rootpath = new File("test/repositories/1").getAbsolutePath().replaceAll("\\\\", "/"); + resolver.addIvyPattern("file:" + rootpath + + "/[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver.addArtifactPattern("file:" + rootpath + + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0"); + ResolvedModuleRevision rmr = resolver + .getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", + "mod1.1", "latest.integration"), false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + } + + public void testIBiblio() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-fileupload", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + assertEquals(mrid, rmr.getId()); + + DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), + "commons-fileupload", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( + _settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + report = resolver.download(new Artifact[] {artifact}, + new DownloadOptions(_settings, _cache)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } + + public void testIBiblioArtifacts() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "nanning", "0.9"); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false); + dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), + "nanning-profiler", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); + dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), + "nanning-trace", "jar", "jar"), ExactPatternMatcher.INSTANCE, null)); + ResolvedModuleRevision rmr = resolver.getDependency(dd, _data); + assertNotNull(rmr); + assertEquals(mrid, rmr.getId()); + + DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), + "nanning-profiler", "jar", "jar"); + DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), + "nanning-trace", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {profiler, trace}, + new DownloadOptions(_settings, _cache)); + assertNotNull(report); + + assertEquals(2, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(profiler); + assertNotNull(ar); + + assertEquals(profiler, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + ar = report.getArtifactReport(trace); + assertNotNull(ar); + + assertEquals(trace, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + report = resolver.download(new Artifact[] {profiler, trace}, new DownloadOptions(_settings, + _cache)); + assertNotNull(report); + + assertEquals(2, report.getArtifactsReports().length); + + ar = report.getArtifactReport(profiler); + assertNotNull(ar); + + assertEquals(profiler, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + + ar = report.getArtifactReport(trace); + assertNotNull(ar); + + assertEquals(trace, ar.getArtifact()); + assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + } + + public void testLatestIBiblio() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("objectweb", "asm", "1.4+"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + assertEquals("1.4.3", rmr.getId().getRevision()); + } + + public void testVersionRangeIBiblio() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + resolver.setAlwaysCheckExactRevision(true); + resolver.addIvyPattern(ibiblioRoot + "/[module]/poms/[module]-[revision].pom"); + resolver.addArtifactPattern(ibiblioRoot + "/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("asm", "asm", "[1.4,1.5]"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + assertEquals("1.4.4", rmr.getId().getRevision()); + } + + public void testUnknown() throws Exception { + String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); + if (ibiblioRoot == null) { + return; + } + + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + resolver.addIvyPattern(ibiblioRoot + "/[module]/ivys/ivy-[revision].xml"); + resolver.addArtifactPattern(ibiblioRoot + + "/maven/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + + assertNull(resolver.getDependency(new DefaultDependencyDescriptor(ModuleRevisionId + .newInstance("unknown", "unknown", "1.0"), false), _data)); + } + + public void testDownloadWithUseOriginIsTrue() throws Exception { + URLResolver resolver = new URLResolver(); + resolver.setSettings(_settings); + String rootpath = new File("test/repositories/1").getAbsolutePath(); + resolver.addIvyPattern("file:" + rootpath + + "/[organisation]/[module]/ivys/ivy-[revision].xml"); + resolver.addArtifactPattern("file:" + rootpath + + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"); + resolver.setName("test"); + assertEquals("test", resolver.getName()); + + ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"); + ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, + false), _data); + assertNotNull(rmr); + + assertEquals(mrid, rmr.getId()); + Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(); + assertEquals(pubdate, rmr.getPublicationDate()); + + // test to ask to download + DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar"); + DownloadReport report = resolver.download(new Artifact[] {artifact}, new DownloadOptions( + _settings, new CacheManager(_settings, _cache), null, true)); + assertNotNull(report); + + assertEquals(1, report.getArtifactsReports().length); + + ArtifactDownloadReport ar = report.getArtifactReport(artifact); + assertNotNull(ar); + + assertEquals(artifact, ar.getArtifact()); + assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); + + // test to ask to download again, should use cache + // report = resolver.download(new Artifact[] {artifact}, _data.getIvy(), _cache); + // assertNotNull(report); + // + // assertEquals(1, report.getArtifactsReports().length); + // + // ar = report.getArtifactReport(artifact); + // assertNotNull(ar); + // + // assertEquals(artifact, ar.getArtifact()); + // assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); + // + } +} diff --git a/test/java/org/apache/ivy/plugins/resolver/chainresolverconf.xml b/test/java/org/apache/ivy/plugins/resolver/chainresolverconf.xml index 711630dd..6f01a336 100644 --- a/test/java/org/apache/ivy/plugins/resolver/chainresolverconf.xml +++ b/test/java/org/apache/ivy/plugins/resolver/chainresolverconf.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/resolver/dualresolverconf-bad.xml b/test/java/org/apache/ivy/plugins/resolver/dualresolverconf-bad.xml index 19e98968..0736820c 100644 --- a/test/java/org/apache/ivy/plugins/resolver/dualresolverconf-bad.xml +++ b/test/java/org/apache/ivy/plugins/resolver/dualresolverconf-bad.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/resolver/dualresolverconf.xml b/test/java/org/apache/ivy/plugins/resolver/dualresolverconf.xml index 40ed5f63..6433e3e9 100644 --- a/test/java/org/apache/ivy/plugins/resolver/dualresolverconf.xml +++ b/test/java/org/apache/ivy/plugins/resolver/dualresolverconf.xml @@ -1,29 +1,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/resolver/ibiblioresolverconf.xml b/test/java/org/apache/ivy/plugins/resolver/ibiblioresolverconf.xml index 881a1d58..feee8109 100644 --- a/test/java/org/apache/ivy/plugins/resolver/ibiblioresolverconf.xml +++ b/test/java/org/apache/ivy/plugins/resolver/ibiblioresolverconf.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/java/org/apache/ivy/plugins/version/MockVersionMatcher.java b/test/java/org/apache/ivy/plugins/version/MockVersionMatcher.java index 219d4591..10f2e02b 100644 --- a/test/java/org/apache/ivy/plugins/version/MockVersionMatcher.java +++ b/test/java/org/apache/ivy/plugins/version/MockVersionMatcher.java @@ -1,35 +1,35 @@ -/* - * 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.version; - -import org.apache.ivy.core.module.id.ModuleRevisionId; - -public class MockVersionMatcher extends AbstractVersionMatcher { - - public MockVersionMatcher() { - } - - public boolean isDynamic(ModuleRevisionId askedMrid) { - return false; - } - - public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { - return false; - } - -} +/* + * 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.version; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +public class MockVersionMatcher extends AbstractVersionMatcher { + + public MockVersionMatcher() { + } + + public boolean isDynamic(ModuleRevisionId askedMrid) { + return false; + } + + public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { + return false; + } + +} diff --git a/test/java/org/apache/ivy/plugins/version/VersionRangeMatcherTest.java b/test/java/org/apache/ivy/plugins/version/VersionRangeMatcherTest.java index 94ea91f4..480815bd 100644 --- a/test/java/org/apache/ivy/plugins/version/VersionRangeMatcherTest.java +++ b/test/java/org/apache/ivy/plugins/version/VersionRangeMatcherTest.java @@ -1,110 +1,110 @@ -/* - * 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.version; - -import junit.framework.TestCase; - -import org.apache.ivy.core.module.id.ModuleRevisionId; -import org.apache.ivy.plugins.latest.LatestRevisionStrategy; - -public class VersionRangeMatcherTest extends TestCase { - VersionMatcher _vm = new VersionRangeMatcher("range", new LatestRevisionStrategy()); - - public VersionRangeMatcherTest() { - } - - public void testDynamic() { - assertDynamic("lastest.integration", false); - assertDynamic("[1.0]", false); - assertDynamic("(1.0)", false); - assertDynamic("(1.0,2.0)", false); - assertDynamic("[1.0;2.0]", false); - - assertDynamic("[1.0,2.0]", true); - assertDynamic("[1.0,2.0[", true); - assertDynamic("]1.0,2.0[", true); - assertDynamic("]1.0,2.0]", true); - assertDynamic("[1.0,)", true); - assertDynamic("(,1.0]", true); - } - - public void testIncludingFinite() { - assertAccept("[1.0,2.0]", "1.1", true); - assertAccept("[1.0,2.0]", "0.9", false); - assertAccept("[1.0,2.0]", "2.1", false); - assertAccept("[1.0,2.0]", "1.0", true); - assertAccept("[1.0,2.0]", "2.0", true); - } - - public void testExcludingFinite() { - assertAccept("]1.0,2.0[", "1.1", true); - assertAccept("]1.0,2.0[", "0.9", false); - assertAccept("]1.0,2.0[", "2.1", false); - - assertAccept("]1.0,2.0]", "1.0", false); - assertAccept("]1.0,2.0[", "1.0", false); - assertAccept("[1.0,2.0[", "1.0", true); - - assertAccept("[1.0,2.0[", "2.0", false); - assertAccept("]1.0,2.0[", "2.0", false); - assertAccept("]1.0,2.0]", "2.0", true); - } - - public void testIncludingInfinite() { - assertAccept("[1.0,)", "1.1", true); - assertAccept("[1.0,)", "2.0", true); - assertAccept("[1.0,)", "3.5.6", true); - assertAccept("[1.0,)", "1.0", true); - - assertAccept("[1.0,)", "0.9", false); - - assertAccept("(,2.0]", "1.1", true); - assertAccept("(,2.0]", "0.1", true); - assertAccept("(,2.0]", "0.2.4", true); - assertAccept("(,2.0]", "2.0", true); - - assertAccept("(,2.0]", "2.3", false); - } - - public void testExcludingInfinite() { - assertAccept("]1.0,)", "1.1", true); - assertAccept("]1.0,)", "2.0", true); - assertAccept("]1.0,)", "3.5.6", true); - - assertAccept("]1.0,)", "1.0", false); - assertAccept("]1.0,)", "0.9", false); - - assertAccept("(,2.0[", "1.1", true); - assertAccept("(,2.0[", "0.1", true); - assertAccept("(,2.0[", "0.2.4", true); - - assertAccept("(,2.0[", "2.0", false); - assertAccept("(,2.0[", "2.3", false); - } - - // assertion helper methods - - private void assertDynamic(String askedVersion, boolean b) { - assertEquals(b, _vm.isDynamic(ModuleRevisionId.newInstance("org", "name", askedVersion))); - } - - private void assertAccept(String askedVersion, String depVersion, boolean b) { - assertEquals(b, _vm.accept(ModuleRevisionId.newInstance("org", "name", askedVersion), - ModuleRevisionId.newInstance("org", "name", depVersion))); - } -} +/* + * 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.version; + +import junit.framework.TestCase; + +import org.apache.ivy.core.module.id.ModuleRevisionId; +import org.apache.ivy.plugins.latest.LatestRevisionStrategy; + +public class VersionRangeMatcherTest extends TestCase { + VersionMatcher _vm = new VersionRangeMatcher("range", new LatestRevisionStrategy()); + + public VersionRangeMatcherTest() { + } + + public void testDynamic() { + assertDynamic("lastest.integration", false); + assertDynamic("[1.0]", false); + assertDynamic("(1.0)", false); + assertDynamic("(1.0,2.0)", false); + assertDynamic("[1.0;2.0]", false); + + assertDynamic("[1.0,2.0]", true); + assertDynamic("[1.0,2.0[", true); + assertDynamic("]1.0,2.0[", true); + assertDynamic("]1.0,2.0]", true); + assertDynamic("[1.0,)", true); + assertDynamic("(,1.0]", true); + } + + public void testIncludingFinite() { + assertAccept("[1.0,2.0]", "1.1", true); + assertAccept("[1.0,2.0]", "0.9", false); + assertAccept("[1.0,2.0]", "2.1", false); + assertAccept("[1.0,2.0]", "1.0", true); + assertAccept("[1.0,2.0]", "2.0", true); + } + + public void testExcludingFinite() { + assertAccept("]1.0,2.0[", "1.1", true); + assertAccept("]1.0,2.0[", "0.9", false); + assertAccept("]1.0,2.0[", "2.1", false); + + assertAccept("]1.0,2.0]", "1.0", false); + assertAccept("]1.0,2.0[", "1.0", false); + assertAccept("[1.0,2.0[", "1.0", true); + + assertAccept("[1.0,2.0[", "2.0", false); + assertAccept("]1.0,2.0[", "2.0", false); + assertAccept("]1.0,2.0]", "2.0", true); + } + + public void testIncludingInfinite() { + assertAccept("[1.0,)", "1.1", true); + assertAccept("[1.0,)", "2.0", true); + assertAccept("[1.0,)", "3.5.6", true); + assertAccept("[1.0,)", "1.0", true); + + assertAccept("[1.0,)", "0.9", false); + + assertAccept("(,2.0]", "1.1", true); + assertAccept("(,2.0]", "0.1", true); + assertAccept("(,2.0]", "0.2.4", true); + assertAccept("(,2.0]", "2.0", true); + + assertAccept("(,2.0]", "2.3", false); + } + + public void testExcludingInfinite() { + assertAccept("]1.0,)", "1.1", true); + assertAccept("]1.0,)", "2.0", true); + assertAccept("]1.0,)", "3.5.6", true); + + assertAccept("]1.0,)", "1.0", false); + assertAccept("]1.0,)", "0.9", false); + + assertAccept("(,2.0[", "1.1", true); + assertAccept("(,2.0[", "0.1", true); + assertAccept("(,2.0[", "0.2.4", true); + + assertAccept("(,2.0[", "2.0", false); + assertAccept("(,2.0[", "2.3", false); + } + + // assertion helper methods + + private void assertDynamic(String askedVersion, boolean b) { + assertEquals(b, _vm.isDynamic(ModuleRevisionId.newInstance("org", "name", askedVersion))); + } + + private void assertAccept(String askedVersion, String depVersion, boolean b) { + assertEquals(b, _vm.accept(ModuleRevisionId.newInstance("org", "name", askedVersion), + ModuleRevisionId.newInstance("org", "name", depVersion))); + } +} diff --git a/test/java/org/apache/ivy/util/ConfiguratorTest.java b/test/java/org/apache/ivy/util/ConfiguratorTest.java index e541d000..1b70277f 100644 --- a/test/java/org/apache/ivy/util/ConfiguratorTest.java +++ b/test/java/org/apache/ivy/util/ConfiguratorTest.java @@ -1,337 +1,337 @@ -/* - * 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.util; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -/** - * - */ -public class ConfiguratorTest extends TestCase { - public static class City { - private List _housings = new ArrayList(); - - private List _streets = new ArrayList(); - - private String _name; - - public String getName() { - return _name; - } - - public void setName(String name) { - _name = name; - } - - public List getHousings() { - return _housings; - } - - public List getStreets() { - return _streets; - } - - public void add(Housing h) { - _housings.add(h); - } - - public void add(Street s) { - _streets.add(s); - } - } - - public static class Street { - private Class _clazz; - - private List _trees = new ArrayList(); - - public List getTrees() { - return _trees; - } - - public void addConfiguredTree(Tree tree) { - _trees.add(tree); - } - - public Class getClazz() { - return _clazz; - } - - public void setClazz(Class clazz) { - _clazz = clazz; - } - } - - public static abstract class Housing { - private List _rooms = new ArrayList(); - - private boolean _isEmpty; - - private Person _proprietary; - - public List getRooms() { - return _rooms; - } - - public void addRoom(Room r) { - _rooms.add(r); - } - - public boolean isEmpty() { - return _isEmpty; - } - - public void setEmpty(boolean isEmpty) { - _isEmpty = isEmpty; - } - - public Person getProprietary() { - return _proprietary; - } - - public void setProprietary(Person proprietary) { - _proprietary = proprietary; - } - } - - public static class House extends Housing { - } - - public static class Tree { - private short _age; - - public short getAge() { - return _age; - } - - public void setAge(short age) { - _age = age; - } - } - - public static class Flat extends Housing { - private int _stage; - - public int getStage() { - return _stage; - } - - public void setStage(int stage) { - _stage = stage; - } - } - - public static class Room { - private short _surface; - - public short getSurface() { - return _surface; - } - - public void setSurface(short surface) { - _surface = surface; - } - } - - public static class Person { - private String _name; - - public Person(String name) { - _name = name; - } - - public String getName() { - return _name; - } - } - - private Configurator _conf; - - protected void setUp() throws Exception { - _conf = new Configurator(); - } - - public void testSetRoot() { - City city = new City(); - _conf.setRoot(city); - assertEquals(city, _conf.getCurrent()); - } - - public void testStringAttribute() { - City city = new City(); - _conf.setRoot(city); - _conf.setAttribute("name", "bordeaux"); - assertEquals("bordeaux", city.getName()); - } - - public void testIntAttribute() { - Flat flat = new Flat(); - _conf.setRoot(flat); - _conf.setAttribute("stage", "4"); - assertEquals(4, flat.getStage()); - } - - public void testBooleanAttribute() { - Housing housing = new House(); - _conf.setRoot(housing); - _conf.setAttribute("empty", "true"); - assertEquals(true, housing.isEmpty()); - _conf.setAttribute("empty", "false"); - assertEquals(false, housing.isEmpty()); - _conf.setAttribute("empty", "yes"); - assertEquals(true, housing.isEmpty()); - _conf.setAttribute("empty", "no"); - assertEquals(false, housing.isEmpty()); - _conf.setAttribute("empty", "on"); - assertEquals(true, housing.isEmpty()); - _conf.setAttribute("empty", "off"); - assertEquals(false, housing.isEmpty()); - } - - public void testClassAttribute() { - Street street = new Street(); - _conf.setRoot(street); - _conf.setAttribute("clazz", getClass().getName()); - assertEquals(getClass(), street.getClazz()); - } - - public void testPersonAttribute() { - Housing housing = new House(); - _conf.setRoot(housing); - _conf.setAttribute("proprietary", "jean"); - assertEquals("jean", housing.getProprietary().getName()); - } - - public void testAddRoom() { - Housing housing = new House(); - _conf.setRoot(housing); - _conf.startCreateChild("room"); - assertEquals(1, housing.getRooms().size()); - _conf.setAttribute("surface", "24"); - assertEquals(24, ((Room) housing.getRooms().get(0)).getSurface()); - _conf.endCreateChild(); - assertEquals(housing, _conf.getCurrent()); - } - - public void testAddConfiguredTree() { - Street street = new Street(); - _conf.setRoot(street); - _conf.startCreateChild("tree"); - assertTrue(street.getTrees().isEmpty()); - _conf.setAttribute("age", "400"); - _conf.endCreateChild(); - assertEquals(1, street.getTrees().size()); - assertEquals(400, ((Tree) street.getTrees().get(0)).getAge()); - assertEquals(street, _conf.getCurrent()); - } - - public void testAddWithTypeDef() throws Exception { - City city = new City(); - _conf.typeDef("house", House.class.getName()); - _conf.typeDef("flat", Flat.class.getName()); - _conf.typeDef("street", Street.class.getName()); - _conf.setRoot(city); - _conf.startCreateChild("house"); - assertEquals(1, city.getHousings().size()); - assertTrue(city.getHousings().get(0) instanceof House); - _conf.endCreateChild(); - _conf.startCreateChild("flat"); - assertEquals(2, city.getHousings().size()); - assertTrue(city.getHousings().get(1) instanceof Flat); - _conf.endCreateChild(); - _conf.startCreateChild("street"); - assertEquals(1, city.getStreets().size()); - _conf.endCreateChild(); - assertEquals(city, _conf.getCurrent()); - } - - public void testNested() throws Exception { - City city = new City(); - _conf.typeDef("house", House.class.getName()); - _conf.setRoot(city); - _conf.startCreateChild("house"); - _conf.startCreateChild("room"); - _conf.setAttribute("surface", "20"); - _conf.endCreateChild(); - _conf.startCreateChild("room"); - _conf.setAttribute("surface", "25"); - _conf.endCreateChild(); - _conf.endCreateChild(); - assertEquals(city, _conf.getCurrent()); - assertEquals(2, ((Housing) city.getHousings().get(0)).getRooms().size()); - assertEquals(20, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(0)) - .getSurface()); - assertEquals(25, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(1)) - .getSurface()); - } - - public void testMacro() throws Exception { - City city = new City(); - _conf.typeDef("house", House.class.getName()); - - _conf.startMacroDef("castle"); - _conf.addMacroAttribute("surface", "40"); - _conf.addMacroElement("addroom", true); - _conf.startCreateChild("house"); - _conf.startCreateChild("room"); - _conf.setAttribute("surface", "@{surface}"); - _conf.endCreateChild(); - _conf.startCreateChild("room"); - _conf.setAttribute("surface", "@{surface}"); - _conf.endCreateChild(); - _conf.startCreateChild("addroom"); - _conf.endCreateChild(); - _conf.endCreateChild(); - _conf.endMacroDef(); - - _conf.setRoot(city); - _conf.startCreateChild("castle"); - _conf.setAttribute("surface", "10"); - _conf.endCreateChild(); - - _conf.startCreateChild("castle"); - _conf.startCreateChild("addroom"); - _conf.startCreateChild("room"); - _conf.setAttribute("surface", "20"); - _conf.endCreateChild(); - _conf.endCreateChild(); - _conf.endCreateChild(); - - assertEquals(city, _conf.getCurrent()); - assertEquals(2, city.getHousings().size()); - - // first castle : 2 default rooms of 10 of surface - assertEquals(2, ((Housing) city.getHousings().get(0)).getRooms().size()); - assertEquals(10, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(0)) - .getSurface()); - assertEquals(10, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(1)) - .getSurface()); - - // second castle : 2 default rooms of default surface 40, + one addroom of surface 20 - assertEquals(3, ((Housing) city.getHousings().get(1)).getRooms().size()); - assertEquals(40, ((Room) ((Housing) city.getHousings().get(1)).getRooms().get(0)) - .getSurface()); - assertEquals(40, ((Room) ((Housing) city.getHousings().get(1)).getRooms().get(1)) - .getSurface()); - assertEquals(20, ((Room) ((Housing) city.getHousings().get(1)).getRooms().get(2)) - .getSurface()); - } -} +/* + * 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.util; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +/** + * + */ +public class ConfiguratorTest extends TestCase { + public static class City { + private List _housings = new ArrayList(); + + private List _streets = new ArrayList(); + + private String _name; + + public String getName() { + return _name; + } + + public void setName(String name) { + _name = name; + } + + public List getHousings() { + return _housings; + } + + public List getStreets() { + return _streets; + } + + public void add(Housing h) { + _housings.add(h); + } + + public void add(Street s) { + _streets.add(s); + } + } + + public static class Street { + private Class _clazz; + + private List _trees = new ArrayList(); + + public List getTrees() { + return _trees; + } + + public void addConfiguredTree(Tree tree) { + _trees.add(tree); + } + + public Class getClazz() { + return _clazz; + } + + public void setClazz(Class clazz) { + _clazz = clazz; + } + } + + public static abstract class Housing { + private List _rooms = new ArrayList(); + + private boolean _isEmpty; + + private Person _proprietary; + + public List getRooms() { + return _rooms; + } + + public void addRoom(Room r) { + _rooms.add(r); + } + + public boolean isEmpty() { + return _isEmpty; + } + + public void setEmpty(boolean isEmpty) { + _isEmpty = isEmpty; + } + + public Person getProprietary() { + return _proprietary; + } + + public void setProprietary(Person proprietary) { + _proprietary = proprietary; + } + } + + public static class House extends Housing { + } + + public static class Tree { + private short _age; + + public short getAge() { + return _age; + } + + public void setAge(short age) { + _age = age; + } + } + + public static class Flat extends Housing { + private int _stage; + + public int getStage() { + return _stage; + } + + public void setStage(int stage) { + _stage = stage; + } + } + + public static class Room { + private short _surface; + + public short getSurface() { + return _surface; + } + + public void setSurface(short surface) { + _surface = surface; + } + } + + public static class Person { + private String _name; + + public Person(String name) { + _name = name; + } + + public String getName() { + return _name; + } + } + + private Configurator _conf; + + protected void setUp() throws Exception { + _conf = new Configurator(); + } + + public void testSetRoot() { + City city = new City(); + _conf.setRoot(city); + assertEquals(city, _conf.getCurrent()); + } + + public void testStringAttribute() { + City city = new City(); + _conf.setRoot(city); + _conf.setAttribute("name", "bordeaux"); + assertEquals("bordeaux", city.getName()); + } + + public void testIntAttribute() { + Flat flat = new Flat(); + _conf.setRoot(flat); + _conf.setAttribute("stage", "4"); + assertEquals(4, flat.getStage()); + } + + public void testBooleanAttribute() { + Housing housing = new House(); + _conf.setRoot(housing); + _conf.setAttribute("empty", "true"); + assertEquals(true, housing.isEmpty()); + _conf.setAttribute("empty", "false"); + assertEquals(false, housing.isEmpty()); + _conf.setAttribute("empty", "yes"); + assertEquals(true, housing.isEmpty()); + _conf.setAttribute("empty", "no"); + assertEquals(false, housing.isEmpty()); + _conf.setAttribute("empty", "on"); + assertEquals(true, housing.isEmpty()); + _conf.setAttribute("empty", "off"); + assertEquals(false, housing.isEmpty()); + } + + public void testClassAttribute() { + Street street = new Street(); + _conf.setRoot(street); + _conf.setAttribute("clazz", getClass().getName()); + assertEquals(getClass(), street.getClazz()); + } + + public void testPersonAttribute() { + Housing housing = new House(); + _conf.setRoot(housing); + _conf.setAttribute("proprietary", "jean"); + assertEquals("jean", housing.getProprietary().getName()); + } + + public void testAddRoom() { + Housing housing = new House(); + _conf.setRoot(housing); + _conf.startCreateChild("room"); + assertEquals(1, housing.getRooms().size()); + _conf.setAttribute("surface", "24"); + assertEquals(24, ((Room) housing.getRooms().get(0)).getSurface()); + _conf.endCreateChild(); + assertEquals(housing, _conf.getCurrent()); + } + + public void testAddConfiguredTree() { + Street street = new Street(); + _conf.setRoot(street); + _conf.startCreateChild("tree"); + assertTrue(street.getTrees().isEmpty()); + _conf.setAttribute("age", "400"); + _conf.endCreateChild(); + assertEquals(1, street.getTrees().size()); + assertEquals(400, ((Tree) street.getTrees().get(0)).getAge()); + assertEquals(street, _conf.getCurrent()); + } + + public void testAddWithTypeDef() throws Exception { + City city = new City(); + _conf.typeDef("house", House.class.getName()); + _conf.typeDef("flat", Flat.class.getName()); + _conf.typeDef("street", Street.class.getName()); + _conf.setRoot(city); + _conf.startCreateChild("house"); + assertEquals(1, city.getHousings().size()); + assertTrue(city.getHousings().get(0) instanceof House); + _conf.endCreateChild(); + _conf.startCreateChild("flat"); + assertEquals(2, city.getHousings().size()); + assertTrue(city.getHousings().get(1) instanceof Flat); + _conf.endCreateChild(); + _conf.startCreateChild("street"); + assertEquals(1, city.getStreets().size()); + _conf.endCreateChild(); + assertEquals(city, _conf.getCurrent()); + } + + public void testNested() throws Exception { + City city = new City(); + _conf.typeDef("house", House.class.getName()); + _conf.setRoot(city); + _conf.startCreateChild("house"); + _conf.startCreateChild("room"); + _conf.setAttribute("surface", "20"); + _conf.endCreateChild(); + _conf.startCreateChild("room"); + _conf.setAttribute("surface", "25"); + _conf.endCreateChild(); + _conf.endCreateChild(); + assertEquals(city, _conf.getCurrent()); + assertEquals(2, ((Housing) city.getHousings().get(0)).getRooms().size()); + assertEquals(20, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(0)) + .getSurface()); + assertEquals(25, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(1)) + .getSurface()); + } + + public void testMacro() throws Exception { + City city = new City(); + _conf.typeDef("house", House.class.getName()); + + _conf.startMacroDef("castle"); + _conf.addMacroAttribute("surface", "40"); + _conf.addMacroElement("addroom", true); + _conf.startCreateChild("house"); + _conf.startCreateChild("room"); + _conf.setAttribute("surface", "@{surface}"); + _conf.endCreateChild(); + _conf.startCreateChild("room"); + _conf.setAttribute("surface", "@{surface}"); + _conf.endCreateChild(); + _conf.startCreateChild("addroom"); + _conf.endCreateChild(); + _conf.endCreateChild(); + _conf.endMacroDef(); + + _conf.setRoot(city); + _conf.startCreateChild("castle"); + _conf.setAttribute("surface", "10"); + _conf.endCreateChild(); + + _conf.startCreateChild("castle"); + _conf.startCreateChild("addroom"); + _conf.startCreateChild("room"); + _conf.setAttribute("surface", "20"); + _conf.endCreateChild(); + _conf.endCreateChild(); + _conf.endCreateChild(); + + assertEquals(city, _conf.getCurrent()); + assertEquals(2, city.getHousings().size()); + + // first castle : 2 default rooms of 10 of surface + assertEquals(2, ((Housing) city.getHousings().get(0)).getRooms().size()); + assertEquals(10, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(0)) + .getSurface()); + assertEquals(10, ((Room) ((Housing) city.getHousings().get(0)).getRooms().get(1)) + .getSurface()); + + // second castle : 2 default rooms of default surface 40, + one addroom of surface 20 + assertEquals(3, ((Housing) city.getHousings().get(1)).getRooms().size()); + assertEquals(40, ((Room) ((Housing) city.getHousings().get(1)).getRooms().get(0)) + .getSurface()); + assertEquals(40, ((Room) ((Housing) city.getHousings().get(1)).getRooms().get(1)) + .getSurface()); + assertEquals(20, ((Room) ((Housing) city.getHousings().get(1)).getRooms().get(2)) + .getSurface()); + } +} diff --git a/test/java/org/apache/ivy/util/IvyPatternHelperTest.java b/test/java/org/apache/ivy/util/IvyPatternHelperTest.java index a0cc903e..2a45f3f1 100644 --- a/test/java/org/apache/ivy/util/IvyPatternHelperTest.java +++ b/test/java/org/apache/ivy/util/IvyPatternHelperTest.java @@ -1,66 +1,66 @@ -/* - * 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.util; - -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.ivy.core.IvyPatternHelper; - -public class IvyPatternHelperTest extends TestCase { - public void testSubstitute() { - String pattern = "[organisation]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; - assertEquals("apache/Test/build/archives/jars/test-1.0.jar", IvyPatternHelper.substitute( - pattern, "apache", "Test", "1.0", "test", "jar", "jar")); - } - - public void testCyclicSubstitute() { - String pattern = "${var}"; - Map variables = new HashMap(); - variables.put("var", "${othervar}"); - variables.put("othervar", "${var}"); - try { - IvyPatternHelper.substituteVariables(pattern, variables); - fail("cyclic var should raise an exception"); - } catch (Exception ex) { - // ok - } catch (Error er) { - fail("cyclic var shouldn't raise an error: " + er); - } - } - - public void testOptionalSubstitute() { - Map tokens = new HashMap(); - tokens.put("token", ""); - tokens.put("othertoken", "myval"); - assertEquals("test-myval", IvyPatternHelper.substituteTokens( - "test(-[token])(-[othertoken])", tokens)); - tokens.put("token", "val"); - assertEquals("test-val-myval", IvyPatternHelper.substituteTokens( - "test(-[token])(-[othertoken])", tokens)); - } - - public void testOrganization() { - String pattern = "[organization]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; - assertEquals("apache/Test/build/archives/jars/test-1.0.jar", IvyPatternHelper.substitute( - pattern, "apache", "Test", "1.0", "test", "jar", "jar")); - } - -} +/* + * 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.util; + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.ivy.core.IvyPatternHelper; + +public class IvyPatternHelperTest extends TestCase { + public void testSubstitute() { + String pattern = "[organisation]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; + assertEquals("apache/Test/build/archives/jars/test-1.0.jar", IvyPatternHelper.substitute( + pattern, "apache", "Test", "1.0", "test", "jar", "jar")); + } + + public void testCyclicSubstitute() { + String pattern = "${var}"; + Map variables = new HashMap(); + variables.put("var", "${othervar}"); + variables.put("othervar", "${var}"); + try { + IvyPatternHelper.substituteVariables(pattern, variables); + fail("cyclic var should raise an exception"); + } catch (Exception ex) { + // ok + } catch (Error er) { + fail("cyclic var shouldn't raise an error: " + er); + } + } + + public void testOptionalSubstitute() { + Map tokens = new HashMap(); + tokens.put("token", ""); + tokens.put("othertoken", "myval"); + assertEquals("test-myval", IvyPatternHelper.substituteTokens( + "test(-[token])(-[othertoken])", tokens)); + tokens.put("token", "val"); + assertEquals("test-val-myval", IvyPatternHelper.substituteTokens( + "test(-[token])(-[othertoken])", tokens)); + } + + public void testOrganization() { + String pattern = "[organization]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; + assertEquals("apache/Test/build/archives/jars/test-1.0.jar", IvyPatternHelper.substitute( + pattern, "apache", "Test", "1.0", "test", "jar", "jar")); + } + +} diff --git a/test/java/org/apache/ivy/util/MockMessageImpl.java b/test/java/org/apache/ivy/util/MockMessageImpl.java index a21016cb..8a655945 100644 --- a/test/java/org/apache/ivy/util/MockMessageImpl.java +++ b/test/java/org/apache/ivy/util/MockMessageImpl.java @@ -1,110 +1,110 @@ -/* - * 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.util; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import junit.framework.AssertionFailedError; - -public class MockMessageImpl implements MessageImpl { - - private List _endProgress = new ArrayList(); - - private List _logs = new ArrayList(); - - private List _rawLogs = new ArrayList(); - - private int _progressCalls; - - public void endProgress(String msg) { - _endProgress.add(msg); - } - - public void log(String msg, int level) { - _logs.add(level + " " + msg); - } - - public void progress() { - _progressCalls++; - } - - public void rawlog(String msg, int level) { - _rawLogs.add(level + " " + msg); - } - - public List getEndProgress() { - return _endProgress; - } - - public List getLogs() { - return _logs; - } - - public int getProgressCalls() { - return _progressCalls; - } - - public List getRawLogs() { - return _rawLogs; - } - - public void clear() { - _logs.clear(); - _rawLogs.clear(); - _endProgress.clear(); - _progressCalls = 0; - } - - public void assertLogContains(String message) { - for (Iterator iter = _logs.iterator(); iter.hasNext();) { - String log = (String) iter.next(); - if (log.indexOf(message) != -1) { - return; - } - } - throw new AssertionFailedError("logs do not contain expected message: expected='" + message - + "' logs='\n" + join(_logs) + "'"); - - } - - public void assertLogInfoContains(String message) { - assertLogContains(Message.MSG_INFO + " " + message); - } - - public void assertLogWarningContains(String message) { - Message.sumupProblems(); - assertLogContains(Message.MSG_WARN + " \t" + message); - } - - public void assertLogErrorContains(String message) { - Message.sumupProblems(); - assertLogContains(Message.MSG_ERR + " " + message); - } - - private String join(List logs) { - StringBuffer sb = new StringBuffer(); - for (Iterator iter = logs.iterator(); iter.hasNext();) { - String log = (String) iter.next(); - sb.append(log).append("\n"); - } - return sb.toString(); - } - -} +/* + * 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.util; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.AssertionFailedError; + +public class MockMessageImpl implements MessageImpl { + + private List _endProgress = new ArrayList(); + + private List _logs = new ArrayList(); + + private List _rawLogs = new ArrayList(); + + private int _progressCalls; + + public void endProgress(String msg) { + _endProgress.add(msg); + } + + public void log(String msg, int level) { + _logs.add(level + " " + msg); + } + + public void progress() { + _progressCalls++; + } + + public void rawlog(String msg, int level) { + _rawLogs.add(level + " " + msg); + } + + public List getEndProgress() { + return _endProgress; + } + + public List getLogs() { + return _logs; + } + + public int getProgressCalls() { + return _progressCalls; + } + + public List getRawLogs() { + return _rawLogs; + } + + public void clear() { + _logs.clear(); + _rawLogs.clear(); + _endProgress.clear(); + _progressCalls = 0; + } + + public void assertLogContains(String message) { + for (Iterator iter = _logs.iterator(); iter.hasNext();) { + String log = (String) iter.next(); + if (log.indexOf(message) != -1) { + return; + } + } + throw new AssertionFailedError("logs do not contain expected message: expected='" + message + + "' logs='\n" + join(_logs) + "'"); + + } + + public void assertLogInfoContains(String message) { + assertLogContains(Message.MSG_INFO + " " + message); + } + + public void assertLogWarningContains(String message) { + Message.sumupProblems(); + assertLogContains(Message.MSG_WARN + " \t" + message); + } + + public void assertLogErrorContains(String message) { + Message.sumupProblems(); + assertLogContains(Message.MSG_ERR + " " + message); + } + + private String join(List logs) { + StringBuffer sb = new StringBuffer(); + for (Iterator iter = logs.iterator(); iter.hasNext();) { + String log = (String) iter.next(); + sb.append(log).append("\n"); + } + return sb.toString(); + } + +} diff --git a/test/java/org/apache/ivy/util/StringUtilsTest.java b/test/java/org/apache/ivy/util/StringUtilsTest.java index bc43dccd..a711eaea 100644 --- a/test/java/org/apache/ivy/util/StringUtilsTest.java +++ b/test/java/org/apache/ivy/util/StringUtilsTest.java @@ -1,31 +1,31 @@ -/* - * 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.util; - -import junit.framework.TestCase; - -public class StringUtilsTest extends TestCase { - public void testEncryption() { - assertEquals("apache", StringUtils.decrypt(StringUtils.encrypt("apache"))); - assertEquals("yet another string with 126 digits and others :;%_-$& characters", - StringUtils.decrypt(StringUtils - .encrypt("yet another string with 126 digits and others :;%_-$& characters"))); - - assertFalse("apache".equals(StringUtils.encrypt("apache"))); - } -} +/* + * 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.util; + +import junit.framework.TestCase; + +public class StringUtilsTest extends TestCase { + public void testEncryption() { + assertEquals("apache", StringUtils.decrypt(StringUtils.encrypt("apache"))); + assertEquals("yet another string with 126 digits and others :;%_-$& characters", + StringUtils.decrypt(StringUtils + .encrypt("yet another string with 126 digits and others :;%_-$& characters"))); + + assertFalse("apache".equals(StringUtils.encrypt("apache"))); + } +} diff --git a/test/java/org/apache/ivy/util/url/ApacheURLListerTest.java b/test/java/org/apache/ivy/util/url/ApacheURLListerTest.java index fdf27b3b..dc0964ac 100644 --- a/test/java/org/apache/ivy/util/url/ApacheURLListerTest.java +++ b/test/java/org/apache/ivy/util/url/ApacheURLListerTest.java @@ -1,73 +1,73 @@ -/* - * 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.util.url; - -import java.net.URL; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -/** - * Tests {@link ApacheURLLister}. - */ -public class ApacheURLListerTest extends TestCase { - - /** - * Tests {@link ApacheURLLister#retrieveListing(URL, boolean, boolean)}. - * - * @throws Exception - */ - public void testRetrieveListing() throws Exception { - ApacheURLLister lister = new ApacheURLLister(); - - List files = lister.retrieveListing(ApacheURLListerTest.class - .getResource("apache-file-listing.html"), true, false); - assertNotNull(files); - assertTrue(files.size() > 0); - for (Iterator iter = files.iterator(); iter.hasNext();) { - URL file = (URL) iter.next(); - assertTrue("found a non matching file: " + file, file.getPath().matches( - ".*/[^/]+\\.(jar|md5|sha1)")); - } - - // try a directory listing - List dirs = lister.retrieveListing(ApacheURLListerTest.class - .getResource("apache-dir-listing.html"), false, true); - assertNotNull(dirs); - assertEquals(4, dirs.size()); - - List empty = lister.retrieveListing(ApacheURLListerTest.class - .getResource("apache-dir-listing.html"), true, false); - assertTrue(empty.isEmpty()); - } - - /** - * Tests {@link ApacheURLLister#retrieveListing(URL, boolean, boolean)}. - * - * @throws Exception - */ - public void testRetrieveListingWithSpaces() throws Exception { - ApacheURLLister lister = new ApacheURLLister(); - - List files = lister.retrieveListing(ApacheURLListerTest.class - .getResource("listing-with-spaces.html"), true, false); - assertNotNull(files); - assertTrue(files.size() > 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. + * + */ +package org.apache.ivy.util.url; + +import java.net.URL; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +/** + * Tests {@link ApacheURLLister}. + */ +public class ApacheURLListerTest extends TestCase { + + /** + * Tests {@link ApacheURLLister#retrieveListing(URL, boolean, boolean)}. + * + * @throws Exception + */ + public void testRetrieveListing() throws Exception { + ApacheURLLister lister = new ApacheURLLister(); + + List files = lister.retrieveListing(ApacheURLListerTest.class + .getResource("apache-file-listing.html"), true, false); + assertNotNull(files); + assertTrue(files.size() > 0); + for (Iterator iter = files.iterator(); iter.hasNext();) { + URL file = (URL) iter.next(); + assertTrue("found a non matching file: " + file, file.getPath().matches( + ".*/[^/]+\\.(jar|md5|sha1)")); + } + + // try a directory listing + List dirs = lister.retrieveListing(ApacheURLListerTest.class + .getResource("apache-dir-listing.html"), false, true); + assertNotNull(dirs); + assertEquals(4, dirs.size()); + + List empty = lister.retrieveListing(ApacheURLListerTest.class + .getResource("apache-dir-listing.html"), true, false); + assertTrue(empty.isEmpty()); + } + + /** + * Tests {@link ApacheURLLister#retrieveListing(URL, boolean, boolean)}. + * + * @throws Exception + */ + public void testRetrieveListingWithSpaces() throws Exception { + ApacheURLLister lister = new ApacheURLLister(); + + List files = lister.retrieveListing(ApacheURLListerTest.class + .getResource("listing-with-spaces.html"), true, false); + assertNotNull(files); + assertTrue(files.size() > 0); + } +} diff --git a/test/java/org/apache/ivy/util/url/BasicURLHandlerTest.java b/test/java/org/apache/ivy/util/url/BasicURLHandlerTest.java index d9f5cec0..4127993f 100644 --- a/test/java/org/apache/ivy/util/url/BasicURLHandlerTest.java +++ b/test/java/org/apache/ivy/util/url/BasicURLHandlerTest.java @@ -1,42 +1,42 @@ -/* - * 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.util.url; - -import java.io.File; -import java.net.URL; - -import junit.framework.TestCase; - -/** - * Test BasicURLHandler - */ -public class BasicURLHandlerTest extends TestCase { - // remote.test - public void testIsReachable() throws Exception { - URLHandler handler = new BasicURLHandler(); - assertTrue(handler.isReachable(new URL("http://www.google.fr/"))); - assertFalse(handler.isReachable(new URL("http://www.google.fr/unknownpage.html"))); - - assertTrue(handler.isReachable(new File("build.xml").toURL())); - assertFalse(handler.isReachable(new File("unknownfile.xml").toURL())); - - // to test ftp we should know of an anonymous ftp site... ! - // assertTrue(handler.isReachable(new URL("ftp://ftp.mozilla.org/pub/dir.sizes"))); - assertFalse(handler.isReachable(new URL("ftp://ftp.mozilla.org/unknown.file"))); - } -} +/* + * 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.util.url; + +import java.io.File; +import java.net.URL; + +import junit.framework.TestCase; + +/** + * Test BasicURLHandler + */ +public class BasicURLHandlerTest extends TestCase { + // remote.test + public void testIsReachable() throws Exception { + URLHandler handler = new BasicURLHandler(); + assertTrue(handler.isReachable(new URL("http://www.google.fr/"))); + assertFalse(handler.isReachable(new URL("http://www.google.fr/unknownpage.html"))); + + assertTrue(handler.isReachable(new File("build.xml").toURL())); + assertFalse(handler.isReachable(new File("unknownfile.xml").toURL())); + + // to test ftp we should know of an anonymous ftp site... ! + // assertTrue(handler.isReachable(new URL("ftp://ftp.mozilla.org/pub/dir.sizes"))); + assertFalse(handler.isReachable(new URL("ftp://ftp.mozilla.org/unknown.file"))); + } +} diff --git a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java b/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java index 09632403..4ba876d3 100644 --- a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java +++ b/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java @@ -1,34 +1,34 @@ -/* - * 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.util.url; - -import java.net.URL; - -import junit.framework.TestCase; - -/** - * Test HttpClientHandler - */ -public class HttpclientURLHandlerTest extends TestCase { - // remote.test - public void testIsReachable() throws Exception { - URLHandler handler = new HttpClientHandler(); - assertTrue(handler.isReachable(new URL("http://www.google.fr/"))); - assertFalse(handler.isReachable(new URL("http://www.google.fr/unknownpage.html"))); - } -} +/* + * 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.util.url; + +import java.net.URL; + +import junit.framework.TestCase; + +/** + * Test HttpClientHandler + */ +public class HttpclientURLHandlerTest extends TestCase { + // remote.test + public void testIsReachable() throws Exception { + URLHandler handler = new HttpClientHandler(); + assertTrue(handler.isReachable(new URL("http://www.google.fr/"))); + assertFalse(handler.isReachable(new URL("http://www.google.fr/unknownpage.html"))); + } +} diff --git a/test/java/org/apache/ivy/util/url/apache-dir-listing.html b/test/java/org/apache/ivy/util/url/apache-dir-listing.html index e06e9dd1..37480f73 100644 --- a/test/java/org/apache/ivy/util/url/apache-dir-listing.html +++ b/test/java/org/apache/ivy/util/url/apache-dir-listing.html @@ -1,37 +1,37 @@ - - - - - Index of /maven/ant - - -

      Index of /maven/ant

      -
            Name                    Last modified       Size  Description
      -
      -
      -[DIR] Parent Directory 13-Feb-2006 20:28 - -[DIR] distributions/ 09-Jul-2002 09:10 - -[DIR] jars/ 28-Feb-2006 16:03 - -[DIR] licenses/ 17-Jan-2004 18:10 - - -[DIR] poms/ 17-Jan-2004 18:10 - -

      -
      Apache/1.3.33 Server at www.ibiblio.org Port 80
      - + + + + + Index of /maven/ant + + +

      Index of /maven/ant

      +
            Name                    Last modified       Size  Description
      +
      +
      +[DIR] Parent Directory 13-Feb-2006 20:28 - +[DIR] distributions/ 09-Jul-2002 09:10 - +[DIR] jars/ 28-Feb-2006 16:03 - +[DIR] licenses/ 17-Jan-2004 18:10 - + +[DIR] poms/ 17-Jan-2004 18:10 - +

      +
      Apache/1.3.33 Server at www.ibiblio.org Port 80
      + diff --git a/test/java/org/apache/ivy/util/url/apache-file-listing.html b/test/java/org/apache/ivy/util/url/apache-file-listing.html index 52580762..95b89d6a 100644 --- a/test/java/org/apache/ivy/util/url/apache-file-listing.html +++ b/test/java/org/apache/ivy/util/url/apache-file-listing.html @@ -1,570 +1,570 @@ - - - - - Index of /maven/ant/jars - - -

      Index of /maven/ant/jars

      -
            Name                               Last modified       Size  Description
      -
      -
      -[DIR] Parent Directory 24-Jul-2006 11:17 - -[   ] ant-1.4.1.jar 17-Jan-2004 18:10 407k -[   ] ant-1.4.1.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-1.5.1.jar 17-Jan-2004 18:10 701k - -[   ] ant-1.5.1.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-1.5.2.jar 17-Jan-2004 18:10 715k -[   ] ant-1.5.2.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-1.5.3-1.jar 17-Jan-2004 18:10 721k -[   ] ant-1.5.3-1.jar.md5 17-Jan-2004 18:10 1k - -[   ] ant-1.5.4.jar 04-May-2004 08:17 720k -[   ] ant-1.5.4.jar.md5 04-May-2004 08:17 1k -[   ] ant-1.5.jar 17-Jan-2004 18:10 699k -[   ] ant-1.5.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-1.6.1.jar 04-May-2004 08:17 936k - -[   ] ant-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-1.6.2.jar 19-Jul-2004 11:19 977k -[   ] ant-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-1.6.3.jar 28-Apr-2005 12:28 1009k -[   ] ant-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-1.6.4.jar 19-May-2005 09:33 1010k -[   ] ant-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-1.6.5.jar 02-Jun-2005 09:57 1010k - -[   ] ant-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-1.6.jar 17-Jan-2004 18:10 930k -[   ] ant-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-antlr-1.6.1.jar 04-May-2004 08:17 6k - -[   ] ant-antlr-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-antlr-1.6.2.jar 19-Jul-2004 11:19 6k -[   ] ant-antlr-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-antlr-1.6.3.jar 28-Apr-2005 12:28 6k -[   ] ant-antlr-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-antlr-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-antlr-1.6.4.jar 19-May-2005 09:33 6k -[   ] ant-antlr-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-antlr-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-antlr-1.6.5.jar 02-Jun-2005 09:57 6k - -[   ] ant-antlr-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-antlr-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-antlr-1.6.jar 17-Jan-2004 18:10 6k -[   ] ant-antlr-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-apache-bcel-1.6.2.jar 19-Jul-2004 11:19 8k - -[   ] ant-apache-bcel-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-apache-bcel-1.6.3.jar 28-Apr-2005 12:28 8k -[   ] ant-apache-bcel-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-apache-bcel-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-apache-bcel-1.6.4.jar 19-May-2005 09:33 8k - -[   ] ant-apache-bcel-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-apache-bcel-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-apache-bcel-1.6.5.jar 02-Jun-2005 09:57 8k -[   ] ant-apache-bcel-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-apache-bcel-1.6.5.jar.sha1 02-Jun-2005 09:57 1k - -[   ] ant-apache-bsf-1.6.1.jar 04-May-2004 08:17 12k -[   ] ant-apache-bsf-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-apache-bsf-1.6.2.jar 19-Jul-2004 11:19 12k -[   ] ant-apache-bsf-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-apache-bsf-1.6.3.jar 28-Apr-2005 12:28 12k - -[   ] ant-apache-bsf-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-apache-bsf-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-apache-bsf-1.6.4.jar 19-May-2005 09:33 12k -[   ] ant-apache-bsf-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-apache-bsf-1.6.4.jar.sha1 19-May-2005 09:33 1k - -[   ] ant-apache-bsf-1.6.5.jar 02-Jun-2005 09:57 12k -[   ] ant-apache-bsf-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-apache-bsf-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-apache-bsf-1.6.jar 17-Jan-2004 18:10 12k -[   ] ant-apache-bsf-1.6.jar.md5 17-Jan-2004 18:10 1k - -[   ] ant-apache-log4j-1.6.2.jar 19-Jul-2004 11:19 3k -[   ] ant-apache-log4j-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-apache-log4j-1.6.3.jar 28-Apr-2005 12:28 3k -[   ] ant-apache-log4j-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-apache-log4j-1.6.3.jar.sha1 29-Apr-2005 06:47 1k - -[   ] ant-apache-log4j-1.6.4.jar 19-May-2005 09:33 3k -[   ] ant-apache-log4j-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-apache-log4j-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-apache-log4j-1.6.5.jar 02-Jun-2005 09:57 3k -[   ] ant-apache-log4j-1.6.5.jar.md5 02-Jun-2005 09:57 1k - -[   ] ant-apache-log4j-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-apache-oro-1.6.2.jar 19-Jul-2004 11:19 47k -[   ] ant-apache-oro-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-apache-oro-1.6.3.jar 28-Apr-2005 12:28 47k -[   ] ant-apache-oro-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-apache-oro-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-apache-oro-1.6.4.jar 19-May-2005 09:33 47k -[   ] ant-apache-oro-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-apache-oro-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-apache-oro-1.6.5.jar 02-Jun-2005 09:57 47k - -[   ] ant-apache-oro-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-apache-oro-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-apache-regexp-1.6.2.jar 19-Jul-2004 11:19 4k -[   ] ant-apache-regexp-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-apache-regexp-1.6.3.jar 28-Apr-2005 12:28 4k - -[   ] ant-apache-regexp-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-apache-regexp-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-apache-regexp-1.6.4.jar 19-May-2005 09:33 4k -[   ] ant-apache-regexp-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-apache-regexp-1.6.4.jar.sha1 19-May-2005 09:33 1k - -[   ] ant-apache-regexp-1.6.5.jar 02-Jun-2005 09:57 4k -[   ] ant-apache-regexp-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-apache-regexp-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-apache-resolver-1.6.1.jar 04-May-2004 08:17 4k -[   ] ant-apache-resolver-1.6.1.jar.md5 04-May-2004 08:17 1k - -[   ] ant-apache-resolver-1.6.2.jar 19-Jul-2004 11:19 4k -[   ] ant-apache-resolver-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-apache-resolver-1.6.3.jar 28-Apr-2005 12:28 4k -[   ] ant-apache-resolver-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-apache-resolver-1.6.3.jar.sha1 29-Apr-2005 06:47 1k - -[   ] ant-apache-resolver-1.6.4.jar 19-May-2005 09:33 4k -[   ] ant-apache-resolver-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-apache-resolver-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-apache-resolver-1.6.5.jar 02-Jun-2005 09:57 4k -[   ] ant-apache-resolver-1.6.5.jar.md5 02-Jun-2005 09:57 1k - -[   ] ant-apache-resolver-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-apache-resolver-1.6.jar 17-Jan-2004 18:10 4k -[   ] ant-apache-resolver-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-commons-logging-1.6.1.jar 04-May-2004 08:17 4k -[   ] ant-commons-logging-1.6.1.jar.md5 04-May-2004 08:17 1k - -[   ] ant-commons-logging-1.6.2.jar 19-Jul-2004 11:19 4k -[   ] ant-commons-logging-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-commons-logging-1.6.3.jar 28-Apr-2005 12:28 4k -[   ] ant-commons-logging-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-commons-logging-1.6.3.jar.sha1 29-Apr-2005 06:47 1k - -[   ] ant-commons-logging-1.6.4.jar 19-May-2005 09:33 4k -[   ] ant-commons-logging-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-commons-logging-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-commons-logging-1.6.5.jar 02-Jun-2005 09:57 4k -[   ] ant-commons-logging-1.6.5.jar.md5 02-Jun-2005 09:57 1k - -[   ] ant-commons-logging-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-commons-logging-1.6.jar 17-Jan-2004 18:10 4k -[   ] ant-commons-logging-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-commons-net-1.6.1.jar 04-May-2004 08:17 34k -[   ] ant-commons-net-1.6.1.jar.md5 04-May-2004 08:17 1k - -[   ] ant-commons-net-1.6.2.jar 19-Jul-2004 11:19 34k -[   ] ant-commons-net-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-commons-net-1.6.3.jar 28-Apr-2005 12:28 34k -[   ] ant-commons-net-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-commons-net-1.6.3.jar.sha1 29-Apr-2005 06:47 1k - -[   ] ant-commons-net-1.6.4.jar 19-May-2005 09:33 34k -[   ] ant-commons-net-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-commons-net-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-commons-net-1.6.5.jar 02-Jun-2005 09:57 34k -[   ] ant-commons-net-1.6.5.jar.md5 02-Jun-2005 09:57 1k - -[   ] ant-commons-net-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-commons-net-1.6.jar 17-Jan-2004 18:10 34k -[   ] ant-commons-net-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-icontract-1.6.1.jar 04-May-2004 08:17 9k -[   ] ant-icontract-1.6.1.jar.md5 04-May-2004 08:17 1k - -[   ] ant-icontract-1.6.2.jar 19-Jul-2004 11:19 9k -[   ] ant-icontract-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-icontract-1.6.3.jar 28-Apr-2005 12:28 9k -[   ] ant-icontract-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-icontract-1.6.3.jar.sha1 29-Apr-2005 06:47 1k - -[   ] ant-icontract-1.6.4.jar 19-May-2005 09:33 9k -[   ] ant-icontract-1.6.4.jar.md5 19-May-2005 09:33 1k -[   ] ant-icontract-1.6.4.jar.sha1 19-May-2005 09:33 1k -[   ] ant-icontract-1.6.5.jar 02-Jun-2005 09:57 9k -[   ] ant-icontract-1.6.5.jar.md5 02-Jun-2005 09:57 1k - -[   ] ant-icontract-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-icontract-1.6.jar 17-Jan-2004 18:10 9k -[   ] ant-icontract-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-jai-1.6.1.jar 04-May-2004 08:17 21k -[   ] ant-jai-1.6.1.jar.md5 04-May-2004 08:17 1k - -[   ] ant-jai-1.6.2.jar 19-Jul-2004 11:19 21k -[   ] ant-jai-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-jai-1.6.3.jar 28-Apr-2005 12:28 21k -[   ] ant-jai-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-jai-1.6.3.jar.sha1 29-Apr-2005 06:47 1k - -[   ] ant-jai-1.6.4.jar 19-May-2005 09:34 21k -[   ] ant-jai-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-jai-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-jai-1.6.5.jar 02-Jun-2005 09:57 21k -[   ] ant-jai-1.6.5.jar.md5 02-Jun-2005 09:57 1k - -[   ] ant-jai-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-jai-1.6.jar 17-Jan-2004 18:10 21k -[   ] ant-jai-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-jakarta-bcel-1.6.1.jar 04-May-2004 08:17 8k -[   ] ant-jakarta-bcel-1.6.1.jar.md5 04-May-2004 08:17 1k - -[   ] ant-jakarta-bcel-1.6.jar 17-Jan-2004 18:10 8k -[   ] ant-jakarta-bcel-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-jakarta-log4j-1.6.1.jar 04-May-2004 08:17 3k -[   ] ant-jakarta-log4j-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-jakarta-log4j-1.6.jar 17-Jan-2004 18:10 3k - -[   ] ant-jakarta-log4j-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-jakarta-oro-1.6.1.jar 04-May-2004 08:17 47k -[   ] ant-jakarta-oro-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-jakarta-oro-1.6.jar 17-Jan-2004 18:10 47k -[   ] ant-jakarta-oro-1.6.jar.md5 17-Jan-2004 18:10 1k - -[   ] ant-jakarta-regexp-1.6.1.jar 04-May-2004 08:17 4k -[   ] ant-jakarta-regexp-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-jakarta-regexp-1.6.jar 17-Jan-2004 18:10 4k -[   ] ant-jakarta-regexp-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-javamail-1.6.1.jar 04-May-2004 08:17 7k - -[   ] ant-javamail-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-javamail-1.6.2.jar 19-Jul-2004 11:19 7k -[   ] ant-javamail-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-javamail-1.6.3.jar 28-Apr-2005 12:28 7k -[   ] ant-javamail-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-javamail-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-javamail-1.6.4.jar 19-May-2005 09:34 7k -[   ] ant-javamail-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-javamail-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-javamail-1.6.5.jar 02-Jun-2005 09:57 7k - -[   ] ant-javamail-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-javamail-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-javamail-1.6.jar 17-Jan-2004 18:10 7k -[   ] ant-javamail-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-jdepend-1.6.1.jar 04-May-2004 08:17 8k - -[   ] ant-jdepend-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-jdepend-1.6.2.jar 19-Jul-2004 11:19 8k -[   ] ant-jdepend-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-jdepend-1.6.3.jar 28-Apr-2005 12:28 8k -[   ] ant-jdepend-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-jdepend-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-jdepend-1.6.4.jar 19-May-2005 09:34 8k -[   ] ant-jdepend-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-jdepend-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-jdepend-1.6.5.jar 02-Jun-2005 09:57 8k - -[   ] ant-jdepend-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-jdepend-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-jdepend-1.6.jar 17-Jan-2004 18:10 8k -[   ] ant-jdepend-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-jmf-1.6.1.jar 04-May-2004 08:17 6k - -[   ] ant-jmf-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-jmf-1.6.2.jar 19-Jul-2004 11:19 6k -[   ] ant-jmf-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-jmf-1.6.3.jar 28-Apr-2005 12:28 6k -[   ] ant-jmf-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-jmf-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-jmf-1.6.4.jar 19-May-2005 09:34 6k -[   ] ant-jmf-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-jmf-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-jmf-1.6.5.jar 02-Jun-2005 09:57 6k - -[   ] ant-jmf-1.6.5.jar.md5 02-Jun-2005 09:57 1k -[   ] ant-jmf-1.6.5.jar.sha1 02-Jun-2005 09:57 1k -[   ] ant-jmf-1.6.jar 17-Jan-2004 18:10 6k -[   ] ant-jmf-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-jsch-1.6.1.jar 04-May-2004 08:17 21k - -[   ] ant-jsch-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-jsch-1.6.2.jar 19-Jul-2004 11:19 22k -[   ] ant-jsch-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-jsch-1.6.3.jar 28-Apr-2005 12:28 22k -[   ] ant-jsch-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-jsch-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-jsch-1.6.4.jar 19-May-2005 09:34 22k -[   ] ant-jsch-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-jsch-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-jsch-1.6.5.jar 02-Jun-2005 09:58 22k - -[   ] ant-jsch-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-jsch-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-jsch-1.6.jar 17-Jan-2004 18:10 21k -[   ] ant-jsch-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-junit-1.6.1.jar 04-May-2004 08:17 66k - -[   ] ant-junit-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-junit-1.6.2.jar 19-Jul-2004 11:19 72k -[   ] ant-junit-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-junit-1.6.3.jar 28-Apr-2005 12:28 72k -[   ] ant-junit-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-junit-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-junit-1.6.4.jar 19-May-2005 09:34 72k -[   ] ant-junit-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-junit-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-junit-1.6.5.jar 02-Jun-2005 09:58 72k - -[   ] ant-junit-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-junit-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-junit-1.6.jar 17-Jan-2004 18:10 67k -[   ] ant-junit-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-launcher-1.6.1.jar 04-May-2004 08:17 8k - -[   ] ant-launcher-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-launcher-1.6.2.jar 19-Jul-2004 11:19 8k -[   ] ant-launcher-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-launcher-1.6.3.jar 28-Apr-2005 12:28 9k -[   ] ant-launcher-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-launcher-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-launcher-1.6.4.jar 19-May-2005 09:34 9k -[   ] ant-launcher-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-launcher-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-launcher-1.6.5.jar 02-Jun-2005 09:58 9k - -[   ] ant-launcher-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-launcher-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-launcher-1.6.jar 17-Jan-2004 18:10 8k -[   ] ant-launcher-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-netrexx-1.6.1.jar 04-May-2004 08:17 10k - -[   ] ant-netrexx-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-netrexx-1.6.2.jar 19-Jul-2004 11:19 10k -[   ] ant-netrexx-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-netrexx-1.6.3.jar 28-Apr-2005 12:28 10k -[   ] ant-netrexx-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-netrexx-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-netrexx-1.6.4.jar 19-May-2005 09:34 10k -[   ] ant-netrexx-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-netrexx-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-netrexx-1.6.5.jar 02-Jun-2005 09:58 10k - -[   ] ant-netrexx-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-netrexx-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-netrexx-1.6.jar 17-Jan-2004 18:10 10k -[   ] ant-netrexx-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-nodeps-1.6.1.jar 04-May-2004 08:17 397k - -[   ] ant-nodeps-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-nodeps-1.6.2.jar 19-Jul-2004 11:19 398k -[   ] ant-nodeps-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-nodeps-1.6.3.jar 28-Apr-2005 12:28 411k -[   ] ant-nodeps-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-nodeps-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-nodeps-1.6.4.jar 19-May-2005 09:34 411k -[   ] ant-nodeps-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-nodeps-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-nodeps-1.6.5.jar 02-Jun-2005 09:58 411k - -[   ] ant-nodeps-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-nodeps-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-nodeps-1.6.jar 17-Jan-2004 18:10 386k -[   ] ant-nodeps-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-optional-1.4.1.jar 17-Jan-2004 18:10 458k - -[   ] ant-optional-1.4.1.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-optional-1.5.1.jar 17-Jan-2004 18:10 639k -[   ] ant-optional-1.5.1.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-optional-1.5.2.jar 17-Jan-2004 18:10 653k -[   ] ant-optional-1.5.2.jar.md5 17-Jan-2004 18:10 1k - -[   ] ant-optional-1.5.3-1.jar 17-Jan-2004 18:10 656k -[   ] ant-optional-1.5.3-1.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-optional-1.5.jar 17-Jan-2004 18:10 638k -[   ] ant-optional-1.5.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-starteam-1.6.1.jar 04-May-2004 08:17 35k - -[   ] ant-starteam-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-starteam-1.6.2.jar 19-Jul-2004 11:19 35k -[   ] ant-starteam-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-starteam-1.6.3.jar 28-Apr-2005 12:28 35k -[   ] ant-starteam-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-starteam-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-starteam-1.6.4.jar 19-May-2005 09:34 35k -[   ] ant-starteam-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-starteam-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-starteam-1.6.5.jar 02-Jun-2005 09:58 35k - -[   ] ant-starteam-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-starteam-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-starteam-1.6.jar 17-Jan-2004 18:10 35k -[   ] ant-starteam-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-stylebook-1.6.1.jar 04-May-2004 08:17 2k - -[   ] ant-stylebook-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-stylebook-1.6.2.jar 19-Jul-2004 11:19 2k -[   ] ant-stylebook-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-stylebook-1.6.3.jar 28-Apr-2005 12:28 2k -[   ] ant-stylebook-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-stylebook-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-stylebook-1.6.4.jar 19-May-2005 09:34 2k -[   ] ant-stylebook-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-stylebook-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-stylebook-1.6.5.jar 02-Jun-2005 09:58 2k - -[   ] ant-stylebook-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-stylebook-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-stylebook-1.6.jar 17-Jan-2004 18:10 2k -[   ] ant-stylebook-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-swing-1.6.1.jar 04-May-2004 08:17 7k - -[   ] ant-swing-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-swing-1.6.2.jar 19-Jul-2004 11:19 7k -[   ] ant-swing-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-swing-1.6.3.jar 28-Apr-2005 12:28 7k -[   ] ant-swing-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-swing-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-swing-1.6.4.jar 19-May-2005 09:34 7k -[   ] ant-swing-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-swing-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-swing-1.6.5.jar 02-Jun-2005 09:58 7k - -[   ] ant-swing-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-swing-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-swing-1.6.jar 17-Jan-2004 18:10 6k -[   ] ant-swing-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-trax-1.6.1.jar 04-May-2004 08:17 65k - -[   ] ant-trax-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-trax-1.6.2.jar 19-Jul-2004 11:19 67k -[   ] ant-trax-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-trax-1.6.3.jar 28-Apr-2005 12:28 67k -[   ] ant-trax-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-trax-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-trax-1.6.4.jar 19-May-2005 09:34 67k -[   ] ant-trax-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-trax-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-trax-1.6.5.jar 02-Jun-2005 09:58 67k - -[   ] ant-trax-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-trax-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-trax-1.6.jar 17-Jan-2004 18:10 66k -[   ] ant-trax-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-vaj-1.6.1.jar 04-May-2004 08:17 47k - -[   ] ant-vaj-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-vaj-1.6.2.jar 19-Jul-2004 11:19 47k -[   ] ant-vaj-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-vaj-1.6.3.jar 28-Apr-2005 12:28 49k -[   ] ant-vaj-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-vaj-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-vaj-1.6.4.jar 19-May-2005 09:34 49k -[   ] ant-vaj-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-vaj-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-vaj-1.6.5.jar 02-Jun-2005 09:58 49k - -[   ] ant-vaj-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-vaj-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-vaj-1.6.jar 17-Jan-2004 18:10 47k -[   ] ant-vaj-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-weblogic-1.6.1.jar 04-May-2004 08:17 14k - -[   ] ant-weblogic-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-weblogic-1.6.2.jar 19-Jul-2004 11:19 14k -[   ] ant-weblogic-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-weblogic-1.6.3.jar 28-Apr-2005 12:28 14k -[   ] ant-weblogic-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-weblogic-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-weblogic-1.6.4.jar 19-May-2005 09:34 14k -[   ] ant-weblogic-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-weblogic-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-weblogic-1.6.5.jar 02-Jun-2005 09:58 14k - -[   ] ant-weblogic-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-weblogic-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-weblogic-1.6.jar 17-Jan-2004 18:10 14k -[   ] ant-weblogic-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-xalan1-1.6.1.jar 04-May-2004 08:17 4k - -[   ] ant-xalan1-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-xalan1-1.6.2.jar 19-Jul-2004 11:19 4k -[   ] ant-xalan1-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-xalan1-1.6.3.jar 28-Apr-2005 12:28 4k -[   ] ant-xalan1-1.6.3.jar.md5 28-Apr-2005 12:28 1k - -[   ] ant-xalan1-1.6.3.jar.sha1 29-Apr-2005 06:47 1k -[   ] ant-xalan1-1.6.4.jar 19-May-2005 09:34 4k -[   ] ant-xalan1-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-xalan1-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-xalan1-1.6.5.jar 02-Jun-2005 09:58 4k - -[   ] ant-xalan1-1.6.5.jar.md5 02-Jun-2005 09:58 1k -[   ] ant-xalan1-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-xalan1-1.6.jar 17-Jan-2004 18:10 4k -[   ] ant-xalan1-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-xalan2-1.6.1.jar 04-May-2004 08:17 2k - -[   ] ant-xalan2-1.6.1.jar.md5 04-May-2004 08:17 1k -[   ] ant-xalan2-1.6.jar 17-Jan-2004 18:10 2k -[   ] ant-xalan2-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] ant-xslp-1.6.1.jar 04-May-2004 08:17 2k -[   ] ant-xslp-1.6.1.jar.md5 04-May-2004 08:17 1k - -[   ] ant-xslp-1.6.2.jar 19-Jul-2004 11:19 2k -[   ] ant-xslp-1.6.2.jar.md5 19-Jul-2004 11:19 1k -[   ] ant-xslp-1.6.3.jar 28-Apr-2005 12:28 2k -[   ] ant-xslp-1.6.3.jar.md5 28-Apr-2005 12:28 1k -[   ] ant-xslp-1.6.3.jar.sha1 29-Apr-2005 06:47 1k - -[   ] ant-xslp-1.6.4.jar 19-May-2005 09:34 2k -[   ] ant-xslp-1.6.4.jar.md5 19-May-2005 09:34 1k -[   ] ant-xslp-1.6.4.jar.sha1 19-May-2005 09:34 1k -[   ] ant-xslp-1.6.5.jar 02-Jun-2005 09:58 2k -[   ] ant-xslp-1.6.5.jar.md5 02-Jun-2005 09:58 1k - -[   ] ant-xslp-1.6.5.jar.sha1 02-Jun-2005 09:58 1k -[   ] ant-xslp-1.6.jar 17-Jan-2004 18:10 2k -[   ] ant-xslp-1.6.jar.md5 17-Jan-2004 18:10 1k -[   ] optional-1.5.4.jar 04-May-2004 08:17 657k -[   ] optional-1.5.4.jar.md5 04-May-2004 08:17 1k - -

      -
      Apache/1.3.33 Server at www.ibiblio.org Port 80
      - + + + + + Index of /maven/ant/jars + + +

      Index of /maven/ant/jars

      +
            Name                               Last modified       Size  Description
      +
      +
      +[DIR] Parent Directory 24-Jul-2006 11:17 - +[   ] ant-1.4.1.jar 17-Jan-2004 18:10 407k +[   ] ant-1.4.1.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-1.5.1.jar 17-Jan-2004 18:10 701k + +[   ] ant-1.5.1.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-1.5.2.jar 17-Jan-2004 18:10 715k +[   ] ant-1.5.2.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-1.5.3-1.jar 17-Jan-2004 18:10 721k +[   ] ant-1.5.3-1.jar.md5 17-Jan-2004 18:10 1k + +[   ] ant-1.5.4.jar 04-May-2004 08:17 720k +[   ] ant-1.5.4.jar.md5 04-May-2004 08:17 1k +[   ] ant-1.5.jar 17-Jan-2004 18:10 699k +[   ] ant-1.5.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-1.6.1.jar 04-May-2004 08:17 936k + +[   ] ant-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-1.6.2.jar 19-Jul-2004 11:19 977k +[   ] ant-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-1.6.3.jar 28-Apr-2005 12:28 1009k +[   ] ant-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-1.6.4.jar 19-May-2005 09:33 1010k +[   ] ant-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-1.6.5.jar 02-Jun-2005 09:57 1010k + +[   ] ant-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-1.6.jar 17-Jan-2004 18:10 930k +[   ] ant-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-antlr-1.6.1.jar 04-May-2004 08:17 6k + +[   ] ant-antlr-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-antlr-1.6.2.jar 19-Jul-2004 11:19 6k +[   ] ant-antlr-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-antlr-1.6.3.jar 28-Apr-2005 12:28 6k +[   ] ant-antlr-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-antlr-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-antlr-1.6.4.jar 19-May-2005 09:33 6k +[   ] ant-antlr-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-antlr-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-antlr-1.6.5.jar 02-Jun-2005 09:57 6k + +[   ] ant-antlr-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-antlr-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-antlr-1.6.jar 17-Jan-2004 18:10 6k +[   ] ant-antlr-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-apache-bcel-1.6.2.jar 19-Jul-2004 11:19 8k + +[   ] ant-apache-bcel-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-apache-bcel-1.6.3.jar 28-Apr-2005 12:28 8k +[   ] ant-apache-bcel-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-apache-bcel-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-apache-bcel-1.6.4.jar 19-May-2005 09:33 8k + +[   ] ant-apache-bcel-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-apache-bcel-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-apache-bcel-1.6.5.jar 02-Jun-2005 09:57 8k +[   ] ant-apache-bcel-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-apache-bcel-1.6.5.jar.sha1 02-Jun-2005 09:57 1k + +[   ] ant-apache-bsf-1.6.1.jar 04-May-2004 08:17 12k +[   ] ant-apache-bsf-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-apache-bsf-1.6.2.jar 19-Jul-2004 11:19 12k +[   ] ant-apache-bsf-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-apache-bsf-1.6.3.jar 28-Apr-2005 12:28 12k + +[   ] ant-apache-bsf-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-apache-bsf-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-apache-bsf-1.6.4.jar 19-May-2005 09:33 12k +[   ] ant-apache-bsf-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-apache-bsf-1.6.4.jar.sha1 19-May-2005 09:33 1k + +[   ] ant-apache-bsf-1.6.5.jar 02-Jun-2005 09:57 12k +[   ] ant-apache-bsf-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-apache-bsf-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-apache-bsf-1.6.jar 17-Jan-2004 18:10 12k +[   ] ant-apache-bsf-1.6.jar.md5 17-Jan-2004 18:10 1k + +[   ] ant-apache-log4j-1.6.2.jar 19-Jul-2004 11:19 3k +[   ] ant-apache-log4j-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-apache-log4j-1.6.3.jar 28-Apr-2005 12:28 3k +[   ] ant-apache-log4j-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-apache-log4j-1.6.3.jar.sha1 29-Apr-2005 06:47 1k + +[   ] ant-apache-log4j-1.6.4.jar 19-May-2005 09:33 3k +[   ] ant-apache-log4j-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-apache-log4j-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-apache-log4j-1.6.5.jar 02-Jun-2005 09:57 3k +[   ] ant-apache-log4j-1.6.5.jar.md5 02-Jun-2005 09:57 1k + +[   ] ant-apache-log4j-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-apache-oro-1.6.2.jar 19-Jul-2004 11:19 47k +[   ] ant-apache-oro-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-apache-oro-1.6.3.jar 28-Apr-2005 12:28 47k +[   ] ant-apache-oro-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-apache-oro-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-apache-oro-1.6.4.jar 19-May-2005 09:33 47k +[   ] ant-apache-oro-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-apache-oro-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-apache-oro-1.6.5.jar 02-Jun-2005 09:57 47k + +[   ] ant-apache-oro-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-apache-oro-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-apache-regexp-1.6.2.jar 19-Jul-2004 11:19 4k +[   ] ant-apache-regexp-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-apache-regexp-1.6.3.jar 28-Apr-2005 12:28 4k + +[   ] ant-apache-regexp-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-apache-regexp-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-apache-regexp-1.6.4.jar 19-May-2005 09:33 4k +[   ] ant-apache-regexp-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-apache-regexp-1.6.4.jar.sha1 19-May-2005 09:33 1k + +[   ] ant-apache-regexp-1.6.5.jar 02-Jun-2005 09:57 4k +[   ] ant-apache-regexp-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-apache-regexp-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-apache-resolver-1.6.1.jar 04-May-2004 08:17 4k +[   ] ant-apache-resolver-1.6.1.jar.md5 04-May-2004 08:17 1k + +[   ] ant-apache-resolver-1.6.2.jar 19-Jul-2004 11:19 4k +[   ] ant-apache-resolver-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-apache-resolver-1.6.3.jar 28-Apr-2005 12:28 4k +[   ] ant-apache-resolver-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-apache-resolver-1.6.3.jar.sha1 29-Apr-2005 06:47 1k + +[   ] ant-apache-resolver-1.6.4.jar 19-May-2005 09:33 4k +[   ] ant-apache-resolver-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-apache-resolver-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-apache-resolver-1.6.5.jar 02-Jun-2005 09:57 4k +[   ] ant-apache-resolver-1.6.5.jar.md5 02-Jun-2005 09:57 1k + +[   ] ant-apache-resolver-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-apache-resolver-1.6.jar 17-Jan-2004 18:10 4k +[   ] ant-apache-resolver-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-commons-logging-1.6.1.jar 04-May-2004 08:17 4k +[   ] ant-commons-logging-1.6.1.jar.md5 04-May-2004 08:17 1k + +[   ] ant-commons-logging-1.6.2.jar 19-Jul-2004 11:19 4k +[   ] ant-commons-logging-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-commons-logging-1.6.3.jar 28-Apr-2005 12:28 4k +[   ] ant-commons-logging-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-commons-logging-1.6.3.jar.sha1 29-Apr-2005 06:47 1k + +[   ] ant-commons-logging-1.6.4.jar 19-May-2005 09:33 4k +[   ] ant-commons-logging-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-commons-logging-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-commons-logging-1.6.5.jar 02-Jun-2005 09:57 4k +[   ] ant-commons-logging-1.6.5.jar.md5 02-Jun-2005 09:57 1k + +[   ] ant-commons-logging-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-commons-logging-1.6.jar 17-Jan-2004 18:10 4k +[   ] ant-commons-logging-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-commons-net-1.6.1.jar 04-May-2004 08:17 34k +[   ] ant-commons-net-1.6.1.jar.md5 04-May-2004 08:17 1k + +[   ] ant-commons-net-1.6.2.jar 19-Jul-2004 11:19 34k +[   ] ant-commons-net-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-commons-net-1.6.3.jar 28-Apr-2005 12:28 34k +[   ] ant-commons-net-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-commons-net-1.6.3.jar.sha1 29-Apr-2005 06:47 1k + +[   ] ant-commons-net-1.6.4.jar 19-May-2005 09:33 34k +[   ] ant-commons-net-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-commons-net-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-commons-net-1.6.5.jar 02-Jun-2005 09:57 34k +[   ] ant-commons-net-1.6.5.jar.md5 02-Jun-2005 09:57 1k + +[   ] ant-commons-net-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-commons-net-1.6.jar 17-Jan-2004 18:10 34k +[   ] ant-commons-net-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-icontract-1.6.1.jar 04-May-2004 08:17 9k +[   ] ant-icontract-1.6.1.jar.md5 04-May-2004 08:17 1k + +[   ] ant-icontract-1.6.2.jar 19-Jul-2004 11:19 9k +[   ] ant-icontract-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-icontract-1.6.3.jar 28-Apr-2005 12:28 9k +[   ] ant-icontract-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-icontract-1.6.3.jar.sha1 29-Apr-2005 06:47 1k + +[   ] ant-icontract-1.6.4.jar 19-May-2005 09:33 9k +[   ] ant-icontract-1.6.4.jar.md5 19-May-2005 09:33 1k +[   ] ant-icontract-1.6.4.jar.sha1 19-May-2005 09:33 1k +[   ] ant-icontract-1.6.5.jar 02-Jun-2005 09:57 9k +[   ] ant-icontract-1.6.5.jar.md5 02-Jun-2005 09:57 1k + +[   ] ant-icontract-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-icontract-1.6.jar 17-Jan-2004 18:10 9k +[   ] ant-icontract-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-jai-1.6.1.jar 04-May-2004 08:17 21k +[   ] ant-jai-1.6.1.jar.md5 04-May-2004 08:17 1k + +[   ] ant-jai-1.6.2.jar 19-Jul-2004 11:19 21k +[   ] ant-jai-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-jai-1.6.3.jar 28-Apr-2005 12:28 21k +[   ] ant-jai-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-jai-1.6.3.jar.sha1 29-Apr-2005 06:47 1k + +[   ] ant-jai-1.6.4.jar 19-May-2005 09:34 21k +[   ] ant-jai-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-jai-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-jai-1.6.5.jar 02-Jun-2005 09:57 21k +[   ] ant-jai-1.6.5.jar.md5 02-Jun-2005 09:57 1k + +[   ] ant-jai-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-jai-1.6.jar 17-Jan-2004 18:10 21k +[   ] ant-jai-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-jakarta-bcel-1.6.1.jar 04-May-2004 08:17 8k +[   ] ant-jakarta-bcel-1.6.1.jar.md5 04-May-2004 08:17 1k + +[   ] ant-jakarta-bcel-1.6.jar 17-Jan-2004 18:10 8k +[   ] ant-jakarta-bcel-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-jakarta-log4j-1.6.1.jar 04-May-2004 08:17 3k +[   ] ant-jakarta-log4j-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-jakarta-log4j-1.6.jar 17-Jan-2004 18:10 3k + +[   ] ant-jakarta-log4j-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-jakarta-oro-1.6.1.jar 04-May-2004 08:17 47k +[   ] ant-jakarta-oro-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-jakarta-oro-1.6.jar 17-Jan-2004 18:10 47k +[   ] ant-jakarta-oro-1.6.jar.md5 17-Jan-2004 18:10 1k + +[   ] ant-jakarta-regexp-1.6.1.jar 04-May-2004 08:17 4k +[   ] ant-jakarta-regexp-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-jakarta-regexp-1.6.jar 17-Jan-2004 18:10 4k +[   ] ant-jakarta-regexp-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-javamail-1.6.1.jar 04-May-2004 08:17 7k + +[   ] ant-javamail-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-javamail-1.6.2.jar 19-Jul-2004 11:19 7k +[   ] ant-javamail-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-javamail-1.6.3.jar 28-Apr-2005 12:28 7k +[   ] ant-javamail-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-javamail-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-javamail-1.6.4.jar 19-May-2005 09:34 7k +[   ] ant-javamail-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-javamail-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-javamail-1.6.5.jar 02-Jun-2005 09:57 7k + +[   ] ant-javamail-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-javamail-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-javamail-1.6.jar 17-Jan-2004 18:10 7k +[   ] ant-javamail-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-jdepend-1.6.1.jar 04-May-2004 08:17 8k + +[   ] ant-jdepend-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-jdepend-1.6.2.jar 19-Jul-2004 11:19 8k +[   ] ant-jdepend-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-jdepend-1.6.3.jar 28-Apr-2005 12:28 8k +[   ] ant-jdepend-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-jdepend-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-jdepend-1.6.4.jar 19-May-2005 09:34 8k +[   ] ant-jdepend-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-jdepend-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-jdepend-1.6.5.jar 02-Jun-2005 09:57 8k + +[   ] ant-jdepend-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-jdepend-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-jdepend-1.6.jar 17-Jan-2004 18:10 8k +[   ] ant-jdepend-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-jmf-1.6.1.jar 04-May-2004 08:17 6k + +[   ] ant-jmf-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-jmf-1.6.2.jar 19-Jul-2004 11:19 6k +[   ] ant-jmf-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-jmf-1.6.3.jar 28-Apr-2005 12:28 6k +[   ] ant-jmf-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-jmf-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-jmf-1.6.4.jar 19-May-2005 09:34 6k +[   ] ant-jmf-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-jmf-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-jmf-1.6.5.jar 02-Jun-2005 09:57 6k + +[   ] ant-jmf-1.6.5.jar.md5 02-Jun-2005 09:57 1k +[   ] ant-jmf-1.6.5.jar.sha1 02-Jun-2005 09:57 1k +[   ] ant-jmf-1.6.jar 17-Jan-2004 18:10 6k +[   ] ant-jmf-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-jsch-1.6.1.jar 04-May-2004 08:17 21k + +[   ] ant-jsch-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-jsch-1.6.2.jar 19-Jul-2004 11:19 22k +[   ] ant-jsch-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-jsch-1.6.3.jar 28-Apr-2005 12:28 22k +[   ] ant-jsch-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-jsch-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-jsch-1.6.4.jar 19-May-2005 09:34 22k +[   ] ant-jsch-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-jsch-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-jsch-1.6.5.jar 02-Jun-2005 09:58 22k + +[   ] ant-jsch-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-jsch-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-jsch-1.6.jar 17-Jan-2004 18:10 21k +[   ] ant-jsch-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-junit-1.6.1.jar 04-May-2004 08:17 66k + +[   ] ant-junit-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-junit-1.6.2.jar 19-Jul-2004 11:19 72k +[   ] ant-junit-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-junit-1.6.3.jar 28-Apr-2005 12:28 72k +[   ] ant-junit-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-junit-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-junit-1.6.4.jar 19-May-2005 09:34 72k +[   ] ant-junit-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-junit-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-junit-1.6.5.jar 02-Jun-2005 09:58 72k + +[   ] ant-junit-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-junit-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-junit-1.6.jar 17-Jan-2004 18:10 67k +[   ] ant-junit-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-launcher-1.6.1.jar 04-May-2004 08:17 8k + +[   ] ant-launcher-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-launcher-1.6.2.jar 19-Jul-2004 11:19 8k +[   ] ant-launcher-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-launcher-1.6.3.jar 28-Apr-2005 12:28 9k +[   ] ant-launcher-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-launcher-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-launcher-1.6.4.jar 19-May-2005 09:34 9k +[   ] ant-launcher-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-launcher-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-launcher-1.6.5.jar 02-Jun-2005 09:58 9k + +[   ] ant-launcher-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-launcher-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-launcher-1.6.jar 17-Jan-2004 18:10 8k +[   ] ant-launcher-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-netrexx-1.6.1.jar 04-May-2004 08:17 10k + +[   ] ant-netrexx-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-netrexx-1.6.2.jar 19-Jul-2004 11:19 10k +[   ] ant-netrexx-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-netrexx-1.6.3.jar 28-Apr-2005 12:28 10k +[   ] ant-netrexx-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-netrexx-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-netrexx-1.6.4.jar 19-May-2005 09:34 10k +[   ] ant-netrexx-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-netrexx-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-netrexx-1.6.5.jar 02-Jun-2005 09:58 10k + +[   ] ant-netrexx-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-netrexx-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-netrexx-1.6.jar 17-Jan-2004 18:10 10k +[   ] ant-netrexx-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-nodeps-1.6.1.jar 04-May-2004 08:17 397k + +[   ] ant-nodeps-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-nodeps-1.6.2.jar 19-Jul-2004 11:19 398k +[   ] ant-nodeps-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-nodeps-1.6.3.jar 28-Apr-2005 12:28 411k +[   ] ant-nodeps-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-nodeps-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-nodeps-1.6.4.jar 19-May-2005 09:34 411k +[   ] ant-nodeps-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-nodeps-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-nodeps-1.6.5.jar 02-Jun-2005 09:58 411k + +[   ] ant-nodeps-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-nodeps-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-nodeps-1.6.jar 17-Jan-2004 18:10 386k +[   ] ant-nodeps-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-optional-1.4.1.jar 17-Jan-2004 18:10 458k + +[   ] ant-optional-1.4.1.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-optional-1.5.1.jar 17-Jan-2004 18:10 639k +[   ] ant-optional-1.5.1.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-optional-1.5.2.jar 17-Jan-2004 18:10 653k +[   ] ant-optional-1.5.2.jar.md5 17-Jan-2004 18:10 1k + +[   ] ant-optional-1.5.3-1.jar 17-Jan-2004 18:10 656k +[   ] ant-optional-1.5.3-1.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-optional-1.5.jar 17-Jan-2004 18:10 638k +[   ] ant-optional-1.5.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-starteam-1.6.1.jar 04-May-2004 08:17 35k + +[   ] ant-starteam-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-starteam-1.6.2.jar 19-Jul-2004 11:19 35k +[   ] ant-starteam-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-starteam-1.6.3.jar 28-Apr-2005 12:28 35k +[   ] ant-starteam-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-starteam-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-starteam-1.6.4.jar 19-May-2005 09:34 35k +[   ] ant-starteam-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-starteam-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-starteam-1.6.5.jar 02-Jun-2005 09:58 35k + +[   ] ant-starteam-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-starteam-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-starteam-1.6.jar 17-Jan-2004 18:10 35k +[   ] ant-starteam-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-stylebook-1.6.1.jar 04-May-2004 08:17 2k + +[   ] ant-stylebook-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-stylebook-1.6.2.jar 19-Jul-2004 11:19 2k +[   ] ant-stylebook-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-stylebook-1.6.3.jar 28-Apr-2005 12:28 2k +[   ] ant-stylebook-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-stylebook-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-stylebook-1.6.4.jar 19-May-2005 09:34 2k +[   ] ant-stylebook-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-stylebook-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-stylebook-1.6.5.jar 02-Jun-2005 09:58 2k + +[   ] ant-stylebook-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-stylebook-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-stylebook-1.6.jar 17-Jan-2004 18:10 2k +[   ] ant-stylebook-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-swing-1.6.1.jar 04-May-2004 08:17 7k + +[   ] ant-swing-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-swing-1.6.2.jar 19-Jul-2004 11:19 7k +[   ] ant-swing-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-swing-1.6.3.jar 28-Apr-2005 12:28 7k +[   ] ant-swing-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-swing-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-swing-1.6.4.jar 19-May-2005 09:34 7k +[   ] ant-swing-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-swing-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-swing-1.6.5.jar 02-Jun-2005 09:58 7k + +[   ] ant-swing-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-swing-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-swing-1.6.jar 17-Jan-2004 18:10 6k +[   ] ant-swing-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-trax-1.6.1.jar 04-May-2004 08:17 65k + +[   ] ant-trax-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-trax-1.6.2.jar 19-Jul-2004 11:19 67k +[   ] ant-trax-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-trax-1.6.3.jar 28-Apr-2005 12:28 67k +[   ] ant-trax-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-trax-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-trax-1.6.4.jar 19-May-2005 09:34 67k +[   ] ant-trax-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-trax-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-trax-1.6.5.jar 02-Jun-2005 09:58 67k + +[   ] ant-trax-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-trax-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-trax-1.6.jar 17-Jan-2004 18:10 66k +[   ] ant-trax-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-vaj-1.6.1.jar 04-May-2004 08:17 47k + +[   ] ant-vaj-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-vaj-1.6.2.jar 19-Jul-2004 11:19 47k +[   ] ant-vaj-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-vaj-1.6.3.jar 28-Apr-2005 12:28 49k +[   ] ant-vaj-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-vaj-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-vaj-1.6.4.jar 19-May-2005 09:34 49k +[   ] ant-vaj-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-vaj-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-vaj-1.6.5.jar 02-Jun-2005 09:58 49k + +[   ] ant-vaj-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-vaj-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-vaj-1.6.jar 17-Jan-2004 18:10 47k +[   ] ant-vaj-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-weblogic-1.6.1.jar 04-May-2004 08:17 14k + +[   ] ant-weblogic-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-weblogic-1.6.2.jar 19-Jul-2004 11:19 14k +[   ] ant-weblogic-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-weblogic-1.6.3.jar 28-Apr-2005 12:28 14k +[   ] ant-weblogic-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-weblogic-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-weblogic-1.6.4.jar 19-May-2005 09:34 14k +[   ] ant-weblogic-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-weblogic-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-weblogic-1.6.5.jar 02-Jun-2005 09:58 14k + +[   ] ant-weblogic-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-weblogic-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-weblogic-1.6.jar 17-Jan-2004 18:10 14k +[   ] ant-weblogic-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-xalan1-1.6.1.jar 04-May-2004 08:17 4k + +[   ] ant-xalan1-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-xalan1-1.6.2.jar 19-Jul-2004 11:19 4k +[   ] ant-xalan1-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-xalan1-1.6.3.jar 28-Apr-2005 12:28 4k +[   ] ant-xalan1-1.6.3.jar.md5 28-Apr-2005 12:28 1k + +[   ] ant-xalan1-1.6.3.jar.sha1 29-Apr-2005 06:47 1k +[   ] ant-xalan1-1.6.4.jar 19-May-2005 09:34 4k +[   ] ant-xalan1-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-xalan1-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-xalan1-1.6.5.jar 02-Jun-2005 09:58 4k + +[   ] ant-xalan1-1.6.5.jar.md5 02-Jun-2005 09:58 1k +[   ] ant-xalan1-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-xalan1-1.6.jar 17-Jan-2004 18:10 4k +[   ] ant-xalan1-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-xalan2-1.6.1.jar 04-May-2004 08:17 2k + +[   ] ant-xalan2-1.6.1.jar.md5 04-May-2004 08:17 1k +[   ] ant-xalan2-1.6.jar 17-Jan-2004 18:10 2k +[   ] ant-xalan2-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] ant-xslp-1.6.1.jar 04-May-2004 08:17 2k +[   ] ant-xslp-1.6.1.jar.md5 04-May-2004 08:17 1k + +[   ] ant-xslp-1.6.2.jar 19-Jul-2004 11:19 2k +[   ] ant-xslp-1.6.2.jar.md5 19-Jul-2004 11:19 1k +[   ] ant-xslp-1.6.3.jar 28-Apr-2005 12:28 2k +[   ] ant-xslp-1.6.3.jar.md5 28-Apr-2005 12:28 1k +[   ] ant-xslp-1.6.3.jar.sha1 29-Apr-2005 06:47 1k + +[   ] ant-xslp-1.6.4.jar 19-May-2005 09:34 2k +[   ] ant-xslp-1.6.4.jar.md5 19-May-2005 09:34 1k +[   ] ant-xslp-1.6.4.jar.sha1 19-May-2005 09:34 1k +[   ] ant-xslp-1.6.5.jar 02-Jun-2005 09:58 2k +[   ] ant-xslp-1.6.5.jar.md5 02-Jun-2005 09:58 1k + +[   ] ant-xslp-1.6.5.jar.sha1 02-Jun-2005 09:58 1k +[   ] ant-xslp-1.6.jar 17-Jan-2004 18:10 2k +[   ] ant-xslp-1.6.jar.md5 17-Jan-2004 18:10 1k +[   ] optional-1.5.4.jar 04-May-2004 08:17 657k +[   ] optional-1.5.4.jar.md5 04-May-2004 08:17 1k + +

      +
      Apache/1.3.33 Server at www.ibiblio.org Port 80
      + diff --git a/test/java/org/apache/ivy/util/url/listing-with-spaces.html b/test/java/org/apache/ivy/util/url/listing-with-spaces.html index 65e3e510..1f618eed 100644 --- a/test/java/org/apache/ivy/util/url/listing-with-spaces.html +++ b/test/java/org/apache/ivy/util/url/listing-with-spaces.html @@ -1,48 +1,48 @@ - - - - - Index of /ivy-company/company/app-test/jars - - -

      Index of /ivy-company/company/app-test/jars

      - - + + + + + Index of /ivy-company/company/app-test/jars + + +

      Index of /ivy-company/company/app-test/jars

      + + diff --git a/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.1.xml b/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.1.xml index ffeb6845..f4507e89 100644 --- a/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.1.xml +++ b/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.1.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml b/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml index ca12effe..d2bf3793 100644 --- a/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml +++ b/test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org1/mod1.1/ivys/ivy-1.1.xml b/test/repositories/1/org1/mod1.1/ivys/ivy-1.1.xml index dfb9c65f..b2f3feec 100644 --- a/test/repositories/1/org1/mod1.1/ivys/ivy-1.1.xml +++ b/test/repositories/1/org1/mod1.1/ivys/ivy-1.1.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org1/mod1.1/ivys/ivy-2.0.xml b/test/repositories/1/org1/mod1.1/ivys/ivy-2.0.xml index 5e697989..70f93293 100644 --- a/test/repositories/1/org1/mod1.1/ivys/ivy-2.0.xml +++ b/test/repositories/1/org1/mod1.1/ivys/ivy-2.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml b/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml index 6b8d1901..73f278a1 100644 --- a/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml +++ b/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml b/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml index 3b35963e..2b83a476 100644 --- a/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml +++ b/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml b/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml index b916a583..49a1aed7 100644 --- a/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml +++ b/test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/1/org1/mod1.4/ivys/ivy-1.1.xml b/test/repositories/1/org1/mod1.4/ivys/ivy-1.1.xml index 1939b2b7..99ec51c8 100644 --- a/test/repositories/1/org1/mod1.4/ivys/ivy-1.1.xml +++ b/test/repositories/1/org1/mod1.4/ivys/ivy-1.1.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org1/mod1.4/ivys/ivy-1.2.xml b/test/repositories/1/org1/mod1.4/ivys/ivy-1.2.xml index 691172a5..6a2a260d 100644 --- a/test/repositories/1/org1/mod1.4/ivys/ivy-1.2.xml +++ b/test/repositories/1/org1/mod1.4/ivys/ivy-1.2.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org1/mod1.4/ivys/ivy-1.3.xml b/test/repositories/1/org1/mod1.4/ivys/ivy-1.3.xml index 35048852..320bae76 100644 --- a/test/repositories/1/org1/mod1.4/ivys/ivy-1.3.xml +++ b/test/repositories/1/org1/mod1.4/ivys/ivy-1.3.xml @@ -1,31 +1,31 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/1/org1/mod1.4/ivys/ivy-2.0.xml b/test/repositories/1/org1/mod1.4/ivys/ivy-2.0.xml index cdbd38d1..9db00bfc 100644 --- a/test/repositories/1/org1/mod1.4/ivys/ivy-2.0.xml +++ b/test/repositories/1/org1/mod1.4/ivys/ivy-2.0.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.1.xml b/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.1.xml index e76206d3..e0762c9a 100644 --- a/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.1.xml +++ b/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.1.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml b/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml index 7ed49b39..08659068 100644 --- a/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml +++ b/test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml @@ -1,31 +1,31 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.2.xml b/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.2.xml index 718f4954..568ec483 100644 --- a/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.2.xml +++ b/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.2.xml @@ -1,26 +1,26 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml b/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml index d65d94be..c9de4d37 100644 --- a/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml +++ b/test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml index a379b95e..77960acc 100644 --- a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml +++ b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml index 94b3c922..4a4d3a4a 100644 --- a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml +++ b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml index 18616dae..e0412e47 100644 --- a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml +++ b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml index e87b9c19..488c63d7 100644 --- a/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml +++ b/test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml b/test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml index e0ae3733..4364f16b 100644 --- a/test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml +++ b/test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml b/test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml index da059f07..5320eb5d 100644 --- a/test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml +++ b/test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml b/test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml index 948dbc7d..f46cfe18 100644 --- a/test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml +++ b/test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml b/test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml index 52fe7715..878fea16 100644 --- a/test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml +++ b/test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.1.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.1.xml index 920ed5ac..909c4262 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.1.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.1.xml @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml index fc3de17e..740e7d0d 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml @@ -1,41 +1,41 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml index 45fcae2e..a833fefe 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml index 9c1883d3..ba1742da 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml index 29f5d1ae..95520584 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml index 408cf2bb..9135a215 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml index 528e6793..d604e4b9 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml index 333b9c4c..70b52203 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.3/ivys/ivy-0.7.xml b/test/repositories/1/org2/mod2.3/ivys/ivy-0.7.xml index 02c39ad2..fbc7e988 100644 --- a/test/repositories/1/org2/mod2.3/ivys/ivy-0.7.xml +++ b/test/repositories/1/org2/mod2.3/ivys/ivy-0.7.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml b/test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml index f5de035f..e3fb16ac 100644 --- a/test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml +++ b/test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.1.xml b/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.1.xml index 71c10525..36c7a0aa 100644 --- a/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.1.xml +++ b/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.1.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml b/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml index ed123853..f3f739fe 100644 --- a/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml +++ b/test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.5/ivys/ivy-0.7.xml b/test/repositories/1/org2/mod2.5/ivys/ivy-0.7.xml index 6d50f4cf..7d37c5fd 100644 --- a/test/repositories/1/org2/mod2.5/ivys/ivy-0.7.xml +++ b/test/repositories/1/org2/mod2.5/ivys/ivy-0.7.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.5/ivys/ivy-0.8.xml b/test/repositories/1/org2/mod2.5/ivys/ivy-0.8.xml index 850e9fca..5fb15ec3 100644 --- a/test/repositories/1/org2/mod2.5/ivys/ivy-0.8.xml +++ b/test/repositories/1/org2/mod2.5/ivys/ivy-0.8.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml b/test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml index 0cf66543..d8bada31 100644 --- a/test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml +++ b/test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.6/ivys/ivy-0.11.xml b/test/repositories/1/org2/mod2.6/ivys/ivy-0.11.xml index 807ad72b..7d15975b 100644 --- a/test/repositories/1/org2/mod2.6/ivys/ivy-0.11.xml +++ b/test/repositories/1/org2/mod2.6/ivys/ivy-0.11.xml @@ -1,31 +1,31 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml b/test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml index af68bcc1..6ecfd2a3 100644 --- a/test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml +++ b/test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml b/test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml index 3f1bbfea..7a3691a6 100644 --- a/test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml +++ b/test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml b/test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml index 8b57c2e4..c5af21e5 100644 --- a/test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml +++ b/test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml b/test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml index d26f9a13..eaa2c96b 100644 --- a/test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml +++ b/test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml @@ -1,30 +1,30 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml b/test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml index 64aa2dc9..e52d9e5e 100644 --- a/test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml +++ b/test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.1/ivys/ivy-0.4.xml b/test/repositories/1/org6/mod6.1/ivys/ivy-0.4.xml index 6f6c3e15..c64c625d 100644 --- a/test/repositories/1/org6/mod6.1/ivys/ivy-0.4.xml +++ b/test/repositories/1/org6/mod6.1/ivys/ivy-0.4.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.1/ivys/ivy-0.5.xml b/test/repositories/1/org6/mod6.1/ivys/ivy-0.5.xml index c6a67583..a9c3f6b3 100644 --- a/test/repositories/1/org6/mod6.1/ivys/ivy-0.5.xml +++ b/test/repositories/1/org6/mod6.1/ivys/ivy-0.5.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org6/mod6.1/ivys/ivy-0.6.xml b/test/repositories/1/org6/mod6.1/ivys/ivy-0.6.xml index 7cb9f02b..190a9bb5 100644 --- a/test/repositories/1/org6/mod6.1/ivys/ivy-0.6.xml +++ b/test/repositories/1/org6/mod6.1/ivys/ivy-0.6.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org6/mod6.1/ivys/ivy-2.0.xml b/test/repositories/1/org6/mod6.1/ivys/ivy-2.0.xml index 40dab52a..c12fd516 100644 --- a/test/repositories/1/org6/mod6.1/ivys/ivy-2.0.xml +++ b/test/repositories/1/org6/mod6.1/ivys/ivy-2.0.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml b/test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml index b0ec0b0e..c324a49b 100644 --- a/test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml +++ b/test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml b/test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml index fab600de..e080fc74 100644 --- a/test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml +++ b/test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml b/test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml index 5f4ca9b8..a62f533c 100644 --- a/test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml +++ b/test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml b/test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml index e9675bfd..8fc45734 100644 --- a/test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml +++ b/test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/1/org6/mod6.2/ivys/ivy-2.0.xml b/test/repositories/1/org6/mod6.2/ivys/ivy-2.0.xml index 61efa754..3b039ea0 100644 --- a/test/repositories/1/org6/mod6.2/ivys/ivy-2.0.xml +++ b/test/repositories/1/org6/mod6.2/ivys/ivy-2.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org6/mod6.4/ivys/ivy-1.xml b/test/repositories/1/org6/mod6.4/ivys/ivy-1.xml index 2007f91d..22644a6c 100644 --- a/test/repositories/1/org6/mod6.4/ivys/ivy-1.xml +++ b/test/repositories/1/org6/mod6.4/ivys/ivy-1.xml @@ -1,28 +1,28 @@ - - - - - - + + + + + + diff --git a/test/repositories/1/org6/mod6.4/ivys/ivy-2.xml b/test/repositories/1/org6/mod6.4/ivys/ivy-2.xml index d888681c..8d699919 100644 --- a/test/repositories/1/org6/mod6.4/ivys/ivy-2.xml +++ b/test/repositories/1/org6/mod6.4/ivys/ivy-2.xml @@ -1,28 +1,28 @@ - - - - - - + + + + + + diff --git a/test/repositories/1/org6/mod6.4/ivys/ivy-3.xml b/test/repositories/1/org6/mod6.4/ivys/ivy-3.xml index e8917c51..18d8f982 100644 --- a/test/repositories/1/org6/mod6.4/ivys/ivy-3.xml +++ b/test/repositories/1/org6/mod6.4/ivys/ivy-3.xml @@ -1,28 +1,28 @@ - - - - - - + + + + + + diff --git a/test/repositories/1/org6/mod6.4/ivys/ivy-4.xml b/test/repositories/1/org6/mod6.4/ivys/ivy-4.xml index ccb84c8f..7c0d0ba1 100644 --- a/test/repositories/1/org6/mod6.4/ivys/ivy-4.xml +++ b/test/repositories/1/org6/mod6.4/ivys/ivy-4.xml @@ -1,28 +1,28 @@ - - - - - - + + + + + + diff --git a/test/repositories/1/org6/mod6.4/ivys/ivy-5.xml b/test/repositories/1/org6/mod6.4/ivys/ivy-5.xml index 091ff57c..27372d90 100644 --- a/test/repositories/1/org6/mod6.4/ivys/ivy-5.xml +++ b/test/repositories/1/org6/mod6.4/ivys/ivy-5.xml @@ -1,28 +1,28 @@ - - - - - - + + + + + + diff --git a/test/repositories/1/org9/mod9.1/ivys/ivy-1.0.xml b/test/repositories/1/org9/mod9.1/ivys/ivy-1.0.xml index 901616ba..ac219abd 100644 --- a/test/repositories/1/org9/mod9.1/ivys/ivy-1.0.xml +++ b/test/repositories/1/org9/mod9.1/ivys/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml b/test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml index 9d6e91e4..13263537 100644 --- a/test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml +++ b/test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml b/test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml index 2deacd02..2c083df7 100644 --- a/test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml +++ b/test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml b/test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml index e32993a1..c21dd18a 100644 --- a/test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml +++ b/test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.0.xml b/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.0.xml index f35a8d5e..5283d3e2 100644 --- a/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.0.xml +++ b/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.0.xml @@ -1,26 +1,26 @@ - - - - - + + + + + diff --git a/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.1.xml b/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.1.xml index 779fd66a..25f8d205 100644 --- a/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.1.xml +++ b/test/repositories/1/orgfailure/modfailure/ivys/ivy-1.1.xml @@ -1,25 +1,25 @@ - - - - + + + + diff --git a/test/repositories/1/yourorg/yourdep/yoursys/yourmod/ivys/ivy-1.0.xml b/test/repositories/1/yourorg/yourdep/yoursys/yourmod/ivys/ivy-1.0.xml index 0e57dd67..f0cc07be 100644 --- a/test/repositories/1/yourorg/yourdep/yoursys/yourmod/ivys/ivy-1.0.xml +++ b/test/repositories/1/yourorg/yourdep/yoursys/yourmod/ivys/ivy-1.0.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/buildnumber/ivy-test.xml b/test/repositories/2/buildnumber/ivy-test.xml index 6543ead2..5df1eb4b 100644 --- a/test/repositories/2/buildnumber/ivy-test.xml +++ b/test/repositories/2/buildnumber/ivy-test.xml @@ -1,26 +1,26 @@ - - - - + + + + diff --git a/test/repositories/2/mod10.1/ivy-1.0.xml b/test/repositories/2/mod10.1/ivy-1.0.xml index 7a9475f0..2f7c3f9f 100644 --- a/test/repositories/2/mod10.1/ivy-1.0.xml +++ b/test/repositories/2/mod10.1/ivy-1.0.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod10.1/ivy-1.1.xml b/test/repositories/2/mod10.1/ivy-1.1.xml index 700888a2..0e2db2cc 100644 --- a/test/repositories/2/mod10.1/ivy-1.1.xml +++ b/test/repositories/2/mod10.1/ivy-1.1.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod10.1/ivy-1.2.xml b/test/repositories/2/mod10.1/ivy-1.2.xml index 4574300d..95341fba 100644 --- a/test/repositories/2/mod10.1/ivy-1.2.xml +++ b/test/repositories/2/mod10.1/ivy-1.2.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/2/mod10.1/ivy-1.3.xml b/test/repositories/2/mod10.1/ivy-1.3.xml index 0f79bb00..989e6ee4 100644 --- a/test/repositories/2/mod10.1/ivy-1.3.xml +++ b/test/repositories/2/mod10.1/ivy-1.3.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod10.2/ivy-1.0.xml b/test/repositories/2/mod10.2/ivy-1.0.xml index 19125316..6a1e5287 100644 --- a/test/repositories/2/mod10.2/ivy-1.0.xml +++ b/test/repositories/2/mod10.2/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod10.2/ivy-1.1.xml b/test/repositories/2/mod10.2/ivy-1.1.xml index b2f67fe8..e8ba0160 100644 --- a/test/repositories/2/mod10.2/ivy-1.1.xml +++ b/test/repositories/2/mod10.2/ivy-1.1.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod10.2/ivy-1.2.xml b/test/repositories/2/mod10.2/ivy-1.2.xml index f80a71d4..c18b517d 100644 --- a/test/repositories/2/mod10.2/ivy-1.2.xml +++ b/test/repositories/2/mod10.2/ivy-1.2.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod10.2/ivy-1.3.xml b/test/repositories/2/mod10.2/ivy-1.3.xml index afd6b420..077d9cf3 100644 --- a/test/repositories/2/mod10.2/ivy-1.3.xml +++ b/test/repositories/2/mod10.2/ivy-1.3.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod10.2/ivy-2.0.xml b/test/repositories/2/mod10.2/ivy-2.0.xml index 1afe7673..6a5ab502 100644 --- a/test/repositories/2/mod10.2/ivy-2.0.xml +++ b/test/repositories/2/mod10.2/ivy-2.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod11.1/ivy-1.0.xml b/test/repositories/2/mod11.1/ivy-1.0.xml index dca83f67..5a4753ec 100644 --- a/test/repositories/2/mod11.1/ivy-1.0.xml +++ b/test/repositories/2/mod11.1/ivy-1.0.xml @@ -1,39 +1,39 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod11.2/ivy-1.0.xml b/test/repositories/2/mod11.2/ivy-1.0.xml index ac4b958c..6bc204a3 100644 --- a/test/repositories/2/mod11.2/ivy-1.0.xml +++ b/test/repositories/2/mod11.2/ivy-1.0.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod12.1/ivy-1.0.xml b/test/repositories/2/mod12.1/ivy-1.0.xml index f9c66d5e..51e4f0a8 100644 --- a/test/repositories/2/mod12.1/ivy-1.0.xml +++ b/test/repositories/2/mod12.1/ivy-1.0.xml @@ -1,27 +1,27 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod12.2/ivy-1.0.xml b/test/repositories/2/mod12.2/ivy-1.0.xml index a9543de4..57761242 100644 --- a/test/repositories/2/mod12.2/ivy-1.0.xml +++ b/test/repositories/2/mod12.2/ivy-1.0.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod13.1/ivy-1.0.xml b/test/repositories/2/mod13.1/ivy-1.0.xml index f79da98b..e4e2f5e8 100644 --- a/test/repositories/2/mod13.1/ivy-1.0.xml +++ b/test/repositories/2/mod13.1/ivy-1.0.xml @@ -1,41 +1,41 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod13.2/ivy-1.0.xml b/test/repositories/2/mod13.2/ivy-1.0.xml index 1d26e801..6725ab1b 100644 --- a/test/repositories/2/mod13.2/ivy-1.0.xml +++ b/test/repositories/2/mod13.2/ivy-1.0.xml @@ -1,41 +1,41 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod13.3/ivy-1.0.xml b/test/repositories/2/mod13.3/ivy-1.0.xml index 55324354..ca41526a 100644 --- a/test/repositories/2/mod13.3/ivy-1.0.xml +++ b/test/repositories/2/mod13.3/ivy-1.0.xml @@ -1,41 +1,41 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod14.1/ivy-1.1.xml b/test/repositories/2/mod14.1/ivy-1.1.xml index 4b865172..4cc80056 100644 --- a/test/repositories/2/mod14.1/ivy-1.1.xml +++ b/test/repositories/2/mod14.1/ivy-1.1.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod14.2/ivy-1.1.xml b/test/repositories/2/mod14.2/ivy-1.1.xml index b526a8e6..5520f661 100644 --- a/test/repositories/2/mod14.2/ivy-1.1.xml +++ b/test/repositories/2/mod14.2/ivy-1.1.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod14.3/ivy-1.1.xml b/test/repositories/2/mod14.3/ivy-1.1.xml index 14d95046..0ddce49b 100644 --- a/test/repositories/2/mod14.3/ivy-1.1.xml +++ b/test/repositories/2/mod14.3/ivy-1.1.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod14.4/ivy-1.1.xml b/test/repositories/2/mod14.4/ivy-1.1.xml index 9796f17d..b06b25a5 100644 --- a/test/repositories/2/mod14.4/ivy-1.1.xml +++ b/test/repositories/2/mod14.4/ivy-1.1.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod15.1/ivy-1.1.xml b/test/repositories/2/mod15.1/ivy-1.1.xml index c79527e4..5e76d7be 100644 --- a/test/repositories/2/mod15.1/ivy-1.1.xml +++ b/test/repositories/2/mod15.1/ivy-1.1.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod15.2/ivy-1.1.xml b/test/repositories/2/mod15.2/ivy-1.1.xml index 2c71b36f..934103d5 100644 --- a/test/repositories/2/mod15.2/ivy-1.1.xml +++ b/test/repositories/2/mod15.2/ivy-1.1.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod3.1/ivy-1.0.1.xml b/test/repositories/2/mod3.1/ivy-1.0.1.xml index b81ac7c6..3ffdbce0 100644 --- a/test/repositories/2/mod3.1/ivy-1.0.1.xml +++ b/test/repositories/2/mod3.1/ivy-1.0.1.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod3.1/ivy-1.0.xml b/test/repositories/2/mod3.1/ivy-1.0.xml index 8ab9184c..30496768 100644 --- a/test/repositories/2/mod3.1/ivy-1.0.xml +++ b/test/repositories/2/mod3.1/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod3.1/ivy-1.1.xml b/test/repositories/2/mod3.1/ivy-1.1.xml index 695782cb..0b3d2424 100644 --- a/test/repositories/2/mod3.1/ivy-1.1.xml +++ b/test/repositories/2/mod3.1/ivy-1.1.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod3.1/ivy-1.2.xml b/test/repositories/2/mod3.1/ivy-1.2.xml index 03078394..2003ba9c 100644 --- a/test/repositories/2/mod3.1/ivy-1.2.xml +++ b/test/repositories/2/mod3.1/ivy-1.2.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod3.1/ivy-1.3.xml b/test/repositories/2/mod3.1/ivy-1.3.xml index 9f503d4b..ae56c70e 100644 --- a/test/repositories/2/mod3.1/ivy-1.3.xml +++ b/test/repositories/2/mod3.1/ivy-1.3.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/2/mod3.1/ivy-1.4.xml b/test/repositories/2/mod3.1/ivy-1.4.xml index 5363d16e..264b2fba 100644 --- a/test/repositories/2/mod3.1/ivy-1.4.xml +++ b/test/repositories/2/mod3.1/ivy-1.4.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/2/mod3.2/ivy-1.1.xml b/test/repositories/2/mod3.2/ivy-1.1.xml index aba8bf54..0793dce5 100644 --- a/test/repositories/2/mod3.2/ivy-1.1.xml +++ b/test/repositories/2/mod3.2/ivy-1.1.xml @@ -1,28 +1,28 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod3.2/ivy-1.2.1.xml b/test/repositories/2/mod3.2/ivy-1.2.1.xml index cd9de58b..fa63fd58 100644 --- a/test/repositories/2/mod3.2/ivy-1.2.1.xml +++ b/test/repositories/2/mod3.2/ivy-1.2.1.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod3.2/ivy-1.2.xml b/test/repositories/2/mod3.2/ivy-1.2.xml index a647c032..f5ff79bc 100644 --- a/test/repositories/2/mod3.2/ivy-1.2.xml +++ b/test/repositories/2/mod3.2/ivy-1.2.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod3.2/ivy-1.3.xml b/test/repositories/2/mod3.2/ivy-1.3.xml index d0c4c95c..f923d520 100644 --- a/test/repositories/2/mod3.2/ivy-1.3.xml +++ b/test/repositories/2/mod3.2/ivy-1.3.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod3.2/ivy-1.4.xml b/test/repositories/2/mod3.2/ivy-1.4.xml index becc8103..bbc3962b 100644 --- a/test/repositories/2/mod3.2/ivy-1.4.xml +++ b/test/repositories/2/mod3.2/ivy-1.4.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.0.xml b/test/repositories/2/mod4.1/ivy-4.0.xml index 7462b5b4..8af4c0d4 100644 --- a/test/repositories/2/mod4.1/ivy-4.0.xml +++ b/test/repositories/2/mod4.1/ivy-4.0.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.1.xml b/test/repositories/2/mod4.1/ivy-4.1.xml index 3b83d440..c8a871a8 100644 --- a/test/repositories/2/mod4.1/ivy-4.1.xml +++ b/test/repositories/2/mod4.1/ivy-4.1.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.10.xml b/test/repositories/2/mod4.1/ivy-4.10.xml index 1ed616ed..f707a5a9 100644 --- a/test/repositories/2/mod4.1/ivy-4.10.xml +++ b/test/repositories/2/mod4.1/ivy-4.10.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.11.xml b/test/repositories/2/mod4.1/ivy-4.11.xml index 5ea13417..dcf01fb2 100644 --- a/test/repositories/2/mod4.1/ivy-4.11.xml +++ b/test/repositories/2/mod4.1/ivy-4.11.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.12.xml b/test/repositories/2/mod4.1/ivy-4.12.xml index 125696e3..b10fcbd9 100644 --- a/test/repositories/2/mod4.1/ivy-4.12.xml +++ b/test/repositories/2/mod4.1/ivy-4.12.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.13.xml b/test/repositories/2/mod4.1/ivy-4.13.xml index c535830f..235799eb 100644 --- a/test/repositories/2/mod4.1/ivy-4.13.xml +++ b/test/repositories/2/mod4.1/ivy-4.13.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.14.xml b/test/repositories/2/mod4.1/ivy-4.14.xml index 11823a67..3bd37c99 100644 --- a/test/repositories/2/mod4.1/ivy-4.14.xml +++ b/test/repositories/2/mod4.1/ivy-4.14.xml @@ -1,31 +1,31 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.2.xml b/test/repositories/2/mod4.1/ivy-4.2.xml index c7f29a8b..113f40a8 100644 --- a/test/repositories/2/mod4.1/ivy-4.2.xml +++ b/test/repositories/2/mod4.1/ivy-4.2.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.3.xml b/test/repositories/2/mod4.1/ivy-4.3.xml index b35d3278..0fff5e41 100644 --- a/test/repositories/2/mod4.1/ivy-4.3.xml +++ b/test/repositories/2/mod4.1/ivy-4.3.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.4.xml b/test/repositories/2/mod4.1/ivy-4.4.xml index 9a2fa151..13489238 100644 --- a/test/repositories/2/mod4.1/ivy-4.4.xml +++ b/test/repositories/2/mod4.1/ivy-4.4.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.5.xml b/test/repositories/2/mod4.1/ivy-4.5.xml index 9257d82b..c23f784d 100644 --- a/test/repositories/2/mod4.1/ivy-4.5.xml +++ b/test/repositories/2/mod4.1/ivy-4.5.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.6.xml b/test/repositories/2/mod4.1/ivy-4.6.xml index 602f502c..94a7f024 100644 --- a/test/repositories/2/mod4.1/ivy-4.6.xml +++ b/test/repositories/2/mod4.1/ivy-4.6.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.7.xml b/test/repositories/2/mod4.1/ivy-4.7.xml index e6052fbd..2e2b189d 100644 --- a/test/repositories/2/mod4.1/ivy-4.7.xml +++ b/test/repositories/2/mod4.1/ivy-4.7.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.8.xml b/test/repositories/2/mod4.1/ivy-4.8.xml index 861563f9..ee96b529 100644 --- a/test/repositories/2/mod4.1/ivy-4.8.xml +++ b/test/repositories/2/mod4.1/ivy-4.8.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod4.1/ivy-4.9.xml b/test/repositories/2/mod4.1/ivy-4.9.xml index 1bb98e29..04d472d4 100644 --- a/test/repositories/2/mod4.1/ivy-4.9.xml +++ b/test/repositories/2/mod4.1/ivy-4.9.xml @@ -1,31 +1,31 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/2/mod5.1/ivy-4.0.xml b/test/repositories/2/mod5.1/ivy-4.0.xml index c788907d..a879cec4 100644 --- a/test/repositories/2/mod5.1/ivy-4.0.xml +++ b/test/repositories/2/mod5.1/ivy-4.0.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/2/mod5.1/ivy-4.1.xml b/test/repositories/2/mod5.1/ivy-4.1.xml index 172b8ff5..b004f67c 100644 --- a/test/repositories/2/mod5.1/ivy-4.1.xml +++ b/test/repositories/2/mod5.1/ivy-4.1.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/2/mod5.1/ivy-4.2.xml b/test/repositories/2/mod5.1/ivy-4.2.xml index f58b626b..bd7ea42f 100644 --- a/test/repositories/2/mod5.1/ivy-4.2.xml +++ b/test/repositories/2/mod5.1/ivy-4.2.xml @@ -1,37 +1,37 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod5.2/ivy-1.0.xml b/test/repositories/2/mod5.2/ivy-1.0.xml index 78354e41..9a9ace59 100644 --- a/test/repositories/2/mod5.2/ivy-1.0.xml +++ b/test/repositories/2/mod5.2/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod5.2/ivy-2.0.xml b/test/repositories/2/mod5.2/ivy-2.0.xml index 0d03f1c2..38788684 100644 --- a/test/repositories/2/mod5.2/ivy-2.0.xml +++ b/test/repositories/2/mod5.2/ivy-2.0.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/2/mod6.1/ivy-1.0.xml b/test/repositories/2/mod6.1/ivy-1.0.xml index 540b7ec9..74363665 100644 --- a/test/repositories/2/mod6.1/ivy-1.0.xml +++ b/test/repositories/2/mod6.1/ivy-1.0.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod6.1/ivy-1.1.xml b/test/repositories/2/mod6.1/ivy-1.1.xml index 1c10796b..f99894b4 100644 --- a/test/repositories/2/mod6.1/ivy-1.1.xml +++ b/test/repositories/2/mod6.1/ivy-1.1.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod6.1/ivy-1.2.xml b/test/repositories/2/mod6.1/ivy-1.2.xml index 9deffbab..8fc0921d 100644 --- a/test/repositories/2/mod6.1/ivy-1.2.xml +++ b/test/repositories/2/mod6.1/ivy-1.2.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/2/mod6.1/ivy-1.3.xml b/test/repositories/2/mod6.1/ivy-1.3.xml index eca37533..f26a9ff2 100644 --- a/test/repositories/2/mod6.1/ivy-1.3.xml +++ b/test/repositories/2/mod6.1/ivy-1.3.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/2/mod6.2/ivy-1.0.xml b/test/repositories/2/mod6.2/ivy-1.0.xml index 21f8b161..8512e2e5 100644 --- a/test/repositories/2/mod6.2/ivy-1.0.xml +++ b/test/repositories/2/mod6.2/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod6.3/ivy-1.0.xml b/test/repositories/2/mod6.3/ivy-1.0.xml index 4bc4b04f..842ea935 100644 --- a/test/repositories/2/mod6.3/ivy-1.0.xml +++ b/test/repositories/2/mod6.3/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod6.3/ivy-1.1.xml b/test/repositories/2/mod6.3/ivy-1.1.xml index 22936536..371863b4 100644 --- a/test/repositories/2/mod6.3/ivy-1.1.xml +++ b/test/repositories/2/mod6.3/ivy-1.1.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/2/mod7.1/ivy-1.0.xml b/test/repositories/2/mod7.1/ivy-1.0.xml index 3888e1b1..58493efd 100644 --- a/test/repositories/2/mod7.1/ivy-1.0.xml +++ b/test/repositories/2/mod7.1/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod7.1/ivy-2.0.xml b/test/repositories/2/mod7.1/ivy-2.0.xml index c9eb1982..da48e344 100644 --- a/test/repositories/2/mod7.1/ivy-2.0.xml +++ b/test/repositories/2/mod7.1/ivy-2.0.xml @@ -1,26 +1,26 @@ - - - - + + + + diff --git a/test/repositories/2/mod7.2/ivy-1.0.xml b/test/repositories/2/mod7.2/ivy-1.0.xml index c7243cae..db20fdc1 100644 --- a/test/repositories/2/mod7.2/ivy-1.0.xml +++ b/test/repositories/2/mod7.2/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/2/mod7.3/ivy-1.0.xml b/test/repositories/2/mod7.3/ivy-1.0.xml index e3e6d2db..9c4bf78e 100644 --- a/test/repositories/2/mod7.3/ivy-1.0.xml +++ b/test/repositories/2/mod7.3/ivy-1.0.xml @@ -1,30 +1,30 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/2/mod8.1/a-1.0.txt b/test/repositories/2/mod8.1/a-1.0.txt index 3cf20d57..39cdd0de 100644 --- a/test/repositories/2/mod8.1/a-1.0.txt +++ b/test/repositories/2/mod8.1/a-1.0.txt @@ -1 +1 @@ -- \ No newline at end of file +- diff --git a/test/repositories/2/mod8.1/a-1.1.txt b/test/repositories/2/mod8.1/a-1.1.txt index 3cf20d57..39cdd0de 100644 --- a/test/repositories/2/mod8.1/a-1.1.txt +++ b/test/repositories/2/mod8.1/a-1.1.txt @@ -1 +1 @@ -- \ No newline at end of file +- diff --git a/test/repositories/2/mod8.1/a-private-1.0.txt b/test/repositories/2/mod8.1/a-private-1.0.txt index 3cf20d57..39cdd0de 100644 --- a/test/repositories/2/mod8.1/a-private-1.0.txt +++ b/test/repositories/2/mod8.1/a-private-1.0.txt @@ -1 +1 @@ -- \ No newline at end of file +- diff --git a/test/repositories/2/mod8.1/a-private-1.1.txt b/test/repositories/2/mod8.1/a-private-1.1.txt index 3cf20d57..39cdd0de 100644 --- a/test/repositories/2/mod8.1/a-private-1.1.txt +++ b/test/repositories/2/mod8.1/a-private-1.1.txt @@ -1 +1 @@ -- \ No newline at end of file +- diff --git a/test/repositories/2/mod8.1/ivy-1.0.xml b/test/repositories/2/mod8.1/ivy-1.0.xml index d40c06fb..386c85b8 100644 --- a/test/repositories/2/mod8.1/ivy-1.0.xml +++ b/test/repositories/2/mod8.1/ivy-1.0.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/2/mod8.1/ivy-1.1.xml b/test/repositories/2/mod8.1/ivy-1.1.xml index 6cd5cfb1..c5df2227 100644 --- a/test/repositories/2/mod8.1/ivy-1.1.xml +++ b/test/repositories/2/mod8.1/ivy-1.1.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/2/mod8.2/ivy-1.0.xml b/test/repositories/2/mod8.2/ivy-1.0.xml index d5688c79..32eaa715 100644 --- a/test/repositories/2/mod8.2/ivy-1.0.xml +++ b/test/repositories/2/mod8.2/ivy-1.0.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/2/mod8.3/ivy-1.0.xml b/test/repositories/2/mod8.3/ivy-1.0.xml index 593b0a9c..9025557f 100644 --- a/test/repositories/2/mod8.3/ivy-1.0.xml +++ b/test/repositories/2/mod8.3/ivy-1.0.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/2/mod8.4/ivy-1.0.xml b/test/repositories/2/mod8.4/ivy-1.0.xml index 906d9fd3..f006233f 100644 --- a/test/repositories/2/mod8.4/ivy-1.0.xml +++ b/test/repositories/2/mod8.4/ivy-1.0.xml @@ -1,32 +1,32 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/2/mod8.4/ivy-1.1.xml b/test/repositories/2/mod8.4/ivy-1.1.xml index 98d28871..6f8b496a 100644 --- a/test/repositories/2/mod8.4/ivy-1.1.xml +++ b/test/repositories/2/mod8.4/ivy-1.1.xml @@ -1,32 +1,32 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/2/mod8.5/ivy-2.0.xml b/test/repositories/2/mod8.5/ivy-2.0.xml index 6e3df85c..1daf870e 100644 --- a/test/repositories/2/mod8.5/ivy-2.0.xml +++ b/test/repositories/2/mod8.5/ivy-2.0.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/2/mod8.6/ivy-2.0.xml b/test/repositories/2/mod8.6/ivy-2.0.xml index 620d13a0..2bf5b3ea 100644 --- a/test/repositories/2/mod8.6/ivy-2.0.xml +++ b/test/repositories/2/mod8.6/ivy-2.0.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/2/mod_released/ivy-1.0.xml b/test/repositories/2/mod_released/ivy-1.0.xml index 00092cc0..fb4eb15c 100644 --- a/test/repositories/2/mod_released/ivy-1.0.xml +++ b/test/repositories/2/mod_released/ivy-1.0.xml @@ -1,31 +1,31 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/2/mod_released/ivy-1.1.xml b/test/repositories/2/mod_released/ivy-1.1.xml index 50fece5c..bdb5d736 100644 --- a/test/repositories/2/mod_released/ivy-1.1.xml +++ b/test/repositories/2/mod_released/ivy-1.1.xml @@ -1,31 +1,31 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/IVY-258/ivy.xml b/test/repositories/IVY-258/ivy.xml index 6635719b..7b929c3b 100644 --- a/test/repositories/IVY-258/ivy.xml +++ b/test/repositories/IVY-258/ivy.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/IVY-258/ivysettings.xml b/test/repositories/IVY-258/ivysettings.xml index 8ff8992a..c2d558bb 100644 --- a/test/repositories/IVY-258/ivysettings.xml +++ b/test/repositories/IVY-258/ivysettings.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/IVY-258/module2/ivy.xml b/test/repositories/IVY-258/module2/ivy.xml index f300dbc6..cbd627e9 100644 --- a/test/repositories/IVY-258/module2/ivy.xml +++ b/test/repositories/IVY-258/module2/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/IVY-264/ivy.xml b/test/repositories/IVY-264/ivy.xml index 5505a73a..bc61dd45 100644 --- a/test/repositories/IVY-264/ivy.xml +++ b/test/repositories/IVY-264/ivy.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/IVY-264/ivysettings.xml b/test/repositories/IVY-264/ivysettings.xml index 0eee29ca..87ab629b 100644 --- a/test/repositories/IVY-264/ivysettings.xml +++ b/test/repositories/IVY-264/ivysettings.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/IVY-264/x/ivy-1.0.xml b/test/repositories/IVY-264/x/ivy-1.0.xml index cdbd0e58..ac0a453c 100644 --- a/test/repositories/IVY-264/x/ivy-1.0.xml +++ b/test/repositories/IVY-264/x/ivy-1.0.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/IVY-264/y/ivy-1.0.xml b/test/repositories/IVY-264/y/ivy-1.0.xml index 702686bd..7598e00a 100644 --- a/test/repositories/IVY-264/y/ivy-1.0.xml +++ b/test/repositories/IVY-264/y/ivy-1.0.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/IVY-264/z/ivy-1.0.xml b/test/repositories/IVY-264/z/ivy-1.0.xml index f35fe665..b1b824a1 100644 --- a/test/repositories/IVY-264/z/ivy-1.0.xml +++ b/test/repositories/IVY-264/z/ivy-1.0.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/IVY-283/B/ivy-1.0.xml b/test/repositories/IVY-283/B/ivy-1.0.xml index d08df3b0..bb75c189 100644 --- a/test/repositories/IVY-283/B/ivy-1.0.xml +++ b/test/repositories/IVY-283/B/ivy-1.0.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-283/C/ivy-1.0.xml b/test/repositories/IVY-283/C/ivy-1.0.xml index 9ff31070..a43688ed 100644 --- a/test/repositories/IVY-283/C/ivy-1.0.xml +++ b/test/repositories/IVY-283/C/ivy-1.0.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-283/ivy-d.xml b/test/repositories/IVY-283/ivy-d.xml index abc5716d..0c3ed013 100644 --- a/test/repositories/IVY-283/ivy-d.xml +++ b/test/repositories/IVY-283/ivy-d.xml @@ -1,43 +1,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-283/ivy.xml b/test/repositories/IVY-283/ivy.xml index db9143dc..b370080e 100644 --- a/test/repositories/IVY-283/ivy.xml +++ b/test/repositories/IVY-283/ivy.xml @@ -1,39 +1,39 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-283/ivysettings.xml b/test/repositories/IVY-283/ivysettings.xml index 0eee29ca..87ab629b 100644 --- a/test/repositories/IVY-283/ivysettings.xml +++ b/test/repositories/IVY-283/ivysettings.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/IVY-283/module_a/ivy-local.xml b/test/repositories/IVY-283/module_a/ivy-local.xml index 5fdeea4e..f186c0bd 100644 --- a/test/repositories/IVY-283/module_a/ivy-local.xml +++ b/test/repositories/IVY-283/module_a/ivy-local.xml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-283/module_b/ivy-local.xml b/test/repositories/IVY-283/module_b/ivy-local.xml index 12afe5af..6eaca6c6 100644 --- a/test/repositories/IVY-283/module_b/ivy-local.xml +++ b/test/repositories/IVY-283/module_b/ivy-local.xml @@ -1,40 +1,40 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-283/module_c/ivy-local.xml b/test/repositories/IVY-283/module_c/ivy-local.xml index 281ce18a..7980f07d 100644 --- a/test/repositories/IVY-283/module_c/ivy-local.xml +++ b/test/repositories/IVY-283/module_c/ivy-local.xml @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-283/module_e/ivy-local.xml b/test/repositories/IVY-283/module_e/ivy-local.xml index 43b5dc8e..e60544ba 100644 --- a/test/repositories/IVY-283/module_e/ivy-local.xml +++ b/test/repositories/IVY-283/module_e/ivy-local.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-407/MyCompany/A/ivy-1.0.0.xml b/test/repositories/IVY-407/MyCompany/A/ivy-1.0.0.xml index 7ba73df2..789a857e 100644 --- a/test/repositories/IVY-407/MyCompany/A/ivy-1.0.0.xml +++ b/test/repositories/IVY-407/MyCompany/A/ivy-1.0.0.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-407/MyCompany/B/ivy-1.0.0.xml b/test/repositories/IVY-407/MyCompany/B/ivy-1.0.0.xml index 4d7f55ea..51ee1697 100644 --- a/test/repositories/IVY-407/MyCompany/B/ivy-1.0.0.xml +++ b/test/repositories/IVY-407/MyCompany/B/ivy-1.0.0.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml b/test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml index 6e72dfcc..c04c36e6 100644 --- a/test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml +++ b/test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml b/test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml index 4f608090..5796f74f 100644 --- a/test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml +++ b/test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml b/test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml index 2876ee3a..cb8b29fb 100644 --- a/test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml +++ b/test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-407/MyCompany/D/ivy-1.0.0.xml b/test/repositories/IVY-407/MyCompany/D/ivy-1.0.0.xml index b5da22c6..74539efe 100644 --- a/test/repositories/IVY-407/MyCompany/D/ivy-1.0.0.xml +++ b/test/repositories/IVY-407/MyCompany/D/ivy-1.0.0.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-448/ivy.xml b/test/repositories/IVY-448/ivy.xml index cc969d9b..be214a09 100644 --- a/test/repositories/IVY-448/ivy.xml +++ b/test/repositories/IVY-448/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/IVY-448/ivysettings.xml b/test/repositories/IVY-448/ivysettings.xml index ab9b748c..337e093b 100644 --- a/test/repositories/IVY-448/ivysettings.xml +++ b/test/repositories/IVY-448/ivysettings.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/IVY-448/module2/ivy-1.0.xml b/test/repositories/IVY-448/module2/ivy-1.0.xml index 120a2001..1653c549 100644 --- a/test/repositories/IVY-448/module2/ivy-1.0.xml +++ b/test/repositories/IVY-448/module2/ivy-1.0.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/IVY-448/module3/ivy-1.0.xml b/test/repositories/IVY-448/module3/ivy-1.0.xml index 7f874139..052d47eb 100644 --- a/test/repositories/IVY-448/module3/ivy-1.0.xml +++ b/test/repositories/IVY-448/module3/ivy-1.0.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/IVY-448/module3/ivy-2.0.xml b/test/repositories/IVY-448/module3/ivy-2.0.xml index 20f3a61b..fa53ab3e 100644 --- a/test/repositories/IVY-448/module3/ivy-2.0.xml +++ b/test/repositories/IVY-448/module3/ivy-2.0.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/IVY-84/ivysettings.xml b/test/repositories/IVY-84/ivysettings.xml index 5f4dbd25..245738bc 100644 --- a/test/repositories/IVY-84/ivysettings.xml +++ b/test/repositories/IVY-84/ivysettings.xml @@ -1,30 +1,30 @@ - - - - latest-revision - - - - - - - - - + + + + latest-revision + + + + + + + + + diff --git a/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml b/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml index 025e8004..e7d5ff74 100644 --- a/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml +++ b/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml b/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml index 2e62b0a4..3f55f018 100644 --- a/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml +++ b/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml b/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml index dd2452e3..b270eab9 100644 --- a/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml +++ b/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml b/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml index 77f7cc42..9a9762a6 100644 --- a/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml +++ b/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml b/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml index 99368ef1..c1c0a6cb 100644 --- a/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml +++ b/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml b/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml index 5fe35174..c351bbd2 100644 --- a/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml +++ b/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/tests/1/ivy.xml b/test/repositories/IVY-84/tests/1/ivy.xml index 847ea247..3cd65e33 100644 --- a/test/repositories/IVY-84/tests/1/ivy.xml +++ b/test/repositories/IVY-84/tests/1/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/tests/2/ivy.xml b/test/repositories/IVY-84/tests/2/ivy.xml index d2b7bb90..20ff9c86 100644 --- a/test/repositories/IVY-84/tests/2/ivy.xml +++ b/test/repositories/IVY-84/tests/2/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/tests/3/ivy.xml b/test/repositories/IVY-84/tests/3/ivy.xml index 0893be9d..f36eab90 100644 --- a/test/repositories/IVY-84/tests/3/ivy.xml +++ b/test/repositories/IVY-84/tests/3/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/tests/4/ivy.xml b/test/repositories/IVY-84/tests/4/ivy.xml index ab40f2cd..33aa38b9 100644 --- a/test/repositories/IVY-84/tests/4/ivy.xml +++ b/test/repositories/IVY-84/tests/4/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/tests/5/ivy.xml b/test/repositories/IVY-84/tests/5/ivy.xml index 702903a4..8d4ea67f 100644 --- a/test/repositories/IVY-84/tests/5/ivy.xml +++ b/test/repositories/IVY-84/tests/5/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/tests/6/ivy.xml b/test/repositories/IVY-84/tests/6/ivy.xml index a5aa849a..bb6aeccd 100644 --- a/test/repositories/IVY-84/tests/6/ivy.xml +++ b/test/repositories/IVY-84/tests/6/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/IVY-84/tests/7/ivy.xml b/test/repositories/IVY-84/tests/7/ivy.xml index 7a674fe3..2ab3c1e2 100644 --- a/test/repositories/IVY-84/tests/7/ivy.xml +++ b/test/repositories/IVY-84/tests/7/ivy.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/badfile/ivys/ ivy-badmodule.xml b/test/repositories/badfile/ivys/ ivy-badmodule.xml index 2c407ad6..af61d73a 100644 --- a/test/repositories/badfile/ivys/ ivy-badmodule.xml +++ b/test/repositories/badfile/ivys/ ivy-badmodule.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/badfile/ivys/ivy-badorg.xml b/test/repositories/badfile/ivys/ivy-badorg.xml index 2c407ad6..af61d73a 100644 --- a/test/repositories/badfile/ivys/ivy-badorg.xml +++ b/test/repositories/badfile/ivys/ivy-badorg.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/badfile/ivys/ivy-badrevision.xml b/test/repositories/badfile/ivys/ivy-badrevision.xml index 2c407ad6..af61d73a 100644 --- a/test/repositories/badfile/ivys/ivy-badrevision.xml +++ b/test/repositories/badfile/ivys/ivy-badrevision.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/badfile/ivysettings.xml b/test/repositories/badfile/ivysettings.xml index e8267287..e0b16bb7 100644 --- a/test/repositories/badfile/ivysettings.xml +++ b/test/repositories/badfile/ivysettings.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/badfile/myorg/mymodule/ivy-badmodule.xml b/test/repositories/badfile/myorg/mymodule/ivy-badmodule.xml index ac0af7c1..8c8ad67b 100644 --- a/test/repositories/badfile/myorg/mymodule/ivy-badmodule.xml +++ b/test/repositories/badfile/myorg/mymodule/ivy-badmodule.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/badfile/myorg/mymodule/ivy-badorg.xml b/test/repositories/badfile/myorg/mymodule/ivy-badorg.xml index 14668315..19944603 100644 --- a/test/repositories/badfile/myorg/mymodule/ivy-badorg.xml +++ b/test/repositories/badfile/myorg/mymodule/ivy-badorg.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/badfile/myorg/mymodule/ivy-badrevision.xml b/test/repositories/badfile/myorg/mymodule/ivy-badrevision.xml index faaba1bc..c812a518 100644 --- a/test/repositories/badfile/myorg/mymodule/ivy-badrevision.xml +++ b/test/repositories/badfile/myorg/mymodule/ivy-badrevision.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/branches/bar/bar1/trunk/1/ivy.xml b/test/repositories/branches/bar/bar1/trunk/1/ivy.xml index cf930546..fa717ae1 100644 --- a/test/repositories/branches/bar/bar1/trunk/1/ivy.xml +++ b/test/repositories/branches/bar/bar1/trunk/1/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/branches/bar/bar1/trunk/2/ivy.xml b/test/repositories/branches/bar/bar1/trunk/2/ivy.xml index f06f277d..6677c6fa 100644 --- a/test/repositories/branches/bar/bar1/trunk/2/ivy.xml +++ b/test/repositories/branches/bar/bar1/trunk/2/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/branches/bar/bar1/trunk/3/ivy.xml b/test/repositories/branches/bar/bar1/trunk/3/ivy.xml index 94b27557..ae7cb157 100644 --- a/test/repositories/branches/bar/bar1/trunk/3/ivy.xml +++ b/test/repositories/branches/bar/bar1/trunk/3/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/branches/bar/bar2/trunk/1/ivy.xml b/test/repositories/branches/bar/bar2/trunk/1/ivy.xml index 43e84e05..bbf49ab1 100644 --- a/test/repositories/branches/bar/bar2/trunk/1/ivy.xml +++ b/test/repositories/branches/bar/bar2/trunk/1/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/branches/bar/bar2/trunk/2/ivy.xml b/test/repositories/branches/bar/bar2/trunk/2/ivy.xml index 458dc5d5..f923bfd3 100644 --- a/test/repositories/branches/bar/bar2/trunk/2/ivy.xml +++ b/test/repositories/branches/bar/bar2/trunk/2/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/branches/foo/foo1/branch1/2/ivy.xml b/test/repositories/branches/foo/foo1/branch1/2/ivy.xml index f5085af2..84e017b0 100644 --- a/test/repositories/branches/foo/foo1/branch1/2/ivy.xml +++ b/test/repositories/branches/foo/foo1/branch1/2/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/branches/foo/foo1/branch1/4/ivy.xml b/test/repositories/branches/foo/foo1/branch1/4/ivy.xml index 83b77312..b3785a49 100644 --- a/test/repositories/branches/foo/foo1/branch1/4/ivy.xml +++ b/test/repositories/branches/foo/foo1/branch1/4/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/branches/foo/foo1/trunk/1/ivy.xml b/test/repositories/branches/foo/foo1/trunk/1/ivy.xml index e2e71b72..602d869a 100644 --- a/test/repositories/branches/foo/foo1/trunk/1/ivy.xml +++ b/test/repositories/branches/foo/foo1/trunk/1/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/branches/foo/foo1/trunk/3/ivy.xml b/test/repositories/branches/foo/foo1/trunk/3/ivy.xml index 01d21e5f..dfba9f13 100644 --- a/test/repositories/branches/foo/foo1/trunk/3/ivy.xml +++ b/test/repositories/branches/foo/foo1/trunk/3/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/repositories/branches/ivysettings-defaultbranch1.xml b/test/repositories/branches/ivysettings-defaultbranch1.xml index 4290c6d9..a14b522e 100644 --- a/test/repositories/branches/ivysettings-defaultbranch1.xml +++ b/test/repositories/branches/ivysettings-defaultbranch1.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/branches/ivysettings-fooonbranch1.xml b/test/repositories/branches/ivysettings-fooonbranch1.xml index dfeba999..f87b0a90 100644 --- a/test/repositories/branches/ivysettings-fooonbranch1.xml +++ b/test/repositories/branches/ivysettings-fooonbranch1.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/branches/ivysettings.xml b/test/repositories/branches/ivysettings.xml index cb5cf89a..9b910f72 100644 --- a/test/repositories/branches/ivysettings.xml +++ b/test/repositories/branches/ivysettings.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/bug148/3rd/idautomation/barcode/ivy-barcode-4.10.xml b/test/repositories/bug148/3rd/idautomation/barcode/ivy-barcode-4.10.xml index bfcb7981..54a2e213 100644 --- a/test/repositories/bug148/3rd/idautomation/barcode/ivy-barcode-4.10.xml +++ b/test/repositories/bug148/3rd/idautomation/barcode/ivy-barcode-4.10.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/bug148/ivysettings.properties b/test/repositories/bug148/ivysettings.properties index aaf4f385..782466eb 100644 --- a/test/repositories/bug148/ivysettings.properties +++ b/test/repositories/bug148/ivysettings.properties @@ -1,20 +1,20 @@ -# *************************************************************** -# * 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.jtv=${ivy.settings.dir}/jtv -lib.3rd=${ivy.settings.dir}/3rd +# *************************************************************** +# * 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.jtv=${ivy.settings.dir}/jtv +lib.3rd=${ivy.settings.dir}/3rd diff --git a/test/repositories/bug148/ivysettings.xml b/test/repositories/bug148/ivysettings.xml index d3ab6e30..b65cd0e7 100644 --- a/test/repositories/bug148/ivysettings.xml +++ b/test/repositories/bug148/ivysettings.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/test/repositories/bug148/jtv/jtv-foo/bar/ivy-bar-1.1.0.0.xml b/test/repositories/bug148/jtv/jtv-foo/bar/ivy-bar-1.1.0.0.xml index 5bb7a26c..80d0d944 100644 --- a/test/repositories/bug148/jtv/jtv-foo/bar/ivy-bar-1.1.0.0.xml +++ b/test/repositories/bug148/jtv/jtv-foo/bar/ivy-bar-1.1.0.0.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/repositories/bugIVY-56/ivysettings.xml b/test/repositories/bugIVY-56/ivysettings.xml index 747f5f47..3ed51be6 100644 --- a/test/repositories/bugIVY-56/ivysettings.xml +++ b/test/repositories/bugIVY-56/ivysettings.xml @@ -1,28 +1,28 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/checkmodified/ivy-1.0-after.xml b/test/repositories/checkmodified/ivy-1.0-after.xml index 0d1e3c73..b0b10bf0 100644 --- a/test/repositories/checkmodified/ivy-1.0-after.xml +++ b/test/repositories/checkmodified/ivy-1.0-after.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/checkmodified/ivy-1.0-before.xml b/test/repositories/checkmodified/ivy-1.0-before.xml index ca12effe..d2bf3793 100644 --- a/test/repositories/checkmodified/ivy-1.0-before.xml +++ b/test/repositories/checkmodified/ivy-1.0-before.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/checksums/allright/ivy-1.0.xml b/test/repositories/checksums/allright/ivy-1.0.xml index be2da6bd..6561afaf 100644 --- a/test/repositories/checksums/allright/ivy-1.0.xml +++ b/test/repositories/checksums/allright/ivy-1.0.xml @@ -1,29 +1,29 @@ - - - - - - - - + + + + + + + + diff --git a/test/repositories/checksums/badartcs/ivy-1.0.xml b/test/repositories/checksums/badartcs/ivy-1.0.xml index ee2367b4..01001cc7 100644 --- a/test/repositories/checksums/badartcs/ivy-1.0.xml +++ b/test/repositories/checksums/badartcs/ivy-1.0.xml @@ -1,25 +1,25 @@ - - - - + + + + diff --git a/test/repositories/checksums/badivycs/ivy-1.0.xml b/test/repositories/checksums/badivycs/ivy-1.0.xml index 6080df99..49a718bd 100644 --- a/test/repositories/checksums/badivycs/ivy-1.0.xml +++ b/test/repositories/checksums/badivycs/ivy-1.0.xml @@ -1,25 +1,25 @@ - - - - + + + + diff --git a/test/repositories/circular/ivy.xml b/test/repositories/circular/ivy.xml index f6217340..f279f537 100644 --- a/test/repositories/circular/ivy.xml +++ b/test/repositories/circular/ivy.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/dual-local/xerces/xerces/ivy-2.6.2.xml b/test/repositories/dual-local/xerces/xerces/ivy-2.6.2.xml index 76b06aa1..d7a7b324 100644 --- a/test/repositories/dual-local/xerces/xerces/ivy-2.6.2.xml +++ b/test/repositories/dual-local/xerces/xerces/ivy-2.6.2.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/external-artifacts/A/ivy-1.0.xml b/test/repositories/external-artifacts/A/ivy-1.0.xml index 60d3ad17..e1481daa 100644 --- a/test/repositories/external-artifacts/A/ivy-1.0.xml +++ b/test/repositories/external-artifacts/A/ivy-1.0.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/external-artifacts/ivy.xml b/test/repositories/external-artifacts/ivy.xml index 7dac499d..0485d86a 100644 --- a/test/repositories/external-artifacts/ivy.xml +++ b/test/repositories/external-artifacts/ivy.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/external-artifacts/ivysettings.xml b/test/repositories/external-artifacts/ivysettings.xml index 95f34c30..7b9a39a3 100644 --- a/test/repositories/external-artifacts/ivysettings.xml +++ b/test/repositories/external-artifacts/ivysettings.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/repositories/extra-attributes/ivysettings.xml b/test/repositories/extra-attributes/ivysettings.xml index e32dd0f9..c559387e 100644 --- a/test/repositories/extra-attributes/ivysettings.xml +++ b/test/repositories/extra-attributes/ivysettings.xml @@ -1,32 +1,32 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml b/test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml index d28d7ba4..c78ae7bf 100644 --- a/test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml +++ b/test/repositories/extra-attributes/mymodule/task1/1854/ivy.xml @@ -1,32 +1,32 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/ivysettings-1.xml b/test/repositories/ivysettings-1.xml index d0f0b4ca..4710bde9 100644 --- a/test/repositories/ivysettings-1.xml +++ b/test/repositories/ivysettings-1.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/ivysettings-nodefaultresolver.xml b/test/repositories/ivysettings-nodefaultresolver.xml index 11def006..ff8c71f7 100644 --- a/test/repositories/ivysettings-nodefaultresolver.xml +++ b/test/repositories/ivysettings-nodefaultresolver.xml @@ -1,43 +1,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/ivysettings.properties b/test/repositories/ivysettings.properties index e1beffc1..719a79ab 100644 --- a/test/repositories/ivysettings.properties +++ b/test/repositories/ivysettings.properties @@ -1,24 +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.publish.src.artifacts.pattern=${build}/[artifact]-[revision].[ext] -cache.dir=build/cache -vfs.host= -vfs.user= -vfs.passwd= -vfs.samba.share= +# *************************************************************** +# * 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.publish.src.artifacts.pattern=${build}/[artifact]-[revision].[ext] +cache.dir=build/cache +vfs.host= +vfs.user= +vfs.passwd= +vfs.samba.share= diff --git a/test/repositories/ivysettings.xml b/test/repositories/ivysettings.xml index bc40eb22..96a7e538 100644 --- a/test/repositories/ivysettings.xml +++ b/test/repositories/ivysettings.xml @@ -1,43 +1,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/m2/ivysettings.xml b/test/repositories/m2/ivysettings.xml index f728b17a..3a612ee8 100644 --- a/test/repositories/m2/ivysettings.xml +++ b/test/repositories/m2/ivysettings.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0.pom b/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0.pom index 967303ba..9403a5b8 100644 --- a/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0.pom +++ b/test/repositories/m2/org/apache/test-classified/1.0/test-classified-1.0.pom @@ -1,31 +1,31 @@ - - - - 4.0.0 - org.apache - test-classified - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - + + + + 4.0.0 + org.apache + test-classified + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + diff --git a/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom b/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom index 7fb2fbfc..f0e41f5c 100644 --- a/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom +++ b/test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom @@ -1,39 +1,39 @@ - - - - 4.0.0 - org.apache - test-classifier - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - org.apache - test-classified - 1.0 - asl - - - + + + + 4.0.0 + org.apache + test-classifier + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + org.apache + test-classified + 1.0 + asl + + + diff --git a/test/repositories/m2/org/apache/test-version/1.0/test-version-1.0.pom b/test/repositories/m2/org/apache/test-version/1.0/test-version-1.0.pom index ae26494c..9ae01ec5 100644 --- a/test/repositories/m2/org/apache/test-version/1.0/test-version-1.0.pom +++ b/test/repositories/m2/org/apache/test-version/1.0/test-version-1.0.pom @@ -1,38 +1,38 @@ - - - - 4.0.0 - org.apache - test-version - Test Module for Ivy M2 parsing - 1.0 - http://incubator.apache.org/ivy - - Apache - http://www.apache.org/ - - - - org.apache - test-classifier - ${version} - - - + + + + 4.0.0 + org.apache + test-version + Test Module for Ivy M2 parsing + 1.0 + http://incubator.apache.org/ivy + + Apache + http://www.apache.org/ + + + + org.apache + test-classifier + ${version} + + + diff --git a/test/repositories/m2/org/apache/test/1.0/test-1.0.pom b/test/repositories/m2/org/apache/test/1.0/test-1.0.pom index 310d2869..6c77b493 100644 --- a/test/repositories/m2/org/apache/test/1.0/test-1.0.pom +++ b/test/repositories/m2/org/apache/test/1.0/test-1.0.pom @@ -1,31 +1,31 @@ - - - - 4.0.0 - org.apache - test - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - + + + + 4.0.0 + org.apache + test + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + diff --git a/test/repositories/m2/org/apache/test2/1.0/test2-1.0.pom b/test/repositories/m2/org/apache/test2/1.0/test2-1.0.pom index f7c093bd..5c0424fb 100644 --- a/test/repositories/m2/org/apache/test2/1.0/test2-1.0.pom +++ b/test/repositories/m2/org/apache/test2/1.0/test2-1.0.pom @@ -1,38 +1,38 @@ - - - - 4.0.0 - org.apache - test2 - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - org.apache - test - 1.0 - - - + + + + 4.0.0 + org.apache + test2 + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + org.apache + test + 1.0 + + + diff --git a/test/repositories/m2/org/apache/test3/1.0/test3-1.0.pom b/test/repositories/m2/org/apache/test3/1.0/test3-1.0.pom index c07b7aa8..8f807a15 100644 --- a/test/repositories/m2/org/apache/test3/1.0/test3-1.0.pom +++ b/test/repositories/m2/org/apache/test3/1.0/test3-1.0.pom @@ -1,38 +1,38 @@ - - - - 4.0.0 - org.apache - test3 - Test Module for Ivy M2 parsing - 1.0 - http://ivy.jayasoft.org/ - - Jayasoft - http://www.jayasoft.org/ - - - - org.apache - test2 - 1.0 - - - + + + + 4.0.0 + org.apache + test3 + Test Module for Ivy M2 parsing + 1.0 + http://ivy.jayasoft.org/ + + Jayasoft + http://www.jayasoft.org/ + + + + org.apache + test2 + 1.0 + + + diff --git a/test/repositories/multi-ivypattern/ivy1/ivy-1.0.xml b/test/repositories/multi-ivypattern/ivy1/ivy-1.0.xml index 6ee65735..d11a5287 100644 --- a/test/repositories/multi-ivypattern/ivy1/ivy-1.0.xml +++ b/test/repositories/multi-ivypattern/ivy1/ivy-1.0.xml @@ -1,27 +1,27 @@ - - - - - + + + + + diff --git a/test/repositories/multi-ivypattern/ivy2/ivy-1.1.xml b/test/repositories/multi-ivypattern/ivy2/ivy-1.1.xml index dfb9c65f..b2f3feec 100644 --- a/test/repositories/multi-ivypattern/ivy2/ivy-1.1.xml +++ b/test/repositories/multi-ivypattern/ivy2/ivy-1.1.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/multi-ivypattern/ivysettings.xml b/test/repositories/multi-ivypattern/ivysettings.xml index 5063855c..89aa7df8 100644 --- a/test/repositories/multi-ivypattern/ivysettings.xml +++ b/test/repositories/multi-ivypattern/ivysettings.xml @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/test/repositories/multirevisions/ivy.xml b/test/repositories/multirevisions/ivy.xml index 74fb5854..457bf648 100644 --- a/test/repositories/multirevisions/ivy.xml +++ b/test/repositories/multirevisions/ivy.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/test/repositories/multirevisions/ivy/moduleX-1.0.xml b/test/repositories/multirevisions/ivy/moduleX-1.0.xml index dbe3578d..aa14ab8d 100644 --- a/test/repositories/multirevisions/ivy/moduleX-1.0.xml +++ b/test/repositories/multirevisions/ivy/moduleX-1.0.xml @@ -1,26 +1,26 @@ - - - - + + + + diff --git a/test/repositories/multirevisions/ivy/moduleX-2.0.xml b/test/repositories/multirevisions/ivy/moduleX-2.0.xml index 12127d01..c7f69ebb 100644 --- a/test/repositories/multirevisions/ivy/moduleX-2.0.xml +++ b/test/repositories/multirevisions/ivy/moduleX-2.0.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/multirevisions/ivy/moduleZ-1.0.xml b/test/repositories/multirevisions/ivy/moduleZ-1.0.xml index 7bec406a..1fcdc7c2 100644 --- a/test/repositories/multirevisions/ivy/moduleZ-1.0.xml +++ b/test/repositories/multirevisions/ivy/moduleZ-1.0.xml @@ -1,32 +1,32 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/multirevisions/ivysettings.xml b/test/repositories/multirevisions/ivysettings.xml index 789ef25a..d2163de7 100644 --- a/test/repositories/multirevisions/ivysettings.xml +++ b/test/repositories/multirevisions/ivysettings.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/namespace/A/A/1.0/ivy.xml b/test/repositories/namespace/A/A/1.0/ivy.xml index c9cdb60b..1f349de0 100644 --- a/test/repositories/namespace/A/A/1.0/ivy.xml +++ b/test/repositories/namespace/A/A/1.0/ivy.xml @@ -1,26 +1,26 @@ - - - - + + + + diff --git a/test/repositories/namespace/A/B/1.0/ivy.xml b/test/repositories/namespace/A/B/1.0/ivy.xml index 5c33bf1b..44929b0a 100644 --- a/test/repositories/namespace/A/B/1.0/ivy.xml +++ b/test/repositories/namespace/A/B/1.0/ivy.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/namespace/B/1/1.0/1-1.0.pom b/test/repositories/namespace/B/1/1.0/1-1.0.pom index c58efca4..2989de5a 100644 --- a/test/repositories/namespace/B/1/1.0/1-1.0.pom +++ b/test/repositories/namespace/B/1/1.0/1-1.0.pom @@ -1,25 +1,25 @@ - - - - 4.0.0 - B - 1 - 1.0 - + + + + 4.0.0 + B + 1 + 1.0 + diff --git a/test/repositories/namespace/B/2/1.0/2-1.0.pom b/test/repositories/namespace/B/2/1.0/2-1.0.pom index 9a401358..2d2502f0 100644 --- a/test/repositories/namespace/B/2/1.0/2-1.0.pom +++ b/test/repositories/namespace/B/2/1.0/2-1.0.pom @@ -1,107 +1,107 @@ - - - - 4.0.0 - B - 2 - Test Module for Ivy M2 parsing - 1.0 - Here comes a description of this test module - 2001 - - - dlr - Daniel Rall - dlr@finemaltcoding.com - CollabNet, Inc. - - Java Developer - - - - scolebourne - Stephen Colebourne - scolebourne@joda.org - SITA ATS Ltd - - Java Developer - - - - bayard - Henri Yandell - bayard@generationjava.com - - - Java Developer - - - - - Steven Caswell - steven@caswell.name - - - Java Developer - - - - - - Ringo De Smet - ringods@yahoo.co.uk - - - Java Developer - - - - Steve Downey - steve.downey@netfolio.com - - - Java Developer - - - - - - - maven-surefire-plugin - - - **/*Test.java - **/*TestCase.java - - - **/Abstract*.java - - - - - - - - B - 1 - 1.0 - - - + + + + 4.0.0 + B + 2 + Test Module for Ivy M2 parsing + 1.0 + Here comes a description of this test module + 2001 + + + dlr + Daniel Rall + dlr@finemaltcoding.com + CollabNet, Inc. + + Java Developer + + + + scolebourne + Stephen Colebourne + scolebourne@joda.org + SITA ATS Ltd + + Java Developer + + + + bayard + Henri Yandell + bayard@generationjava.com + + + Java Developer + + + + + Steven Caswell + steven@caswell.name + + + Java Developer + + + + + + Ringo De Smet + ringods@yahoo.co.uk + + + Java Developer + + + + Steve Downey + steve.downey@netfolio.com + + + Java Developer + + + + + + + maven-surefire-plugin + + + **/*Test.java + **/*TestCase.java + + + **/Abstract*.java + + + + + + + + B + 1 + 1.0 + + + diff --git a/test/repositories/namespace/ivysettings.xml b/test/repositories/namespace/ivysettings.xml index 99e0c8e5..7d60bba7 100644 --- a/test/repositories/namespace/ivysettings.xml +++ b/test/repositories/namespace/ivysettings.xml @@ -1,72 +1,72 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/repositories/norev/ivy.xml b/test/repositories/norev/ivy.xml index 6635719b..7b929c3b 100644 --- a/test/repositories/norev/ivy.xml +++ b/test/repositories/norev/ivy.xml @@ -1,27 +1,27 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/test/repositories/norev/ivysettings.xml b/test/repositories/norev/ivysettings.xml index 8ff8992a..c2d558bb 100644 --- a/test/repositories/norev/ivysettings.xml +++ b/test/repositories/norev/ivysettings.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/test/repositories/norev/module2/ivy.xml b/test/repositories/norev/module2/ivy.xml index fd430cc1..b6e951e3 100644 --- a/test/repositories/norev/module2/ivy.xml +++ b/test/repositories/norev/module2/ivy.xml @@ -1,24 +1,24 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/norevision/ivy-mod1.1-after.xml b/test/repositories/norevision/ivy-mod1.1-after.xml index 5d86be53..4a499571 100644 --- a/test/repositories/norevision/ivy-mod1.1-after.xml +++ b/test/repositories/norevision/ivy-mod1.1-after.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/repositories/norevision/ivy-mod1.1-before.xml b/test/repositories/norevision/ivy-mod1.1-before.xml index ca12effe..d2bf3793 100644 --- a/test/repositories/norevision/ivy-mod1.1-before.xml +++ b/test/repositories/norevision/ivy-mod1.1-before.xml @@ -1,29 +1,29 @@ - - - - - - - + + + + + + + diff --git a/test/triggers/ant-build/A/build.xml b/test/triggers/ant-build/A/build.xml index 771c0344..6aa6933f 100644 --- a/test/triggers/ant-build/A/build.xml +++ b/test/triggers/ant-build/A/build.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/test/triggers/ant-build/A/ivy.xml b/test/triggers/ant-build/A/ivy.xml index 846423e7..3dc77117 100644 --- a/test/triggers/ant-build/A/ivy.xml +++ b/test/triggers/ant-build/A/ivy.xml @@ -1,21 +1,21 @@ - - - - + + + + diff --git a/test/triggers/ant-build/B/ivy.xml b/test/triggers/ant-build/B/ivy.xml index b737d1a9..03146415 100644 --- a/test/triggers/ant-build/B/ivy.xml +++ b/test/triggers/ant-build/B/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/triggers/ant-build/ivysettings.xml b/test/triggers/ant-build/ivysettings.xml index 3db7593c..dfa5be85 100644 --- a/test/triggers/ant-build/ivysettings.xml +++ b/test/triggers/ant-build/ivysettings.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/triggers/ant-call/A/build.xml b/test/triggers/ant-call/A/build.xml index 59697bb8..3a2db5d7 100644 --- a/test/triggers/ant-call/A/build.xml +++ b/test/triggers/ant-call/A/build.xml @@ -1,45 +1,45 @@ - - - - - - - - - - - - unzipping artifact: - organisation=${dep.organisation} - module=${dep.module} - revision=${dep.revision} - artifact=${dep.artifact} - type=${dep.type} - ext=${dep.ext} - origin=${dep.origin} - local=${dep.local} - size=${dep.size} - file=${dep.file} - - - - - + + + + + + + + + + + + unzipping artifact: + organisation=${dep.organisation} + module=${dep.module} + revision=${dep.revision} + artifact=${dep.artifact} + type=${dep.type} + ext=${dep.ext} + origin=${dep.origin} + local=${dep.local} + size=${dep.size} + file=${dep.file} + + + + + diff --git a/test/triggers/ant-call/A/ivy.xml b/test/triggers/ant-call/A/ivy.xml index 075f4cc2..b9501900 100644 --- a/test/triggers/ant-call/A/ivy.xml +++ b/test/triggers/ant-call/A/ivy.xml @@ -1,25 +1,25 @@ - - - - - - - - + + + + + + + + diff --git a/test/triggers/ant-call/ivysettings.xml b/test/triggers/ant-call/ivysettings.xml index 07496baf..4fcee798 100644 --- a/test/triggers/ant-call/ivysettings.xml +++ b/test/triggers/ant-call/ivysettings.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/test/triggers/ant-call/local/foo/ivy.xml b/test/triggers/ant-call/local/foo/ivy.xml index a61b547f..0c743487 100644 --- a/test/triggers/ant-call/local/foo/ivy.xml +++ b/test/triggers/ant-call/local/foo/ivy.xml @@ -1,26 +1,26 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/xsl/test.xml b/test/xsl/test.xml index 25262e22..58fe3f02 100644 --- a/test/xsl/test.xml +++ b/test/xsl/test.xml @@ -1,88 +1,88 @@ - - - - - - - - - This module is great !
      - You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too.
      - And you can even use xhtml in this description. -
      -
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      + + + + + + + + + This module is great !
      + You can use it especially with myconf1 and myconf2, and myconf4 is not too bad too.
      + And you can even use xhtml in this description. +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      diff --git a/version.properties b/version.properties index 828c6b86..b83e5f56 100644 --- a/version.properties +++ b/version.properties @@ -1,20 +1,20 @@ -# *************************************************************** -# * 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. -# *************************************************************** -target.ivy.version=2.0.0-alpha-1-incubating -target.ivy.bundle.version=2.0.0.alpha1 +# *************************************************************** +# * 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. +# *************************************************************** +target.ivy.version=2.0.0-alpha-1-incubating +target.ivy.bundle.version=2.0.0.alpha1