/
IvySettings.java
1484 lines (1247 loc) · 52.5 KB
/
IvySettings.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF 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.security.AccessControlException;
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.NormalRelativeUrlResolver;
import org.apache.ivy.core.RelativeUrlResolver;
import org.apache.ivy.core.cache.CacheUtil;
import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
import org.apache.ivy.core.cache.DefaultResolutionCacheManager;
import org.apache.ivy.core.cache.RepositoryCacheManager;
import org.apache.ivy.core.cache.ResolutionCacheManager;
import org.apache.ivy.core.check.CheckEngineSettings;
import org.apache.ivy.core.deliver.DeliverEngineSettings;
import org.apache.ivy.core.install.InstallEngineSettings;
import org.apache.ivy.core.module.id.ModuleId;
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.core.module.id.ModuleRules;
import org.apache.ivy.core.module.status.StatusManager;
import org.apache.ivy.core.publish.PublishEngineSettings;
import org.apache.ivy.core.repository.RepositoryManagementEngineSettings;
import org.apache.ivy.core.resolve.ResolveEngineSettings;
import org.apache.ivy.core.resolve.ResolveOptions;
import org.apache.ivy.core.retrieve.RetrieveEngineSettings;
import org.apache.ivy.core.sort.SortEngineSettings;
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.LatestCompatibleConflictManager;
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.lock.ArtifactLockStrategy;
import org.apache.ivy.plugins.lock.LockStrategy;
import org.apache.ivy.plugins.lock.NoLockStrategy;
import org.apache.ivy.plugins.matcher.ExactOrRegexpPatternMatcher;
import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
import org.apache.ivy.plugins.matcher.MapMatcher;
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.parser.ParserSettings;
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.resolver.ResolverSettings;
import org.apache.ivy.plugins.signer.SignatureGenerator;
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.Checks;
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.ivy.util.filter.Filter;
import org.apache.ivy.util.url.URLHandlerRegistry;
public class IvySettings implements SortEngineSettings, PublishEngineSettings, ParserSettings,
DeliverEngineSettings, CheckEngineSettings, InstallEngineSettings,
ResolverSettings, ResolveEngineSettings, RetrieveEngineSettings,
RepositoryManagementEngineSettings {
private static final long INTERUPT_TIMEOUT = 2000;
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 ModuleRules moduleSettings = new ModuleRules();
// Map (String conflictManagerName -> ConflictManager)
private Map conflictsManager = new HashMap();
// Map (String latestStrategyName -> LatestStrategy)
private Map latestStrategies = new HashMap();
// Map (String name -> LockStrategy)
private Map lockStrategies = new HashMap();
// Map (String namespaceName -> Namespace)
private Map namespaces = new HashMap();
// Map (String matcherName -> Matcher)
private Map matchers = new HashMap();
// Map (String outputterName -> ReportOutputter)
private Map reportOutputters = new HashMap();
// Map (String matcherName -> VersionMatcher)
private Map versionMatchers = new HashMap();
// Map (String name -> CircularDependencyStrategy)
private Map circularDependencyStrategies = new HashMap();
// Map (String name -> RepositoryCacheManager)
private Map repositoryCacheManagers = new HashMap();
// Map (String name -> SignatureGenerator)
private Map signatureGenerators = new HashMap();
// List (Trigger)
private List triggers = new ArrayList();
private IvyVariableContainer variableContainer = new IvyVariableContainerImpl();
private boolean validate = true;
private LatestStrategy defaultLatestStrategy = null;
private LockStrategy defaultLockStrategy = null;
private ConflictManager defaultConflictManager = null;
private CircularDependencyStrategy circularDependencyStrategy = null;
private RepositoryCacheManager defaultRepositoryCacheManager = null;
private ResolutionCacheManager resolutionCacheManager = null;
private List listingIgnore = new ArrayList();
private boolean repositoriesConfigured;
private boolean useRemoteConfig = false;
private File defaultUserDir;
private File baseDir = new File(".").getAbsoluteFile();
private List classpathURLs = new ArrayList();
private ClassLoader classloader;
private Boolean debugConflictResolution;
private boolean logNotConvertedExclusionRule;
private VersionMatcher versionMatcher;
private StatusManager statusManager;
private Boolean debugLocking;
private Boolean dumpMemoryUsage;
private String defaultCacheIvyPattern;
private String defaultCacheArtifactPattern;
private boolean defaultUseOrigin;
private String defaultResolveMode = ResolveOptions.RESOLVEMODE_DEFAULT;
public IvySettings() {
this(new IvyVariableContainerImpl());
}
public IvySettings(IvyVariableContainer variableContainer) {
setVariableContainer(variableContainer);
setVariable("ivy.default.settings.dir", getDefaultSettingsDir(), true);
setVariable("ivy.basedir", getBaseDir().getAbsolutePath());
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(
Checks.checkAbsolute(files[i].trim(), "ivy.typedef.files")), 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);
addLockStrategy("no-lock", new NoLockStrategy());
addLockStrategy("artifact-lock", new ArtifactLockStrategy(debugLocking()));
addConflictManager("latest-revision", new LatestConflictManager("latest-revision",
latestRevisionStrategy));
addConflictManager("latest-compatible",
new LatestCompatibleConflictManager("latest-compatible", 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.");
}
addReportOutputter(new LogReportOutputter());
addReportOutputter(new XmlReportOutputter());
configureDefaultCircularDependencyStrategies();
listingIgnore.add(".cvsignore");
listingIgnore.add("CVS");
listingIgnore.add(".svn");
listingIgnore.add("maven-metadata.xml");
listingIgnore.add("maven-metadata.xml.md5");
listingIgnore.add("maven-metadata.xml.sha1");
addSystemProperties();
}
private void addSystemProperties() {
try {
addAllVariables(System.getProperties());
} catch (AccessControlException ex) {
Message.verbose(
"access denied to getting all system properties: they won't be available as Ivy variables."
+ "\nset " + ex.getPermission() + " permission if you want to access them");
}
}
/**
* 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://ant.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) {
//nothing to do
}
}
}
}
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(Checks.checkAbsolute(
getVariable("ivy.default.ivy.user.dir"), "ivy.default.ivy.user.dir"));
} else {
getDefaultIvyUserDir();
}
loadDefaultProperties();
try {
new XmlSettingsParser(this).parse(settingsFile.toURI().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(Checks.checkAbsolute(
getVariable("ivy.default.ivy.user.dir"), "ivy.default.ivy.user.dir"));
} else {
getDefaultIvyUserDir();
}
loadDefaultProperties();
new XmlSettingsParser(this).parse(settingsURL);
setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir().getAbsolutePath(), false);
Message.verbose("settings loaded (" + (System.currentTimeMillis() - start) + "ms)");
dumpSettings();
}
/**
* Default initialization of settings, useful when you don't want to load your settings from a
* settings file or URL, but prefer to set them manually. By calling this method you will still
* have the basic initialization done when loading settings.
*
* @throws IOException
*/
public void defaultInit() throws IOException {
if (getVariable("ivy.default.ivy.user.dir") != null) {
setDefaultIvyUserDir(Checks.checkAbsolute(
getVariable("ivy.default.ivy.user.dir"), "ivy.default.ivy.user.dir"));
} else {
getDefaultIvyUserDir();
}
getDefaultCache();
loadDefaultProperties();
setVariable("ivy.default.ivy.user.dir", getDefaultIvyUserDir().getAbsolutePath(), false);
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.toURI().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());
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();
}
Message.debug("\tmodule settings:");
moduleSettings.dump("\t\t");
}
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) {
//nothing
}
}
}
}
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
* If the input str doesn't use any variable, the same object is returned
*/
public String substitute(String str) {
return IvyPatternHelper.substituteVariables(str, variableContainer);
}
/**
* Substitute variables in the given map values by their value found in the current set of
* variables
*
* @param strings
* the map of strings in which substitution should be made
* @return a new map of strings in which all current ivy variables in values have been
* substituted by their value
*/
public Map/*<String, String>*/ substitute(Map/*<String, String>*/ strings) {
Map substituted = new LinkedHashMap();
for (Iterator it = strings.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
substituted.put(entry.getKey(), substitute((String) entry.getValue()));
}
return substituted;
}
/**
* Returns the variables loaded in configuration file. Those variables may better be seen as ant
* properties
*
* @return
*/
public IvyVariableContainer getVariables() {
return variableContainer;
}
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 addConfigured(SignatureGenerator generator) {
addSignatureGenerator(generator);
}
public void addSignatureGenerator(SignatureGenerator generator) {
init(generator);
signatureGenerators.put(generator.getName(), generator);
}
public SignatureGenerator getSignatureGenerator(String name) {
return (SignatureGenerator) signatureGenerators.get(name);
}
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) {
setVariable("ivy.cache.dir", cacheDirectory.getAbsolutePath(), false);
defaultCache = cacheDirectory;
if (defaultRepositoryCacheManager != null) {
if ("default-cache".equals(defaultRepositoryCacheManager.getName())
&& defaultRepositoryCacheManager instanceof DefaultRepositoryCacheManager) {
((DefaultRepositoryCacheManager) defaultRepositoryCacheManager)
.setBasedir(defaultCache);
}
}
}
public void setDefaultResolver(String resolverName) {
checkResolverName(resolverName);
if (resolverName != null && !resolverName.equals(defaultResolverName)) {
defaultResolver = null;
}
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 attributes
*/
public void addModuleConfiguration(Map attributes, PatternMatcher matcher,
String resolverName, String branch, String conflictManager, String resolveMode) {
checkResolverName(resolverName);
moduleSettings.defineRule(
new MapMatcher(attributes, matcher),
new ModuleSettings(resolverName, branch, conflictManager, resolveMode));
}
/**
* Return the canonical form of a filename.
* <p>
* If the specified file name is relative it is resolved
* with respect to the settings's base directory.
*
* @param fileName The name of the file to resolve.
* Must not be <code>null</code>.
*
* @return the resolved File.
*
*/
public File resolveFile(String fileName) {
return FileUtil.resolveFile(baseDir, fileName);
}
public void setBaseDir(File baseDir) {
this.baseDir = baseDir.getAbsoluteFile();
setVariable("ivy.basedir", this.baseDir.getAbsolutePath());
setVariable("basedir", this.baseDir.getAbsolutePath(), false);
}
public File getBaseDir() {
return baseDir;
}
public File getDefaultIvyUserDir() {
if (defaultUserDir == null) {
if (getVariable("ivy.home") != null) {
setDefaultIvyUserDir(Checks.checkAbsolute(getVariable("ivy.home"), "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"), ".ivy2"));
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) {
String cache = getVariable("ivy.cache.dir");
if (cache != null) {
defaultCache = Checks.checkAbsolute(cache, "ivy.cache.dir");
} else {
setDefaultCache(new File(getDefaultIvyUserDir(), "cache"));
Message.verbose("no default cache defined: set to " + defaultCache);
}
}
return defaultCache;
}
public void setDefaultRepositoryCacheBasedir(String repositoryCacheRoot) {
setVariable("ivy.cache.repository", repositoryCacheRoot, true);
if (defaultRepositoryCacheManager != null
&& "default-cache".equals(defaultRepositoryCacheManager.getName())
&& defaultRepositoryCacheManager instanceof DefaultRepositoryCacheManager) {
((DefaultRepositoryCacheManager) defaultRepositoryCacheManager)
.setBasedir(getDefaultRepositoryCacheBasedir());
}
}
public void setDefaultResolutionCacheBasedir(String resolutionCacheRoot) {
setVariable("ivy.cache.resolution", resolutionCacheRoot, true);
if (resolutionCacheManager != null
&& resolutionCacheManager instanceof DefaultResolutionCacheManager) {
((DefaultResolutionCacheManager) resolutionCacheManager)
.setBasedir(getDefaultResolutionCacheBasedir());
}
}
public File getDefaultRepositoryCacheBasedir() {
String repositoryCacheRoot = getVariable("ivy.cache.repository");
if (repositoryCacheRoot != null) {
return Checks.checkAbsolute(repositoryCacheRoot, "ivy.cache.repository");
} else {
return getDefaultCache();
}
}
public File getDefaultResolutionCacheBasedir() {
String resolutionCacheRoot = getVariable("ivy.cache.resolution");
if (resolutionCacheRoot != null) {
return Checks.checkAbsolute(resolutionCacheRoot, "ivy.cache.resolution");
} else {
return getDefaultCache();
}
}
public void setDictatorResolver(DependencyResolver resolver) {
dictatorResolver = resolver;
}
public DependencyResolver getResolver(ModuleRevisionId mrid) {
if (dictatorResolver != null) {
return dictatorResolver;
}
String resolverName = getResolverName(mrid);
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(ModuleRevisionId mrid) {
ModuleSettings ms = (ModuleSettings) moduleSettings.getRule(mrid, new Filter() {
public boolean accept(Object o) {
return ((ModuleSettings) o).getResolverName() != null;
}
});
return ms == null ? defaultResolverName : ms.getResolverName();
}
public String getDefaultBranch(ModuleId moduleId) {
ModuleSettings ms = (ModuleSettings) moduleSettings.getRule(moduleId, new Filter() {
public boolean accept(Object o) {
return ((ModuleSettings) o).getBranch() != null;
}
});
return ms == null ? getDefaultBranch() : ms.getBranch();
}
public String getDefaultBranch() {
return defaultBranch;
}
public void setDefaultBranch(String defaultBranch) {
this.defaultBranch = defaultBranch;
}
public ConflictManager getConflictManager(ModuleId moduleId) {
ModuleSettings ms = (ModuleSettings) moduleSettings.getRule(moduleId, new Filter() {
public boolean accept(Object o) {
return ((ModuleSettings) o).getConflictManager() != null;
}
});
if (ms == null) {
return getDefaultConflictManager();
} else {
ConflictManager cm = getConflictManager(ms.getConflictManager());
if (cm == null) {
throw new IllegalStateException(
"ivy badly configured: unknown conflict manager "
+ ms.getConflictManager());
}
return cm;
}
}
public String getResolveMode(ModuleId moduleId) {
ModuleSettings ms = (ModuleSettings) moduleSettings.getRule(moduleId, new Filter() {
public boolean accept(Object o) {
return ((ModuleSettings) o).getResolveMode() != null;
}
});
return ms == null ? getDefaultResolveMode() : ms.getResolveMode();
}
public String getDefaultResolveMode() {
return defaultResolveMode;
}
public void setDefaultResolveMode(String defaultResolveMode) {
this.defaultResolveMode = defaultResolveMode;
}
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(LockStrategy lockStrategy) {
addLockStrategy(lockStrategy.getName(), lockStrategy);
}
public LockStrategy getLockStrategy(String name) {
if ("default".equals(name)) {
return getDefaultLockStrategy();
}
return (LockStrategy) lockStrategies.get(name);
}