-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
DefaultProject.java
1326 lines (1104 loc) · 40.8 KB
/
DefaultProject.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
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.project;
import com.google.common.collect.Maps;
import groovy.lang.Closure;
import groovy.lang.MissingPropertyException;
import org.gradle.api.Action;
import org.gradle.api.AntBuilder;
import org.gradle.api.CircularReferenceException;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.NamedDomainObjectFactory;
import org.gradle.api.PathValidation;
import org.gradle.api.Project;
import org.gradle.api.ProjectConfigurationException;
import org.gradle.api.ProjectEvaluationListener;
import org.gradle.api.Task;
import org.gradle.api.UnknownProjectException;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.dsl.ArtifactHandler;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.component.SoftwareComponentContainer;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.CopySpec;
import org.gradle.api.file.DeleteSpec;
import org.gradle.api.file.FileTree;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.api.internal.ClosureBackedAction;
import org.gradle.api.internal.DynamicObjectAware;
import org.gradle.api.internal.DynamicPropertyNamer;
import org.gradle.api.internal.ExtensibleDynamicObject;
import org.gradle.api.internal.FactoryNamedDomainObjectContainer;
import org.gradle.api.internal.GradleInternal;
import org.gradle.api.internal.NoConventionMapping;
import org.gradle.api.internal.ProcessOperations;
import org.gradle.api.internal.artifacts.Module;
import org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider;
import org.gradle.api.internal.file.DefaultProjectLayout;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.internal.file.SourceDirectorySetFactory;
import org.gradle.api.internal.initialization.ClassLoaderScope;
import org.gradle.api.internal.initialization.ScriptHandlerFactory;
import org.gradle.api.internal.plugins.DefaultObjectConfigurationAction;
import org.gradle.api.internal.plugins.ExtensionContainerInternal;
import org.gradle.api.internal.plugins.PluginManagerInternal;
import org.gradle.api.internal.project.taskfactory.ITaskFactory;
import org.gradle.api.internal.tasks.TaskContainerInternal;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.plugins.Convention;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.provider.PropertyState;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.resources.ResourceHandler;
import org.gradle.api.tasks.WorkResult;
import org.gradle.configuration.ScriptPluginFactory;
import org.gradle.configuration.project.ProjectConfigurationActionContainer;
import org.gradle.configuration.project.ProjectEvaluator;
import org.gradle.groovy.scripts.ScriptSource;
import org.gradle.internal.Actions;
import org.gradle.internal.Factories;
import org.gradle.internal.Factory;
import org.gradle.internal.event.ListenerBroadcast;
import org.gradle.internal.logging.LoggingManagerInternal;
import org.gradle.internal.logging.StandardOutputCapture;
import org.gradle.internal.metaobject.BeanDynamicObject;
import org.gradle.internal.metaobject.DynamicObject;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.internal.service.ServiceRegistry;
import org.gradle.internal.service.scopes.ServiceRegistryFactory;
import org.gradle.internal.typeconversion.TypeConverter;
import org.gradle.listener.ClosureBackedMethodInvocationDispatch;
import org.gradle.model.Model;
import org.gradle.model.RuleSource;
import org.gradle.model.dsl.internal.NonTransformedModelDslBacking;
import org.gradle.model.dsl.internal.TransformedModelDslBacking;
import org.gradle.model.internal.core.DefaultNodeInitializerRegistry;
import org.gradle.model.internal.core.Hidden;
import org.gradle.model.internal.core.ModelReference;
import org.gradle.model.internal.core.ModelRegistrations;
import org.gradle.model.internal.core.NodeInitializerRegistry;
import org.gradle.model.internal.manage.binding.StructBindingsStore;
import org.gradle.model.internal.manage.instance.ManagedProxyFactory;
import org.gradle.model.internal.manage.schema.ModelSchemaStore;
import org.gradle.model.internal.registry.ModelRegistry;
import org.gradle.model.internal.type.ModelType;
import org.gradle.normalization.InputNormalizationHandler;
import org.gradle.process.ExecResult;
import org.gradle.process.ExecSpec;
import org.gradle.process.JavaExecSpec;
import org.gradle.util.Configurable;
import org.gradle.util.ConfigureUtil;
import org.gradle.util.DeprecationLogger;
import org.gradle.util.Path;
import javax.inject.Inject;
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.Collections.singletonMap;
import static org.gradle.util.ConfigureUtil.configureUsing;
import static org.gradle.util.GUtil.addMaps;
@NoConventionMapping
public class DefaultProject extends AbstractPluginAware implements ProjectInternal, DynamicObjectAware {
private static final ModelType<ServiceRegistry> SERVICE_REGISTRY_MODEL_TYPE = ModelType.of(ServiceRegistry.class);
private static final ModelType<File> FILE_MODEL_TYPE = ModelType.of(File.class);
private static final ModelType<ProjectIdentifier> PROJECT_IDENTIFIER_MODEL_TYPE = ModelType.of(ProjectIdentifier.class);
private static final ModelType<ExtensionContainer> EXTENSION_CONTAINER_MODEL_TYPE = ModelType.of(ExtensionContainer.class);
private static final Logger BUILD_LOGGER = Logging.getLogger(Project.class);
private final ClassLoaderScope classLoaderScope;
private final ClassLoaderScope baseClassLoaderScope;
private ServiceRegistry services;
private final ProjectInternal rootProject;
private final GradleInternal gradle;
private ProjectEvaluator projectEvaluator;
private ScriptSource buildScriptSource;
private final File projectDir;
private final ProjectInternal parent;
private final String name;
private Object group;
private Object version;
private Object status;
private final Map<String, Project> childProjects = Maps.newTreeMap();
private List<String> defaultTasks = new ArrayList<String>();
private ProjectStateInternal state;
private FileResolver fileResolver;
private Factory<AntBuilder> antBuilderFactory;
private AntBuilder ant;
private final int depth;
private TaskContainerInternal taskContainer;
private DependencyHandler dependencyHandler;
private ConfigurationContainer configurationContainer;
private ArtifactHandler artifactHandler;
private ListenerBroadcast<ProjectEvaluationListener> evaluationListener = new ListenerBroadcast<ProjectEvaluationListener>(ProjectEvaluationListener.class);
private ExtensibleDynamicObject extensibleDynamicObject;
private String description;
private final Path path;
private Path identityPath;
public DefaultProject(String name,
ProjectInternal parent,
File projectDir,
ScriptSource buildScriptSource,
GradleInternal gradle,
ServiceRegistryFactory serviceRegistryFactory,
ClassLoaderScope selfClassLoaderScope,
ClassLoaderScope baseClassLoaderScope) {
this.classLoaderScope = selfClassLoaderScope;
this.baseClassLoaderScope = baseClassLoaderScope;
assert name != null;
this.rootProject = parent != null ? parent.getRootProject() : this;
this.projectDir = projectDir;
this.parent = parent;
this.name = name;
this.state = new ProjectStateInternal();
this.buildScriptSource = buildScriptSource;
this.gradle = gradle;
if (parent == null) {
path = Path.ROOT;
depth = 0;
} else {
path = parent.getProjectPath().child(name);
depth = parent.getDepth() + 1;
}
services = serviceRegistryFactory.createFor(this);
taskContainer = services.newInstance(TaskContainerInternal.class);
extensibleDynamicObject = new ExtensibleDynamicObject(this, Project.class, services.get(Instantiator.class));
if (parent != null) {
extensibleDynamicObject.setParent(parent.getInheritedScope());
}
extensibleDynamicObject.addObject(taskContainer.getTasksAsDynamicObject(), ExtensibleDynamicObject.Location.AfterConvention);
evaluationListener.add(gradle.getProjectEvaluationBroadcaster());
populateModelRegistry(services.get(ModelRegistry.class));
}
@SuppressWarnings("unused")
static class BasicServicesRules extends RuleSource {
@Hidden @Model
SourceDirectorySetFactory sourceDirectorySetFactory(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(SourceDirectorySetFactory.class);
}
@Hidden @Model
ITaskFactory taskFactory(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(ITaskFactory.class);
}
@Hidden @Model
Instantiator instantiator(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(Instantiator.class);
}
@Hidden @Model
ModelSchemaStore schemaStore(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(ModelSchemaStore.class);
}
@Hidden @Model
ManagedProxyFactory proxyFactory(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(ManagedProxyFactory.class);
}
@Hidden @Model
StructBindingsStore structBindingsStore(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(StructBindingsStore.class);
}
@Hidden @Model
NodeInitializerRegistry nodeInitializerRegistry(ModelSchemaStore schemaStore, StructBindingsStore structBindingsStore) {
return new DefaultNodeInitializerRegistry(schemaStore, structBindingsStore);
}
@Hidden @Model
TypeConverter typeConverter(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(TypeConverter.class);
}
@Hidden @Model
FileOperations fileOperations(ServiceRegistry serviceRegistry) {
return serviceRegistry.get(FileOperations.class);
}
}
private void populateModelRegistry(ModelRegistry modelRegistry) {
registerServiceOn(modelRegistry, "serviceRegistry", SERVICE_REGISTRY_MODEL_TYPE, services, instanceDescriptorFor("serviceRegistry"));
// TODO:LPTR This ignores changes to Project.buildDir after model node has been created
registerFactoryOn(modelRegistry, "buildDir", FILE_MODEL_TYPE, new Factory<File>() {
@Override
public File create() {
return getBuildDir();
}
});
registerInstanceOn(modelRegistry, "projectIdentifier", PROJECT_IDENTIFIER_MODEL_TYPE, this);
registerInstanceOn(modelRegistry, "extensionContainer", EXTENSION_CONTAINER_MODEL_TYPE, getExtensions());
modelRegistry.getRoot().applyToSelf(BasicServicesRules.class);
}
private <T> void registerInstanceOn(ModelRegistry modelRegistry, String path, ModelType<T> type, T instance) {
registerFactoryOn(modelRegistry, path, type, Factories.constant(instance));
}
private <T> void registerFactoryOn(ModelRegistry modelRegistry, String path, ModelType<T> type, Factory<T> factory) {
modelRegistry.register(ModelRegistrations
.unmanagedInstance(ModelReference.of(path, type), factory)
.descriptor(instanceDescriptorFor(path))
.hidden(true)
.build());
}
private <T> void registerServiceOn(ModelRegistry modelRegistry, String path, ModelType<T> type, T instance, String descriptor) {
modelRegistry.register(ModelRegistrations.serviceInstance(ModelReference.of(path, type), instance)
.descriptor(descriptor)
.build()
);
}
private String instanceDescriptorFor(String path) {
return "Project.<init>." + path + "()";
}
@Override
public ProjectInternal getRootProject() {
return rootProject;
}
@Override
public GradleInternal getGradle() {
return gradle;
}
public ProjectEvaluator getProjectEvaluator() {
if (projectEvaluator == null) {
projectEvaluator = services.get(ProjectEvaluator.class);
}
return projectEvaluator;
}
public void setProjectEvaluator(ProjectEvaluator projectEvaluator) {
this.projectEvaluator = projectEvaluator;
}
@Inject
@Override
public ScriptHandler getBuildscript() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
public File getBuildFile() {
return getBuildscript().getSourceFile();
}
@Override
public void setScript(groovy.lang.Script buildScript) {
extensibleDynamicObject.addObject(new BeanDynamicObject(buildScript).withNoProperties().withNotImplementsMissing(),
ExtensibleDynamicObject.Location.BeforeConvention);
}
@Override
public ScriptSource getBuildScriptSource() {
return buildScriptSource;
}
@Override
public File getRootDir() {
return rootProject.getProjectDir();
}
@Override
public ProjectInternal getParent() {
return parent;
}
@Override
public ProjectIdentifier getParentIdentifier() {
return parent;
}
@Override
public DynamicObject getAsDynamicObject() {
return extensibleDynamicObject;
}
@Override
public DynamicObject getInheritedScope() {
return extensibleDynamicObject.getInheritable();
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public Object getGroup() {
if (group != null) {
return group;
} else if (this == rootProject) {
return "";
}
group = rootProject.getName() + (getParent() == rootProject ? "" : "." + getParent().getPath().substring(1).replace(':', '.'));
return group;
}
@Override
public void setGroup(Object group) {
this.group = group;
}
@Override
public Object getVersion() {
return version == null ? DEFAULT_VERSION : version;
}
@Override
public void setVersion(Object version) {
this.version = version;
}
@Override
public Object getStatus() {
return status == null ? DEFAULT_STATUS : status;
}
@Override
public void setStatus(Object status) {
this.status = status;
}
@Override
public Map<String, Project> getChildProjects() {
return childProjects;
}
@Override
public List<String> getDefaultTasks() {
return defaultTasks;
}
@Override
public void setDefaultTasks(List<String> defaultTasks) {
this.defaultTasks = defaultTasks;
}
@Override
public ProjectStateInternal getState() {
return state;
}
@Override
public FileResolver getFileResolver() {
if (fileResolver == null) {
fileResolver = services.get(FileResolver.class);
}
return fileResolver;
}
public void setFileResolver(FileResolver fileResolver) {
this.fileResolver = fileResolver;
}
public void setAnt(AntBuilder ant) {
this.ant = ant;
}
@Override
public ArtifactHandler getArtifacts() {
if (artifactHandler == null) {
artifactHandler = services.get(ArtifactHandler.class);
}
return artifactHandler;
}
public void setArtifactHandler(ArtifactHandler artifactHandler) {
this.artifactHandler = artifactHandler;
}
@Inject
@Override
public RepositoryHandler getRepositories() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
public ConfigurationContainer getConfigurations() {
if (configurationContainer == null) {
configurationContainer = services.get(ConfigurationContainer.class);
}
return configurationContainer;
}
public void setConfigurationContainer(ConfigurationContainer configurationContainer) {
this.configurationContainer = configurationContainer;
}
@Override
public Convention getConvention() {
return extensibleDynamicObject.getConvention();
}
@Override
public String getPath() {
return path.toString();
}
@Override
public Path getIdentityPath() {
if (identityPath == null) {
if (parent == null) {
identityPath = gradle.getIdentityPath();
} else {
identityPath = parent.getIdentityPath().child(name);
}
}
return identityPath;
}
@Override
public int getDepth() {
return depth;
}
@Inject
@Override
public ProjectRegistry<ProjectInternal> getProjectRegistry() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
public int depthCompare(Project otherProject) {
return new Integer(getDepth()).compareTo(otherProject.getDepth());
}
@Override
public int compareTo(Project otherProject) {
int depthCompare = depthCompare(otherProject);
if (depthCompare == 0) {
return getPath().compareTo(otherProject.getPath());
} else {
return depthCompare;
}
}
@Override
public String absoluteProjectPath(String path) {
return this.path.absolutePath(path);
}
@Override
public Path identityPath(String name) {
return getIdentityPath().child(name);
}
@Override
public Path getProjectPath() {
return path;
}
@Override
public Path projectPath(String name) {
return path.child(name);
}
@Override
public String relativeProjectPath(String path) {
return this.path.relativePath(path);
}
@Override
public ProjectInternal project(String path) {
ProjectInternal project = findProject(path);
if (project == null) {
throw new UnknownProjectException(String.format("Project with path '%s' could not be found in %s.", path, this));
}
return project;
}
@Override
public ProjectInternal findProject(String path) {
if (isNullOrEmpty(path)) {
throw new InvalidUserDataException("A path must be specified!");
}
return getProjectRegistry().getProject(absoluteProjectPath(path));
}
@Override
public Set<Project> getAllprojects() {
return new TreeSet<Project>(getProjectRegistry().getAllProjects(getPath()));
}
@Override
public Set<Project> getSubprojects() {
return new TreeSet<Project>(getProjectRegistry().getSubProjects(getPath()));
}
@Override
public void subprojects(Action<? super Project> action) {
getProjectConfigurator().subprojects(getSubprojects(), action);
}
@Override
public void allprojects(Action<? super Project> action) {
getProjectConfigurator().allprojects(getAllprojects(), action);
}
@Override
public <T> Iterable<T> configure(Iterable<T> objects, Action<? super T> configureAction) {
for (T object : objects) {
configureAction.execute(object);
}
return objects;
}
@Override
public AntBuilder getAnt() {
if (ant == null) {
ant = createAntBuilder();
}
return ant;
}
@Override
public AntBuilder createAntBuilder() {
return getAntBuilderFactory().create();
}
/**
* This method is used when scripts access the project via project.x
*/
@Override
public Project getProject() {
return this;
}
@Override
public DefaultProject evaluate() {
getProjectEvaluator().evaluate(this, state);
return this;
}
@Override
public ProjectInternal bindAllModelRules() {
try {
getModelRegistry().bindAllReferences();
} catch (Exception e) {
throw new ProjectConfigurationException(String.format("A problem occurred configuring %s.", this), e);
}
return this;
}
@Override
public TaskContainerInternal getTasks() {
return taskContainer;
}
@Override
public void defaultTasks(String... defaultTasks) {
if (defaultTasks == null) {
throw new InvalidUserDataException("Default tasks must not be null!");
}
this.defaultTasks = new ArrayList<String>();
for (String defaultTask : defaultTasks) {
if (defaultTask == null) {
throw new InvalidUserDataException("Default tasks must not be null!");
}
this.defaultTasks.add(defaultTask);
}
}
@Override
public void addChildProject(ProjectInternal childProject) {
childProjects.put(childProject.getName(), childProject);
}
@Override
public File getProjectDir() {
return projectDir;
}
@Override
public File getBuildDir() {
return getLayout().getBuildDirectory().getAsFile().get();
}
@Override
public void setBuildDir(File path) {
setBuildDir((Object) path);
}
@Override
public void setBuildDir(Object path) {
getLayout().setBuildDirectory(path);
}
@Override
public void evaluationDependsOnChildren() {
for (Project project : childProjects.values()) {
DefaultProject defaultProjectToEvaluate = (DefaultProject) project;
evaluationDependsOn(defaultProjectToEvaluate);
}
}
@Override
public Project evaluationDependsOn(String path) {
if (isNullOrEmpty(path)) {
throw new InvalidUserDataException("You must specify a project!");
}
DefaultProject projectToEvaluate = (DefaultProject) project(path);
return evaluationDependsOn(projectToEvaluate);
}
private Project evaluationDependsOn(DefaultProject projectToEvaluate) {
if (projectToEvaluate.getState().getExecuting()) {
throw new CircularReferenceException(String.format("Circular referencing during evaluation for %s.",
projectToEvaluate));
}
return projectToEvaluate.evaluate();
}
@Override
public String getDisplayName() {
StringBuilder builder = new StringBuilder();
if (parent == null && gradle.getParent() == null) {
builder.append("root project '");
builder.append(name);
builder.append('\'');
} else {
builder.append("project '");
builder.append(getIdentityPath());
builder.append("'");
}
return builder.toString();
}
@Override
public String toString() {
return getDisplayName();
}
@Override
public Map<Project, Set<Task>> getAllTasks(boolean recursive) {
final Map<Project, Set<Task>> foundTargets = new TreeMap<Project, Set<Task>>();
Action<Project> action = new Action<Project>() {
public void execute(Project project) {
foundTargets.put(project, new TreeSet<Task>(project.getTasks()));
}
};
if (recursive) {
allprojects(action);
} else {
action.execute(this);
}
return foundTargets;
}
@Override
public Set<Task> getTasksByName(final String name, boolean recursive) {
if (isNullOrEmpty(name)) {
throw new InvalidUserDataException("Name is not specified!");
}
final Set<Task> foundTasks = new HashSet<Task>();
Action<Project> action = new Action<Project>() {
public void execute(Project project) {
// Don't force evaluation of rules here, let the task container do what it needs to
((ProjectInternal) project).evaluate();
Task task = project.getTasks().findByName(name);
if (task != null) {
foundTasks.add(task);
}
}
};
if (recursive) {
allprojects(action);
} else {
action.execute(this);
}
return foundTasks;
}
@Inject
protected FileOperations getFileOperations() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
@Inject
public ProviderFactory getProviders() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
@Inject
public ObjectFactory getObjects() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
@Inject
public DefaultProjectLayout getLayout() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
public File file(Object path) {
return getFileOperations().file(path);
}
@Override
public File file(Object path, PathValidation validation) {
return getFileOperations().file(path, validation);
}
@Override
public URI uri(Object path) {
return getFileOperations().uri(path);
}
@Override
public ConfigurableFileCollection files(Object... paths) {
return getFileOperations().files(paths);
}
@Override
public ConfigurableFileCollection files(Object paths, Closure closure) {
return ConfigureUtil.configure(closure, files(paths));
}
@Override
public ConfigurableFileCollection files(Object paths, Action<? super ConfigurableFileCollection> configureAction) {
ConfigurableFileCollection files = files(paths);
configureAction.execute(files);
return files;
}
@Override
public ConfigurableFileTree fileTree(Object baseDir) {
return getFileOperations().fileTree(baseDir);
}
@Override
public ConfigurableFileTree fileTree(Object baseDir, Closure closure) {
return ConfigureUtil.configure(closure, fileTree(baseDir));
}
@Override
public ConfigurableFileTree fileTree(Object baseDir, Action<? super ConfigurableFileTree> configureAction) {
ConfigurableFileTree fileTree = fileTree(baseDir);
configureAction.execute(fileTree);
return fileTree;
}
@Override
public ConfigurableFileTree fileTree(Map<String, ?> args) {
return getFileOperations().fileTree(args);
}
@Override
public FileTree zipTree(Object zipPath) {
return getFileOperations().zipTree(zipPath);
}
@Override
public FileTree tarTree(Object tarPath) {
return getFileOperations().tarTree(tarPath);
}
@Override
public <T> Provider<T> provider(Callable<T> value) {
return getProviders().provider(value);
}
@Override
public <T> PropertyState<T> property(Class<T> clazz) {
return getProviders().property(clazz);
}
@Override
public ResourceHandler getResources() {
return getFileOperations().getResources();
}
@Override
public String relativePath(Object path) {
return getFileOperations().relativePath(path);
}
@Override
public File mkdir(Object path) {
return getFileOperations().mkdir(path);
}
@Override
public boolean delete(Object... paths) {
return getFileOperations().delete(paths);
}
@Override
public WorkResult delete(Action<? super DeleteSpec> action) {
return getFileOperations().delete(action);
}
public Factory<AntBuilder> getAntBuilderFactory() {
if (antBuilderFactory == null) {
antBuilderFactory = services.getFactory(AntBuilder.class);
}
return antBuilderFactory;
}
@Override
public DependencyHandler getDependencies() {
if (dependencyHandler == null) {
dependencyHandler = services.get(DependencyHandler.class);
}
return dependencyHandler;
}
public void setDependencyHandler(DependencyHandler dependencyHandler) {
this.dependencyHandler = dependencyHandler;
}
@Override
public ProjectEvaluationListener getProjectEvaluationBroadcaster() {
return evaluationListener.getSource();
}
@Override
public void beforeEvaluate(Action<? super Project> action) {
evaluationListener.add("beforeEvaluate", action);
}
@Override
public void afterEvaluate(Action<? super Project> action) {
evaluationListener.add("afterEvaluate", action);
}
@Override
public void beforeEvaluate(Closure closure) {
evaluationListener.add(new ClosureBackedMethodInvocationDispatch("beforeEvaluate", closure));
}
@Override
public void afterEvaluate(Closure closure) {
evaluationListener.add(new ClosureBackedMethodInvocationDispatch("afterEvaluate", closure));
}
@Override
public Logger getLogger() {
return BUILD_LOGGER;
}
@Override
public StandardOutputCapture getStandardOutputCapture() {
return getLogging();
}
@Inject
@Override
public LoggingManagerInternal getLogging() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Inject
@Override
public SoftwareComponentContainer getComponents() {
// Decoration takes care of the implementation
throw new UnsupportedOperationException();
}
@Override
public Object property(String propertyName) throws MissingPropertyException {
return extensibleDynamicObject.getProperty(propertyName);
}
@Override
public Object findProperty(String propertyName) {
return hasProperty(propertyName) ? property(propertyName) : null;
}
@Override
public void setProperty(String name, Object value) {