Source Code Cross Referenced for IvySettings.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » core » settings » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » apache ivy » org.apache.ivy.core.settings 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *      http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         *
0017:         */
0018:        package org.apache.ivy.core.settings;
0019:
0020:        import java.io.File;
0021:        import java.io.FileInputStream;
0022:        import java.io.FileNotFoundException;
0023:        import java.io.IOException;
0024:        import java.io.InputStream;
0025:        import java.lang.reflect.Field;
0026:        import java.net.MalformedURLException;
0027:        import java.net.URL;
0028:        import java.net.URLClassLoader;
0029:        import java.text.ParseException;
0030:        import java.util.ArrayList;
0031:        import java.util.Collection;
0032:        import java.util.HashMap;
0033:        import java.util.Iterator;
0034:        import java.util.List;
0035:        import java.util.Map;
0036:        import java.util.Properties;
0037:
0038:        import org.apache.ivy.Ivy;
0039:        import org.apache.ivy.core.IvyPatternHelper;
0040:        import org.apache.ivy.core.NormalRelativeUrlResolver;
0041:        import org.apache.ivy.core.RelativeUrlResolver;
0042:        import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
0043:        import org.apache.ivy.core.cache.DefaultResolutionCacheManager;
0044:        import org.apache.ivy.core.cache.RepositoryCacheManager;
0045:        import org.apache.ivy.core.cache.ResolutionCacheManager;
0046:        import org.apache.ivy.core.check.CheckEngineSettings;
0047:        import org.apache.ivy.core.deliver.DeliverEngineSettings;
0048:        import org.apache.ivy.core.install.InstallEngineSettings;
0049:        import org.apache.ivy.core.module.id.ModuleId;
0050:        import org.apache.ivy.core.module.id.ModuleRevisionId;
0051:        import org.apache.ivy.core.module.id.ModuleRules;
0052:        import org.apache.ivy.core.module.status.StatusManager;
0053:        import org.apache.ivy.core.publish.PublishEngineSettings;
0054:        import org.apache.ivy.core.repository.RepositoryManagementEngineSettings;
0055:        import org.apache.ivy.core.resolve.ResolveEngineSettings;
0056:        import org.apache.ivy.core.retrieve.RetrieveEngineSettings;
0057:        import org.apache.ivy.core.sort.SortEngineSettings;
0058:        import org.apache.ivy.plugins.IvySettingsAware;
0059:        import org.apache.ivy.plugins.circular.CircularDependencyStrategy;
0060:        import org.apache.ivy.plugins.circular.ErrorCircularDependencyStrategy;
0061:        import org.apache.ivy.plugins.circular.IgnoreCircularDependencyStrategy;
0062:        import org.apache.ivy.plugins.circular.WarnCircularDependencyStrategy;
0063:        import org.apache.ivy.plugins.conflict.ConflictManager;
0064:        import org.apache.ivy.plugins.conflict.LatestCompatibleConflictManager;
0065:        import org.apache.ivy.plugins.conflict.LatestConflictManager;
0066:        import org.apache.ivy.plugins.conflict.NoConflictManager;
0067:        import org.apache.ivy.plugins.conflict.StrictConflictManager;
0068:        import org.apache.ivy.plugins.latest.LatestLexicographicStrategy;
0069:        import org.apache.ivy.plugins.latest.LatestRevisionStrategy;
0070:        import org.apache.ivy.plugins.latest.LatestStrategy;
0071:        import org.apache.ivy.plugins.latest.LatestTimeStrategy;
0072:        import org.apache.ivy.plugins.lock.ArtifactLockStrategy;
0073:        import org.apache.ivy.plugins.lock.LockStrategy;
0074:        import org.apache.ivy.plugins.lock.NoLockStrategy;
0075:        import org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher;
0076:        import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
0077:        import org.apache.ivy.plugins.matcher.MapMatcher;
0078:        import org.apache.ivy.plugins.matcher.PatternMatcher;
0079:        import org.apache.ivy.plugins.matcher.RegexpPatternMatcher;
0080:        import org.apache.ivy.plugins.namespace.Namespace;
0081:        import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
0082:        import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry;
0083:        import org.apache.ivy.plugins.parser.ParserSettings;
0084:        import org.apache.ivy.plugins.report.LogReportOutputter;
0085:        import org.apache.ivy.plugins.report.ReportOutputter;
0086:        import org.apache.ivy.plugins.report.XmlReportOutputter;
0087:        import org.apache.ivy.plugins.resolver.ChainResolver;
0088:        import org.apache.ivy.plugins.resolver.DependencyResolver;
0089:        import org.apache.ivy.plugins.resolver.DualResolver;
0090:        import org.apache.ivy.plugins.resolver.ResolverSettings;
0091:        import org.apache.ivy.plugins.trigger.Trigger;
0092:        import org.apache.ivy.plugins.version.ChainVersionMatcher;
0093:        import org.apache.ivy.plugins.version.ExactVersionMatcher;
0094:        import org.apache.ivy.plugins.version.LatestVersionMatcher;
0095:        import org.apache.ivy.plugins.version.SubVersionMatcher;
0096:        import org.apache.ivy.plugins.version.VersionMatcher;
0097:        import org.apache.ivy.plugins.version.VersionRangeMatcher;
0098:        import org.apache.ivy.util.Message;
0099:        import org.apache.ivy.util.filter.Filter;
0100:        import org.apache.ivy.util.url.URLHandlerRegistry;
0101:
0102:        public class IvySettings implements  SortEngineSettings,
0103:                PublishEngineSettings, ParserSettings, DeliverEngineSettings,
0104:                CheckEngineSettings, InstallEngineSettings, ResolverSettings,
0105:                ResolveEngineSettings, RetrieveEngineSettings,
0106:                RepositoryManagementEngineSettings {
0107:            private static final long INTERUPT_TIMEOUT = 2000;
0108:
0109:            private Map typeDefs = new HashMap();
0110:
0111:            private Map resolversMap = new HashMap();
0112:
0113:            private DependencyResolver defaultResolver;
0114:
0115:            private DependencyResolver dictatorResolver = null;
0116:
0117:            private String defaultResolverName;
0118:
0119:            private File defaultCache;
0120:
0121:            private String defaultBranch = null;
0122:
0123:            private boolean checkUpToDate = true;
0124:
0125:            private ModuleRules moduleSettings = new ModuleRules();
0126:
0127:            // Map (String conflictManagerName -> ConflictManager)
0128:            private Map conflictsManager = new HashMap();
0129:
0130:            // Map (String latestStrategyName -> LatestStrategy)
0131:            private Map latestStrategies = new HashMap();
0132:
0133:            // Map (String name -> LockStrategy)
0134:            private Map lockStrategies = new HashMap();
0135:
0136:            // Map (String namespaceName -> Namespace)
0137:            private Map namespaces = new HashMap();
0138:
0139:            // Map (String matcherName -> Matcher)
0140:            private Map matchers = new HashMap();
0141:
0142:            // Map (String outputterName -> ReportOutputter)
0143:            private Map reportOutputters = new HashMap();
0144:
0145:            // Map (String matcherName -> VersionMatcher)
0146:            private Map versionMatchers = new HashMap();
0147:
0148:            // Map (String name -> CircularDependencyStrategy)
0149:            private Map circularDependencyStrategies = new HashMap();
0150:
0151:            // Map (String name -> RepositoryCacheManager)
0152:            private Map repositoryCacheManagers = new HashMap();
0153:
0154:            // List (Trigger)
0155:            private List triggers = new ArrayList();
0156:
0157:            private IvyVariableContainer variableContainer = new IvyVariableContainerImpl();
0158:
0159:            private boolean validate = true;
0160:
0161:            private LatestStrategy defaultLatestStrategy = null;
0162:
0163:            private LockStrategy defaultLockStrategy = null;
0164:
0165:            private ConflictManager defaultConflictManager = null;
0166:
0167:            private CircularDependencyStrategy circularDependencyStrategy = null;
0168:
0169:            private RepositoryCacheManager defaultRepositoryCacheManager = null;
0170:
0171:            private ResolutionCacheManager resolutionCacheManager = null;
0172:
0173:            private List listingIgnore = new ArrayList();
0174:
0175:            private boolean repositoriesConfigured;
0176:
0177:            private boolean useRemoteConfig = false;
0178:
0179:            private File defaultUserDir;
0180:
0181:            private List classpathURLs = new ArrayList();
0182:
0183:            private ClassLoader classloader;
0184:
0185:            private Boolean debugConflictResolution;
0186:
0187:            private boolean logNotConvertedExclusionRule;
0188:
0189:            private VersionMatcher versionMatcher;
0190:
0191:            private StatusManager statusManager;
0192:
0193:            private Boolean debugLocking;
0194:
0195:            private Boolean dumpMemoryUsage;
0196:
0197:            private String defaultCacheIvyPattern;
0198:
0199:            private String defaultCacheArtifactPattern;
0200:
0201:            private boolean defaultUseOrigin;
0202:
0203:            public IvySettings() {
0204:                this (new IvyVariableContainerImpl());
0205:            }
0206:
0207:            public IvySettings(IvyVariableContainer variableContainer) {
0208:                setVariableContainer(variableContainer);
0209:                setVariable("ivy.default.settings.dir",
0210:                        getDefaultSettingsDir(), true);
0211:                setDeprecatedVariable("ivy.default.conf.dir",
0212:                        "ivy.default.settings.dir");
0213:
0214:                String ivyTypeDefs = System.getProperty("ivy.typedef.files");
0215:                if (ivyTypeDefs != null) {
0216:                    String[] files = ivyTypeDefs.split("\\,");
0217:                    for (int i = 0; i < files.length; i++) {
0218:                        try {
0219:                            typeDefs(new FileInputStream(new File(files[i]
0220:                                    .trim())), true);
0221:                        } catch (FileNotFoundException e) {
0222:                            Message.warn("typedefs file not found: "
0223:                                    + files[i].trim());
0224:                        } catch (IOException e) {
0225:                            Message.warn("problem with typedef file: "
0226:                                    + files[i].trim() + ": " + e.getMessage());
0227:                        }
0228:                    }
0229:                } else {
0230:                    try {
0231:                        typeDefs(getSettingsURL("typedef.properties")
0232:                                .openStream(), true);
0233:                    } catch (IOException e) {
0234:                        Message.warn("impossible to load default type defs");
0235:                    }
0236:                }
0237:                LatestLexicographicStrategy latestLexicographicStrategy = new LatestLexicographicStrategy();
0238:                LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy();
0239:                LatestTimeStrategy latestTimeStrategy = new LatestTimeStrategy();
0240:
0241:                addLatestStrategy("latest-revision", latestRevisionStrategy);
0242:                addLatestStrategy("latest-lexico", latestLexicographicStrategy);
0243:                addLatestStrategy("latest-time", latestTimeStrategy);
0244:
0245:                addLockStrategy("no-lock", new NoLockStrategy());
0246:                addLockStrategy("artifact-lock", new ArtifactLockStrategy(
0247:                        debugLocking()));
0248:
0249:                addConflictManager("latest-revision",
0250:                        new LatestConflictManager("latest-revision",
0251:                                latestRevisionStrategy));
0252:                addConflictManager("latest-compatible",
0253:                        new LatestCompatibleConflictManager(
0254:                                "latest-compatible", latestRevisionStrategy));
0255:                addConflictManager("latest-time", new LatestConflictManager(
0256:                        "latest-time", latestTimeStrategy));
0257:                addConflictManager("all", new NoConflictManager());
0258:                addConflictManager("strict", new StrictConflictManager());
0259:
0260:                addMatcher(ExactPatternMatcher.INSTANCE);
0261:                addMatcher(RegexpPatternMatcher.INSTANCE);
0262:                addMatcher(ExactOrRegexpPatternMatcher.INSTANCE);
0263:
0264:                try {
0265:                    // GlobPatternMatcher is optional. Only add it when available.
0266:                    Class globClazz = IvySettings.class
0267:                            .getClassLoader()
0268:                            .loadClass(
0269:                                    "org.apache.ivy.plugins.matcher.GlobPatternMatcher");
0270:                    Field instanceField = globClazz.getField("INSTANCE");
0271:                    addMatcher((PatternMatcher) instanceField.get(null));
0272:                } catch (Exception e) {
0273:                    // ignore: the matcher isn't on the classpath
0274:                    Message
0275:                            .info("impossible to define glob matcher: "
0276:                                    + "org.apache.ivy.plugins.matcher.GlobPatternMatcher was not found.");
0277:                }
0278:
0279:                addReportOutputter(new LogReportOutputter());
0280:                addReportOutputter(new XmlReportOutputter());
0281:
0282:                configureDefaultCircularDependencyStrategies();
0283:
0284:                listingIgnore.add(".cvsignore");
0285:                listingIgnore.add("CVS");
0286:                listingIgnore.add(".svn");
0287:
0288:                addSystemProperties();
0289:            }
0290:
0291:            private void addSystemProperties() {
0292:                addAllVariables(System.getProperties());
0293:            }
0294:
0295:            /**
0296:             * Call this method to ask ivy to configure some variables using either a remote or a local
0297:             * properties file
0298:             */
0299:            public void configureRepositories(boolean remote) {
0300:                if (!repositoriesConfigured) {
0301:                    Properties props = new Properties();
0302:                    boolean configured = false;
0303:                    if (useRemoteConfig && remote) {
0304:                        try {
0305:                            URL url = new URL(
0306:                                    "http://ant.apache.org/ivy/repository.properties");
0307:                            Message.verbose("configuring repositories with "
0308:                                    + url);
0309:                            props.load(URLHandlerRegistry.getDefault()
0310:                                    .openStream(url));
0311:                            configured = true;
0312:                        } catch (Exception ex) {
0313:                            Message
0314:                                    .verbose("unable to use remote repository configuration: "
0315:                                            + ex.getMessage());
0316:                            props = new Properties();
0317:                        }
0318:                    }
0319:                    if (!configured) {
0320:                        InputStream repositoryPropsStream = null;
0321:                        try {
0322:                            repositoryPropsStream = getSettingsURL(
0323:                                    "repository.properties").openStream();
0324:                            props.load(repositoryPropsStream);
0325:                        } catch (IOException e) {
0326:                            Message
0327:                                    .error("unable to use internal repository configuration: "
0328:                                            + e.getMessage());
0329:                            if (repositoryPropsStream != null) {
0330:                                try {
0331:                                    repositoryPropsStream.close();
0332:                                } catch (Exception ex) {
0333:                                    //nothing to do
0334:                                }
0335:                            }
0336:                        }
0337:                    }
0338:                    addAllVariables(props, false);
0339:                    repositoriesConfigured = true;
0340:                }
0341:            }
0342:
0343:            public void typeDefs(InputStream stream) throws IOException {
0344:                typeDefs(stream, false);
0345:            }
0346:
0347:            public void typeDefs(InputStream stream, boolean silentFail)
0348:                    throws IOException {
0349:                try {
0350:                    Properties p = new Properties();
0351:                    p.load(stream);
0352:                    typeDefs(p, silentFail);
0353:                } finally {
0354:                    stream.close();
0355:                }
0356:            }
0357:
0358:            public void typeDefs(Properties p) {
0359:                typeDefs(p, false);
0360:            }
0361:
0362:            public void typeDefs(Properties p, boolean silentFail) {
0363:                for (Iterator iter = p.keySet().iterator(); iter.hasNext();) {
0364:                    String name = (String) iter.next();
0365:                    typeDef(name, p.getProperty(name), silentFail);
0366:                }
0367:            }
0368:
0369:            public void load(File settingsFile) throws ParseException,
0370:                    IOException {
0371:                Message.info(":: loading settings :: file = " + settingsFile);
0372:                long start = System.currentTimeMillis();
0373:                setSettingsVariables(settingsFile);
0374:                if (getVariable("ivy.default.ivy.user.dir") != null) {
0375:                    setDefaultIvyUserDir(new File(
0376:                            getVariable("ivy.default.ivy.user.dir")));
0377:                } else {
0378:                    getDefaultIvyUserDir();
0379:                }
0380:                getDefaultCache();
0381:
0382:                loadDefaultProperties();
0383:                try {
0384:                    new XmlSettingsParser(this ).parse(settingsFile.toURL());
0385:                } catch (MalformedURLException e) {
0386:                    IllegalArgumentException iae = new IllegalArgumentException(
0387:                            "given file cannot be transformed to url: "
0388:                                    + settingsFile);
0389:                    iae.initCause(e);
0390:                    throw iae;
0391:                }
0392:                setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir()
0393:                        .getAbsolutePath(), false);
0394:                Message.verbose("settings loaded ("
0395:                        + (System.currentTimeMillis() - start) + "ms)");
0396:                dumpSettings();
0397:            }
0398:
0399:            public void load(URL settingsURL) throws ParseException,
0400:                    IOException {
0401:                Message.info(":: loading settings :: url = " + settingsURL);
0402:                long start = System.currentTimeMillis();
0403:                setSettingsVariables(settingsURL);
0404:                if (getVariable("ivy.default.ivy.user.dir") != null) {
0405:                    setDefaultIvyUserDir(new File(
0406:                            getVariable("ivy.default.ivy.user.dir")));
0407:                } else {
0408:                    getDefaultIvyUserDir();
0409:                }
0410:                getDefaultCache();
0411:
0412:                loadDefaultProperties();
0413:                new XmlSettingsParser(this ).parse(settingsURL);
0414:                setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir()
0415:                        .getAbsolutePath(), false);
0416:                Message.verbose("settings loaded ("
0417:                        + (System.currentTimeMillis() - start) + "ms)");
0418:                dumpSettings();
0419:            }
0420:
0421:            /**
0422:             * Default initialization of settings, useful when you don't want to load your settings from a
0423:             * settings file or URL, but prefer to set them manually. By calling this method you will still
0424:             * have the basic initialization done when loading settings.
0425:             * 
0426:             * @throws IOException
0427:             */
0428:            public void defaultInit() throws IOException {
0429:                if (getVariable("ivy.default.ivy.user.dir") != null) {
0430:                    setDefaultIvyUserDir(new File(
0431:                            getVariable("ivy.default.ivy.user.dir")));
0432:                } else {
0433:                    getDefaultIvyUserDir();
0434:                }
0435:                getDefaultCache();
0436:
0437:                loadDefaultProperties();
0438:                setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir()
0439:                        .getAbsolutePath(), false);
0440:                dumpSettings();
0441:            }
0442:
0443:            public void loadDefault() throws ParseException, IOException {
0444:                load(getDefaultSettingsURL());
0445:            }
0446:
0447:            public void loadDefault14() throws ParseException, IOException {
0448:                load(getDefault14SettingsURL());
0449:            }
0450:
0451:            private void loadDefaultProperties() throws IOException {
0452:                loadProperties(getDefaultPropertiesURL(), false);
0453:            }
0454:
0455:            public static URL getDefaultPropertiesURL() {
0456:                return getSettingsURL("ivy.properties");
0457:            }
0458:
0459:            public static URL getDefaultSettingsURL() {
0460:                return getSettingsURL("ivysettings.xml");
0461:            }
0462:
0463:            public static URL getDefault14SettingsURL() {
0464:                return getSettingsURL("ivysettings-1.4.xml");
0465:            }
0466:
0467:            private String getDefaultSettingsDir() {
0468:                String ivysettingsLocation = getDefaultSettingsURL()
0469:                        .toExternalForm();
0470:                return ivysettingsLocation.substring(0, ivysettingsLocation
0471:                        .length()
0472:                        - "ivysettings.xml".length() - 1);
0473:            }
0474:
0475:            private static URL getSettingsURL(String file) {
0476:                return XmlSettingsParser.class.getResource(file);
0477:            }
0478:
0479:            public void setSettingsVariables(File settingsFile) {
0480:                try {
0481:                    setVariable("ivy.settings.dir", new File(settingsFile
0482:                            .getAbsolutePath()).getParent());
0483:                    setDeprecatedVariable("ivy.conf.dir", "ivy.settings.dir");
0484:                    setVariable("ivy.settings.file", settingsFile
0485:                            .getAbsolutePath());
0486:                    setDeprecatedVariable("ivy.conf.file", "ivy.settings.file");
0487:                    setVariable("ivy.settings.url", settingsFile.toURL()
0488:                            .toExternalForm());
0489:                    setDeprecatedVariable("ivy.conf.url", "ivy.settings.url");
0490:                } catch (MalformedURLException e) {
0491:                    IllegalArgumentException iae = new IllegalArgumentException(
0492:                            "given file cannot be transformed to url: "
0493:                                    + settingsFile);
0494:                    iae.initCause(e);
0495:                    throw iae;
0496:                }
0497:            }
0498:
0499:            /**
0500:             * Sets a deprecated variable with the value of the new variable
0501:             * 
0502:             * @param deprecatedKey
0503:             *            the deprecated variable name
0504:             * @param newKey
0505:             *            the new variable name
0506:             */
0507:            private void setDeprecatedVariable(String deprecatedKey,
0508:                    String newKey) {
0509:                setVariable(deprecatedKey, getVariable(newKey));
0510:            }
0511:
0512:            public void setSettingsVariables(URL settingsURL) {
0513:                String settingsURLStr = settingsURL.toExternalForm();
0514:                setVariable("ivy.settings.url", settingsURLStr);
0515:                setDeprecatedVariable("ivy.conf.url", "ivy.settings.url");
0516:                int slashIndex = settingsURLStr.lastIndexOf('/');
0517:                if (slashIndex != -1) {
0518:                    setVariable("ivy.settings.dir", settingsURLStr.substring(0,
0519:                            slashIndex));
0520:                    setDeprecatedVariable("ivy.conf.dir", "ivy.settings.dir");
0521:                } else {
0522:                    Message
0523:                            .warn("settings url does not contain any slash (/): "
0524:                                    + "ivy.settings.dir variable not set");
0525:                }
0526:            }
0527:
0528:            private void dumpSettings() {
0529:                Message.verbose("\tdefault cache: " + getDefaultCache());
0530:                Message.verbose("\tdefault resolver: " + getDefaultResolver());
0531:                Message.debug("\tdefault latest strategy: "
0532:                        + getDefaultLatestStrategy());
0533:                Message.debug("\tdefault conflict manager: "
0534:                        + getDefaultConflictManager());
0535:                Message.debug("\tcircular dependency strategy: "
0536:                        + getCircularDependencyStrategy());
0537:                Message.debug("\tvalidate: " + doValidate());
0538:                Message.debug("\tcheck up2date: " + isCheckUpToDate());
0539:
0540:                if (!classpathURLs.isEmpty()) {
0541:                    Message.verbose("\t-- " + classpathURLs.size()
0542:                            + " custom classpath urls:");
0543:                    for (Iterator iter = classpathURLs.iterator(); iter
0544:                            .hasNext();) {
0545:                        Message.debug("\t\t" + iter.next());
0546:                    }
0547:                }
0548:                Message.verbose("\t-- " + resolversMap.size() + " resolvers:");
0549:                for (Iterator iter = resolversMap.values().iterator(); iter
0550:                        .hasNext();) {
0551:                    DependencyResolver resolver = (DependencyResolver) iter
0552:                            .next();
0553:                    resolver.dumpSettings();
0554:                }
0555:                Message.debug("\tmodule settings:");
0556:                moduleSettings.dump("\t\t");
0557:            }
0558:
0559:            public void loadProperties(URL url) throws IOException {
0560:                loadProperties(url, true);
0561:            }
0562:
0563:            public void loadProperties(URL url, boolean overwrite)
0564:                    throws IOException {
0565:                loadProperties(url.openStream(), overwrite);
0566:            }
0567:
0568:            public void loadProperties(File file) throws IOException {
0569:                loadProperties(file, true);
0570:            }
0571:
0572:            public void loadProperties(File file, boolean overwrite)
0573:                    throws IOException {
0574:                loadProperties(new FileInputStream(file), overwrite);
0575:            }
0576:
0577:            private void loadProperties(InputStream stream, boolean overwrite)
0578:                    throws IOException {
0579:                try {
0580:                    Properties properties = new Properties();
0581:                    properties.load(stream);
0582:                    addAllVariables(properties, overwrite);
0583:                } finally {
0584:                    if (stream != null) {
0585:                        try {
0586:                            stream.close();
0587:                        } catch (IOException e) {
0588:                            //nothing
0589:                        }
0590:                    }
0591:                }
0592:            }
0593:
0594:            public void setVariable(String varName, String value) {
0595:                setVariable(varName, value, true);
0596:            }
0597:
0598:            public void setVariable(String varName, String value,
0599:                    boolean overwrite) {
0600:                variableContainer.setVariable(varName, value, overwrite);
0601:            }
0602:
0603:            public void addAllVariables(Map variables) {
0604:                addAllVariables(variables, true);
0605:            }
0606:
0607:            public void addAllVariables(Map variables, boolean overwrite) {
0608:                for (Iterator iter = variables.keySet().iterator(); iter
0609:                        .hasNext();) {
0610:                    String key = (String) iter.next();
0611:                    String val = (String) variables.get(key);
0612:                    setVariable(key, val, overwrite);
0613:                }
0614:            }
0615:
0616:            /**
0617:             * Substitute variables in the given string by their value found in the current set of variables
0618:             * 
0619:             * @param str
0620:             *            the string in which substitution should be made
0621:             * @return the string where all current ivy variables have been substituted by their value
0622:             */
0623:            public String substitute(String str) {
0624:                return IvyPatternHelper.substituteVariables(str,
0625:                        variableContainer);
0626:            }
0627:
0628:            /**
0629:             * Returns the variables loaded in configuration file. Those variables may better be seen as ant
0630:             * properties
0631:             * 
0632:             * @return
0633:             */
0634:            public IvyVariableContainer getVariables() {
0635:                return variableContainer;
0636:            }
0637:
0638:            public Class typeDef(String name, String className) {
0639:                return typeDef(name, className, false);
0640:            }
0641:
0642:            public Class typeDef(String name, String className,
0643:                    boolean silentFail) {
0644:                Class clazz = classForName(className, silentFail);
0645:                if (clazz != null) {
0646:                    typeDefs.put(name, clazz);
0647:                }
0648:                return clazz;
0649:            }
0650:
0651:            private Class classForName(String className, boolean silentFail) {
0652:                try {
0653:                    return getClassLoader().loadClass(className);
0654:                } catch (ClassNotFoundException e) {
0655:                    if (silentFail) {
0656:                        Message
0657:                                .info("impossible to define new type: class not found: "
0658:                                        + className
0659:                                        + " in "
0660:                                        + classpathURLs
0661:                                        + " nor Ivy classloader");
0662:                        return null;
0663:                    } else {
0664:                        throw new RuntimeException(
0665:                                "impossible to define new type: class not found: "
0666:                                        + className + " in " + classpathURLs
0667:                                        + " nor Ivy classloader");
0668:                    }
0669:                }
0670:            }
0671:
0672:            private ClassLoader getClassLoader() {
0673:                if (classloader == null) {
0674:                    if (classpathURLs.isEmpty()) {
0675:                        classloader = Ivy.class.getClassLoader();
0676:                    } else {
0677:                        classloader = new URLClassLoader((URL[]) classpathURLs
0678:                                .toArray(new URL[classpathURLs.size()]),
0679:                                Ivy.class.getClassLoader());
0680:                    }
0681:                }
0682:                return classloader;
0683:            }
0684:
0685:            public void addClasspathURL(URL url) {
0686:                classpathURLs.add(url);
0687:                classloader = null;
0688:            }
0689:
0690:            public Map getTypeDefs() {
0691:                return typeDefs;
0692:            }
0693:
0694:            public Class getTypeDef(String name) {
0695:                return (Class) typeDefs.get(name);
0696:            }
0697:
0698:            // methods which match ivy conf method signature specs
0699:            public void addConfigured(DependencyResolver resolver) {
0700:                addResolver(resolver);
0701:            }
0702:
0703:            public void addConfigured(ModuleDescriptorParser parser) {
0704:                ModuleDescriptorParserRegistry.getInstance().addParser(parser);
0705:            }
0706:
0707:            public void addResolver(DependencyResolver resolver) {
0708:                if (resolver == null) {
0709:                    throw new NullPointerException("null resolver");
0710:                }
0711:                init(resolver);
0712:                resolversMap.put(resolver.getName(), resolver);
0713:                if (resolver instanceof  ChainResolver) {
0714:                    List subresolvers = ((ChainResolver) resolver)
0715:                            .getResolvers();
0716:                    for (Iterator iter = subresolvers.iterator(); iter
0717:                            .hasNext();) {
0718:                        DependencyResolver dr = (DependencyResolver) iter
0719:                                .next();
0720:                        addResolver(dr);
0721:                    }
0722:                } else if (resolver instanceof  DualResolver) {
0723:                    DependencyResolver ivyResolver = ((DualResolver) resolver)
0724:                            .getIvyResolver();
0725:                    if (ivyResolver != null) {
0726:                        addResolver(ivyResolver);
0727:                    }
0728:                    DependencyResolver artifactResolver = ((DualResolver) resolver)
0729:                            .getArtifactResolver();
0730:                    if (artifactResolver != null) {
0731:                        addResolver(artifactResolver);
0732:                    }
0733:                }
0734:            }
0735:
0736:            public void setDefaultCache(File cacheDirectory) {
0737:                setVariable("ivy.cache.dir", cacheDirectory.getAbsolutePath(),
0738:                        false);
0739:                defaultCache = cacheDirectory;
0740:            }
0741:
0742:            public void setDefaultResolver(String resolverName) {
0743:                checkResolverName(resolverName);
0744:                defaultResolverName = resolverName;
0745:            }
0746:
0747:            private void checkResolverName(String resolverName) {
0748:                if (resolverName != null
0749:                        && !resolversMap.containsKey(resolverName)) {
0750:                    throw new IllegalArgumentException(
0751:                            "no resolver found called " + resolverName
0752:                                    + ": check your settings");
0753:                }
0754:            }
0755:
0756:            /**
0757:             * regular expressions as explained in Pattern class may be used in attributes
0758:             */
0759:            public void addModuleConfiguration(Map attributes,
0760:                    PatternMatcher matcher, String resolverName, String branch,
0761:                    String conflictManager) {
0762:                checkResolverName(resolverName);
0763:                moduleSettings.defineRule(new MapMatcher(attributes, matcher),
0764:                        new ModuleSettings(resolverName, branch,
0765:                                conflictManager));
0766:            }
0767:
0768:            public File getDefaultIvyUserDir() {
0769:                if (defaultUserDir == null) {
0770:                    if (getVariable("ivy.home") != null) {
0771:                        setDefaultIvyUserDir(new File(getVariable("ivy.home")));
0772:                        Message
0773:                                .verbose("using ivy.default.ivy.user.dir variable for default ivy user dir: "
0774:                                        + defaultUserDir);
0775:                    } else {
0776:                        setDefaultIvyUserDir(new File(System
0777:                                .getProperty("user.home"), ".ivy2"));
0778:                        Message
0779:                                .verbose("no default ivy user dir defined: set to "
0780:                                        + defaultUserDir);
0781:                    }
0782:                }
0783:                return defaultUserDir;
0784:            }
0785:
0786:            public void setDefaultIvyUserDir(File defaultUserDir) {
0787:                this .defaultUserDir = defaultUserDir;
0788:                setVariable("ivy.default.ivy.user.dir", this .defaultUserDir
0789:                        .getAbsolutePath());
0790:                setVariable("ivy.home", this .defaultUserDir.getAbsolutePath());
0791:            }
0792:
0793:            public File getDefaultCache() {
0794:                if (defaultCache == null) {
0795:                    String cache = getVariable("ivy.cache.dir");
0796:                    if (cache != null) {
0797:                        defaultCache = new File(cache);
0798:                    } else {
0799:                        setDefaultCache(new File(getDefaultIvyUserDir(),
0800:                                "cache"));
0801:                        Message.verbose("no default cache defined: set to "
0802:                                + defaultCache);
0803:                    }
0804:                }
0805:                return defaultCache;
0806:            }
0807:
0808:            public void setDefaultRepositoryCacheBasedir(
0809:                    String repositoryCacheRoot) {
0810:                setVariable("ivy.cache.repository", repositoryCacheRoot, true);
0811:            }
0812:
0813:            public void setDefaultResolutionCacheBasedir(
0814:                    String resolutionCacheRoot) {
0815:                setVariable("ivy.cache.resolution", resolutionCacheRoot, true);
0816:            }
0817:
0818:            public File getDefaultRepositoryCacheBasedir() {
0819:                String repositoryCacheRoot = getVariable("ivy.cache.repository");
0820:                if (repositoryCacheRoot != null) {
0821:                    return new File(repositoryCacheRoot);
0822:                } else {
0823:                    return getDefaultCache();
0824:                }
0825:            }
0826:
0827:            public File getDefaultResolutionCacheBasedir() {
0828:                String resolutionCacheRoot = getVariable("ivy.cache.resolution");
0829:                if (resolutionCacheRoot != null) {
0830:                    return new File(resolutionCacheRoot);
0831:                } else {
0832:                    return getDefaultCache();
0833:                }
0834:            }
0835:
0836:            public void setDictatorResolver(DependencyResolver resolver) {
0837:                dictatorResolver = resolver;
0838:            }
0839:
0840:            public DependencyResolver getResolver(ModuleRevisionId mrid) {
0841:                if (dictatorResolver != null) {
0842:                    return dictatorResolver;
0843:                }
0844:                String resolverName = getResolverName(mrid);
0845:                return getResolver(resolverName);
0846:            }
0847:
0848:            public DependencyResolver getResolver(String resolverName) {
0849:                if (dictatorResolver != null) {
0850:                    return dictatorResolver;
0851:                }
0852:                DependencyResolver resolver = (DependencyResolver) resolversMap
0853:                        .get(resolverName);
0854:                if (resolver == null) {
0855:                    Message.error("unknown resolver " + resolverName);
0856:                }
0857:                return resolver;
0858:            }
0859:
0860:            public DependencyResolver getDefaultResolver() {
0861:                if (dictatorResolver != null) {
0862:                    return dictatorResolver;
0863:                }
0864:                if (defaultResolver == null) {
0865:                    defaultResolver = (DependencyResolver) resolversMap
0866:                            .get(defaultResolverName);
0867:                }
0868:                return defaultResolver;
0869:            }
0870:
0871:            public String getResolverName(ModuleRevisionId mrid) {
0872:                ModuleSettings ms = (ModuleSettings) moduleSettings.getRule(
0873:                        mrid, new Filter() {
0874:                            public boolean accept(Object o) {
0875:                                return ((ModuleSettings) o).getResolverName() != null;
0876:                            }
0877:                        });
0878:                return ms == null ? defaultResolverName : ms.getResolverName();
0879:            }
0880:
0881:            public String getDefaultBranch(ModuleId moduleId) {
0882:                ModuleSettings ms = (ModuleSettings) moduleSettings.getRule(
0883:                        moduleId, new Filter() {
0884:                            public boolean accept(Object o) {
0885:                                return ((ModuleSettings) o).getBranch() != null;
0886:                            }
0887:                        });
0888:                return ms == null ? getDefaultBranch() : ms.getBranch();
0889:            }
0890:
0891:            public String getDefaultBranch() {
0892:                return defaultBranch;
0893:            }
0894:
0895:            public void setDefaultBranch(String defaultBranch) {
0896:                this .defaultBranch = defaultBranch;
0897:            }
0898:
0899:            public ConflictManager getConflictManager(ModuleId moduleId) {
0900:                ModuleSettings ms = (ModuleSettings) moduleSettings.getRule(
0901:                        moduleId, new Filter() {
0902:                            public boolean accept(Object o) {
0903:                                return ((ModuleSettings) o)
0904:                                        .getConflictManager() != null;
0905:                            }
0906:                        });
0907:                if (ms == null) {
0908:                    return getDefaultConflictManager();
0909:                } else {
0910:                    ConflictManager cm = getConflictManager(ms
0911:                            .getConflictManager());
0912:                    if (cm == null) {
0913:                        throw new IllegalStateException(
0914:                                "ivy badly configured: unknown conflict manager "
0915:                                        + ms.getConflictManager());
0916:                    }
0917:                    return cm;
0918:                }
0919:            }
0920:
0921:            public void addConfigured(ConflictManager cm) {
0922:                addConflictManager(cm.getName(), cm);
0923:            }
0924:
0925:            public ConflictManager getConflictManager(String name) {
0926:                if ("default".equals(name)) {
0927:                    return getDefaultConflictManager();
0928:                }
0929:                return (ConflictManager) conflictsManager.get(name);
0930:            }
0931:
0932:            public void addConflictManager(String name, ConflictManager cm) {
0933:                init(cm);
0934:                conflictsManager.put(name, cm);
0935:            }
0936:
0937:            public void addConfigured(LatestStrategy latest) {
0938:                addLatestStrategy(latest.getName(), latest);
0939:            }
0940:
0941:            public LatestStrategy getLatestStrategy(String name) {
0942:                if ("default".equals(name)) {
0943:                    return getDefaultLatestStrategy();
0944:                }
0945:                return (LatestStrategy) latestStrategies.get(name);
0946:            }
0947:
0948:            public void addLatestStrategy(String name, LatestStrategy latest) {
0949:                init(latest);
0950:                latestStrategies.put(name, latest);
0951:            }
0952:
0953:            public void addConfigured(LockStrategy lockStrategy) {
0954:                addLockStrategy(lockStrategy.getName(), lockStrategy);
0955:            }
0956:
0957:            public LockStrategy getLockStrategy(String name) {
0958:                if ("default".equals(name)) {
0959:                    return getDefaultLockStrategy();
0960:                }
0961:                return (LockStrategy) lockStrategies.get(name);
0962:            }
0963:
0964:            public void addLockStrategy(String name, LockStrategy lockStrategy) {
0965:                init(lockStrategy);
0966:                lockStrategies.put(name, lockStrategy);
0967:            }
0968:
0969:            public void addConfigured(Namespace ns) {
0970:                addNamespace(ns);
0971:            }
0972:
0973:            public Namespace getNamespace(String name) {
0974:                if ("system".equals(name)) {
0975:                    return getSystemNamespace();
0976:                }
0977:                return (Namespace) namespaces.get(name);
0978:            }
0979:
0980:            public Namespace getSystemNamespace() {
0981:                return Namespace.SYSTEM_NAMESPACE;
0982:            }
0983:
0984:            public void addNamespace(Namespace ns) {
0985:                init(ns);
0986:                namespaces.put(ns.getName(), ns);
0987:            }
0988:
0989:            public void addConfigured(PatternMatcher m) {
0990:                addMatcher(m);
0991:            }
0992:
0993:            public PatternMatcher getMatcher(String name) {
0994:                return (PatternMatcher) matchers.get(name);
0995:            }
0996:
0997:            public void addMatcher(PatternMatcher m) {
0998:                init(m);
0999:                matchers.put(m.getName(), m);
1000:            }
1001:
1002:            public void addConfigured(RepositoryCacheManager c) {
1003:                addRepositoryCacheManager(c);
1004:            }
1005:
1006:            public RepositoryCacheManager getRepositoryCacheManager(String name) {
1007:                return (RepositoryCacheManager) repositoryCacheManagers
1008:                        .get(name);
1009:            }
1010:
1011:            public void addRepositoryCacheManager(RepositoryCacheManager c) {
1012:                init(c);
1013:                repositoryCacheManagers.put(c.getName(), c);
1014:            }
1015:
1016:            public RepositoryCacheManager[] getRepositoryCacheManagers() {
1017:                return (RepositoryCacheManager[]) repositoryCacheManagers
1018:                        .values()
1019:                        .toArray(
1020:                                new RepositoryCacheManager[repositoryCacheManagers
1021:                                        .size()]);
1022:            }
1023:
1024:            public void addConfigured(ReportOutputter outputter) {
1025:                addReportOutputter(outputter);
1026:            }
1027:
1028:            public ReportOutputter getReportOutputter(String name) {
1029:                return (ReportOutputter) reportOutputters.get(name);
1030:            }
1031:
1032:            public void addReportOutputter(ReportOutputter outputter) {
1033:                init(outputter);
1034:                reportOutputters.put(outputter.getName(), outputter);
1035:            }
1036:
1037:            public ReportOutputter[] getReportOutputters() {
1038:                return (ReportOutputter[]) reportOutputters.values().toArray(
1039:                        new ReportOutputter[reportOutputters.size()]);
1040:            }
1041:
1042:            public void addConfigured(VersionMatcher vmatcher) {
1043:                addVersionMatcher(vmatcher);
1044:            }
1045:
1046:            public VersionMatcher getVersionMatcher(String name) {
1047:                return (VersionMatcher) versionMatchers.get(name);
1048:            }
1049:
1050:            public void addVersionMatcher(VersionMatcher vmatcher) {
1051:                init(vmatcher);
1052:                versionMatchers.put(vmatcher.getName(), vmatcher);
1053:
1054:                if (versionMatcher == null) {
1055:                    versionMatcher = new ChainVersionMatcher();
1056:                    addVersionMatcher(new ExactVersionMatcher());
1057:                }
1058:                if (versionMatcher instanceof  ChainVersionMatcher) {
1059:                    ChainVersionMatcher chain = (ChainVersionMatcher) versionMatcher;
1060:                    chain.add(vmatcher);
1061:                }
1062:            }
1063:
1064:            public VersionMatcher[] getVersionMatchers() {
1065:                return (VersionMatcher[]) versionMatchers.values().toArray(
1066:                        new VersionMatcher[versionMatchers.size()]);
1067:            }
1068:
1069:            public VersionMatcher getVersionMatcher() {
1070:                if (versionMatcher == null) {
1071:                    configureDefaultVersionMatcher();
1072:                }
1073:                return versionMatcher;
1074:            }
1075:
1076:            public void configureDefaultVersionMatcher() {
1077:                addVersionMatcher(new LatestVersionMatcher());
1078:                addVersionMatcher(new SubVersionMatcher());
1079:                addVersionMatcher(new VersionRangeMatcher());
1080:            }
1081:
1082:            public CircularDependencyStrategy getCircularDependencyStrategy() {
1083:                if (circularDependencyStrategy == null) {
1084:                    circularDependencyStrategy = getCircularDependencyStrategy("default");
1085:                }
1086:                return circularDependencyStrategy;
1087:            }
1088:
1089:            public CircularDependencyStrategy getCircularDependencyStrategy(
1090:                    String name) {
1091:                if ("default".equals(name)) {
1092:                    name = "warn";
1093:                }
1094:                return (CircularDependencyStrategy) circularDependencyStrategies
1095:                        .get(name);
1096:            }
1097:
1098:            public void setCircularDependencyStrategy(
1099:                    CircularDependencyStrategy strategy) {
1100:                circularDependencyStrategy = strategy;
1101:            }
1102:
1103:            public void addConfigured(CircularDependencyStrategy strategy) {
1104:                addCircularDependencyStrategy(strategy);
1105:            }
1106:
1107:            private void addCircularDependencyStrategy(
1108:                    CircularDependencyStrategy strategy) {
1109:                circularDependencyStrategies.put(strategy.getName(), strategy);
1110:            }
1111:
1112:            private void configureDefaultCircularDependencyStrategies() {
1113:                addCircularDependencyStrategy(WarnCircularDependencyStrategy
1114:                        .getInstance());
1115:                addCircularDependencyStrategy(ErrorCircularDependencyStrategy
1116:                        .getInstance());
1117:                addCircularDependencyStrategy(IgnoreCircularDependencyStrategy
1118:                        .getInstance());
1119:            }
1120:
1121:            public StatusManager getStatusManager() {
1122:                if (statusManager == null) {
1123:                    statusManager = StatusManager.newDefaultInstance();
1124:                }
1125:                return statusManager;
1126:            }
1127:
1128:            public void setStatusManager(StatusManager statusManager) {
1129:                this .statusManager = statusManager;
1130:            }
1131:
1132:            /**
1133:             * Returns true if the name should be ignored in listing
1134:             * 
1135:             * @param name
1136:             * @return
1137:             */
1138:            public boolean listingIgnore(String name) {
1139:                return listingIgnore.contains(name);
1140:            }
1141:
1142:            /**
1143:             * Filters the names list by removing all names that should be ignored as defined by the listing
1144:             * ignore list
1145:             * 
1146:             * @param names
1147:             */
1148:            public void filterIgnore(Collection names) {
1149:                names.removeAll(listingIgnore);
1150:            }
1151:
1152:            public boolean isCheckUpToDate() {
1153:                return checkUpToDate;
1154:            }
1155:
1156:            public void setCheckUpToDate(boolean checkUpToDate) {
1157:                this .checkUpToDate = checkUpToDate;
1158:            }
1159:
1160:            public boolean doValidate() {
1161:                return validate;
1162:            }
1163:
1164:            public void setValidate(boolean validate) {
1165:                this .validate = validate;
1166:            }
1167:
1168:            public String getVariable(String name) {
1169:                return variableContainer.getVariable(name);
1170:            }
1171:
1172:            public ConflictManager getDefaultConflictManager() {
1173:                if (defaultConflictManager == null) {
1174:                    defaultConflictManager = new LatestConflictManager(
1175:                            getDefaultLatestStrategy());
1176:                }
1177:                return defaultConflictManager;
1178:            }
1179:
1180:            public void setDefaultConflictManager(
1181:                    ConflictManager defaultConflictManager) {
1182:                this .defaultConflictManager = defaultConflictManager;
1183:            }
1184:
1185:            public LatestStrategy getDefaultLatestStrategy() {
1186:                if (defaultLatestStrategy == null) {
1187:                    defaultLatestStrategy = new LatestRevisionStrategy();
1188:                }
1189:                return defaultLatestStrategy;
1190:            }
1191:
1192:            public void setDefaultLatestStrategy(
1193:                    LatestStrategy defaultLatestStrategy) {
1194:                this .defaultLatestStrategy = defaultLatestStrategy;
1195:            }
1196:
1197:            public LockStrategy getDefaultLockStrategy() {
1198:                if (defaultLockStrategy == null) {
1199:                    defaultLockStrategy = new NoLockStrategy();
1200:                }
1201:                return defaultLockStrategy;
1202:            }
1203:
1204:            public void setDefaultLockStrategy(LockStrategy defaultLockStrategy) {
1205:                this .defaultLockStrategy = defaultLockStrategy;
1206:            }
1207:
1208:            public RepositoryCacheManager getDefaultRepositoryCacheManager() {
1209:                if (defaultRepositoryCacheManager == null) {
1210:                    defaultRepositoryCacheManager = new DefaultRepositoryCacheManager(
1211:                            "default-cache", this ,
1212:                            getDefaultRepositoryCacheBasedir());
1213:                    addRepositoryCacheManager(defaultRepositoryCacheManager);
1214:                }
1215:                return defaultRepositoryCacheManager;
1216:            }
1217:
1218:            public void setDefaultRepositoryCacheManager(
1219:                    RepositoryCacheManager cache) {
1220:                this .defaultRepositoryCacheManager = cache;
1221:            }
1222:
1223:            public ResolutionCacheManager getResolutionCacheManager() {
1224:                if (resolutionCacheManager == null) {
1225:                    resolutionCacheManager = new DefaultResolutionCacheManager(
1226:                            getDefaultResolutionCacheBasedir());
1227:                }
1228:                return resolutionCacheManager;
1229:            }
1230:
1231:            public void setResolutionCacheManager(
1232:                    ResolutionCacheManager resolutionCacheManager) {
1233:                this .resolutionCacheManager = resolutionCacheManager;
1234:            }
1235:
1236:            public void addTrigger(Trigger trigger) {
1237:                init(trigger);
1238:                triggers.add(trigger);
1239:            }
1240:
1241:            public List getTriggers() {
1242:                return triggers;
1243:            }
1244:
1245:            public void addConfigured(Trigger trigger) {
1246:                addTrigger(trigger);
1247:            }
1248:
1249:            public boolean isUseRemoteConfig() {
1250:                return useRemoteConfig;
1251:            }
1252:
1253:            public void setUseRemoteConfig(boolean useRemoteConfig) {
1254:                this .useRemoteConfig = useRemoteConfig;
1255:            }
1256:
1257:            public boolean logModulesInUse() {
1258:                String var = getVariable("ivy.log.modules.in.use");
1259:                return var == null || Boolean.valueOf(var).booleanValue();
1260:            }
1261:
1262:            public boolean logModuleWhenFound() {
1263:                String var = getVariable("ivy.log.module.when.found");
1264:                return var == null || Boolean.valueOf(var).booleanValue();
1265:            }
1266:
1267:            public boolean logResolvedRevision() {
1268:                String var = getVariable("ivy.log.resolved.revision");
1269:                return var == null || Boolean.valueOf(var).booleanValue();
1270:            }
1271:
1272:            public boolean debugConflictResolution() {
1273:                if (debugConflictResolution == null) {
1274:                    String var = getVariable("ivy.log.conflict.resolution");
1275:                    debugConflictResolution = Boolean.valueOf(var != null
1276:                            && Boolean.valueOf(var).booleanValue());
1277:                }
1278:                return debugConflictResolution.booleanValue();
1279:            }
1280:
1281:            public final boolean debugLocking() {
1282:                if (debugLocking == null) {
1283:                    String var = getVariable("ivy.log.locking");
1284:                    debugLocking = Boolean.valueOf(var != null
1285:                            && Boolean.valueOf(var).booleanValue());
1286:                }
1287:                return debugLocking.booleanValue();
1288:            }
1289:
1290:            public boolean dumpMemoryUsage() {
1291:                if (dumpMemoryUsage == null) {
1292:                    String var = getVariable("ivy.log.memory");
1293:                    dumpMemoryUsage = Boolean.valueOf(var != null
1294:                            && Boolean.valueOf(var).booleanValue());
1295:                }
1296:                return dumpMemoryUsage.booleanValue();
1297:            }
1298:
1299:            public boolean logNotConvertedExclusionRule() {
1300:                return logNotConvertedExclusionRule;
1301:            }
1302:
1303:            public void setLogNotConvertedExclusionRule(
1304:                    boolean logNotConvertedExclusionRule) {
1305:                this .logNotConvertedExclusionRule = logNotConvertedExclusionRule;
1306:            }
1307:
1308:            private void init(Object obj) {
1309:                if (obj instanceof  IvySettingsAware) {
1310:                    ((IvySettingsAware) obj).setSettings(this );
1311:                } else if (obj instanceof  DependencyResolver) {
1312:                    ((DependencyResolver) obj).setSettings(this );
1313:                }
1314:            }
1315:
1316:            private static class ModuleSettings {
1317:                private String resolverName;
1318:
1319:                private String branch;
1320:
1321:                private String conflictManager;
1322:
1323:                public ModuleSettings(String resolver, String branchName,
1324:                        String conflictMgr) {
1325:                    resolverName = resolver;
1326:                    branch = branchName;
1327:                    conflictManager = conflictMgr;
1328:                }
1329:
1330:                public String toString() {
1331:                    return resolverName != null ? "resolver: " + resolverName
1332:                            : "" + branch != null ? "branch: " + branch : "";
1333:                }
1334:
1335:                public String getBranch() {
1336:                    return branch;
1337:                }
1338:
1339:                public String getResolverName() {
1340:                    return resolverName;
1341:                }
1342:
1343:                protected String getConflictManager() {
1344:                    return conflictManager;
1345:                }
1346:            }
1347:
1348:            public long getInterruptTimeout() {
1349:                return INTERUPT_TIMEOUT;
1350:            }
1351:
1352:            public Collection getResolvers() {
1353:                return resolversMap.values();
1354:            }
1355:
1356:            public Collection getResolverNames() {
1357:                return resolversMap.keySet();
1358:            }
1359:
1360:            public Collection getMatcherNames() {
1361:                return matchers.keySet();
1362:            }
1363:
1364:            public IvyVariableContainer getVariableContainer() {
1365:                return variableContainer;
1366:            }
1367:
1368:            /**
1369:             * Use a different variable container.
1370:             * 
1371:             * @param variables
1372:             */
1373:            public void setVariableContainer(IvyVariableContainer variables) {
1374:                variableContainer = variables;
1375:            }
1376:
1377:            public RelativeUrlResolver getRelativeUrlResolver() {
1378:                return new NormalRelativeUrlResolver();
1379:            }
1380:
1381:            public void setDefaultCacheIvyPattern(String defaultCacheIvyPattern) {
1382:                this .defaultCacheIvyPattern = defaultCacheIvyPattern;
1383:            }
1384:
1385:            public String getDefaultCacheIvyPattern() {
1386:                return defaultCacheIvyPattern;
1387:            }
1388:
1389:            public void setDefaultCacheArtifactPattern(
1390:                    String defaultCacheArtifactPattern) {
1391:                this .defaultCacheArtifactPattern = defaultCacheArtifactPattern;
1392:            }
1393:
1394:            public String getDefaultCacheArtifactPattern() {
1395:                return defaultCacheArtifactPattern;
1396:            }
1397:
1398:            public void setDefaultUseOrigin(boolean useOrigin) {
1399:                defaultUseOrigin = useOrigin;
1400:            }
1401:
1402:            public boolean isDefaultUseOrigin() {
1403:                return defaultUseOrigin;
1404:            }
1405:
1406:            public void useDeprecatedUseOrigin() {
1407:                Message
1408:                        .deprecated("useOrigin option is deprecated when calling resolve, use useOrigin"
1409:                                + " setting on the cache implementation instead");
1410:                setDefaultUseOrigin(true);
1411:
1412:            }
1413:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.