92
92
public class MavenProject
93
93
implements Cloneable
94
94
{
95
+
95
96
private static final Logger LOGGER = LoggerFactory .getLogger ( MavenProject .class );
97
+
96
98
public static final String EMPTY_PROJECT_GROUP_ID = "unknown" ;
99
+
97
100
public static final String EMPTY_PROJECT_ARTIFACT_ID = "empty-project" ;
101
+
98
102
public static final String EMPTY_PROJECT_VERSION = "0" ;
99
103
100
104
private Model model ;
@@ -107,6 +111,10 @@ public class MavenProject
107
111
108
112
private Set <Artifact > resolvedArtifacts ;
109
113
114
+ private ArtifactFilter artifactFilter ;
115
+
116
+ private Set <Artifact > artifacts ;
117
+
110
118
private Artifact parentArtifact ;
111
119
112
120
private Set <Artifact > pluginArtifacts ;
@@ -143,7 +151,8 @@ public class MavenProject
143
151
144
152
private Artifact artifact ;
145
153
146
- private ThreadLocal <ArtifactsHolder > threadLocalArtifactsHolder = newThreadLocalArtifactsHolder ();
154
+ // calculated.
155
+ private Map <String , Artifact > artifactMap ;
147
156
148
157
private Model originalModel ;
149
158
@@ -176,21 +185,12 @@ public class MavenProject
176
185
public MavenProject ()
177
186
{
178
187
Model model = new Model ();
188
+
179
189
model .setGroupId ( EMPTY_PROJECT_GROUP_ID );
180
190
model .setArtifactId ( EMPTY_PROJECT_ARTIFACT_ID );
181
191
model .setVersion ( EMPTY_PROJECT_VERSION );
182
- setModel ( model );
183
- }
184
192
185
- private static ThreadLocal <ArtifactsHolder > newThreadLocalArtifactsHolder ()
186
- {
187
- return new ThreadLocal <ArtifactsHolder >()
188
- {
189
- protected ArtifactsHolder initialValue ()
190
- {
191
- return new ArtifactsHolder ();
192
- }
193
- };
193
+ setModel ( model );
194
194
}
195
195
196
196
public MavenProject ( Model model )
@@ -695,11 +695,10 @@ public void addLicense( License license )
695
695
696
696
public void setArtifacts ( Set <Artifact > artifacts )
697
697
{
698
- ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder .get ();
699
- artifactsHolder .artifacts = artifacts ;
698
+ this .artifacts = artifacts ;
700
699
701
700
// flush the calculated artifactMap
702
- artifactsHolder . artifactMap = null ;
701
+ artifactMap = null ;
703
702
}
704
703
705
704
/**
@@ -712,36 +711,34 @@ public void setArtifacts( Set<Artifact> artifacts )
712
711
*/
713
712
public Set <Artifact > getArtifacts ()
714
713
{
715
- ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder .get ();
716
- if ( artifactsHolder .artifacts == null )
714
+ if ( artifacts == null )
717
715
{
718
- if ( artifactsHolder . artifactFilter == null || resolvedArtifacts == null )
716
+ if ( artifactFilter == null || resolvedArtifacts == null )
719
717
{
720
- artifactsHolder . artifacts = new LinkedHashSet <>();
718
+ artifacts = new LinkedHashSet <>();
721
719
}
722
720
else
723
721
{
724
- artifactsHolder . artifacts = new LinkedHashSet <>( resolvedArtifacts .size () * 2 );
722
+ artifacts = new LinkedHashSet <>( resolvedArtifacts .size () * 2 );
725
723
for ( Artifact artifact : resolvedArtifacts )
726
724
{
727
- if ( artifactsHolder . artifactFilter .include ( artifact ) )
725
+ if ( artifactFilter .include ( artifact ) )
728
726
{
729
- artifactsHolder . artifacts .add ( artifact );
727
+ artifacts .add ( artifact );
730
728
}
731
729
}
732
730
}
733
731
}
734
- return artifactsHolder . artifacts ;
732
+ return artifacts ;
735
733
}
736
734
737
735
public Map <String , Artifact > getArtifactMap ()
738
736
{
739
- ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder .get ();
740
- if ( artifactsHolder .artifactMap == null )
737
+ if ( artifactMap == null )
741
738
{
742
- artifactsHolder . artifactMap = ArtifactUtils .artifactMapByVersionlessId ( getArtifacts () );
739
+ artifactMap = ArtifactUtils .artifactMapByVersionlessId ( getArtifacts () );
743
740
}
744
- return artifactsHolder . artifactMap ;
741
+ return artifactMap ;
745
742
}
746
743
747
744
public void setPluginArtifacts ( Set <Artifact > pluginArtifacts )
@@ -1186,8 +1183,7 @@ public MavenProject clone()
1186
1183
{
1187
1184
throw new UnsupportedOperationException ( e );
1188
1185
}
1189
- // clone must have it's own TL, otherwise the artifacts are intermingled!
1190
- clone .threadLocalArtifactsHolder = newThreadLocalArtifactsHolder ();
1186
+
1191
1187
clone .deepCopy ( this );
1192
1188
1193
1189
return clone ;
@@ -1230,7 +1226,6 @@ private void deepCopy( MavenProject project )
1230
1226
// copy fields
1231
1227
file = project .file ;
1232
1228
basedir = project .basedir ;
1233
- threadLocalArtifactsHolder .set ( project .threadLocalArtifactsHolder .get ().copy () );
1234
1229
1235
1230
// don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be
1236
1231
// sure!
@@ -1239,6 +1234,11 @@ private void deepCopy( MavenProject project )
1239
1234
setDependencyArtifacts ( Collections .unmodifiableSet ( project .getDependencyArtifacts () ) );
1240
1235
}
1241
1236
1237
+ if ( project .getArtifacts () != null )
1238
+ {
1239
+ setArtifacts ( Collections .unmodifiableSet ( project .getArtifacts () ) );
1240
+ }
1241
+
1242
1242
if ( project .getParentFile () != null )
1243
1243
{
1244
1244
parentFile = new File ( project .getParentFile ().getAbsolutePath () );
@@ -1433,9 +1433,8 @@ public DependencyFilter getExtensionDependencyFilter()
1433
1433
public void setResolvedArtifacts ( Set <Artifact > artifacts )
1434
1434
{
1435
1435
this .resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections .<Artifact >emptySet ();
1436
- ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder .get ();
1437
- artifactsHolder .artifacts = null ;
1438
- artifactsHolder .artifactMap = null ;
1436
+ this .artifacts = null ;
1437
+ this .artifactMap = null ;
1439
1438
}
1440
1439
1441
1440
/**
@@ -1448,10 +1447,9 @@ public void setResolvedArtifacts( Set<Artifact> artifacts )
1448
1447
*/
1449
1448
public void setArtifactFilter ( ArtifactFilter artifactFilter )
1450
1449
{
1451
- ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder .get ();
1452
- artifactsHolder .artifactFilter = artifactFilter ;
1453
- artifactsHolder .artifacts = null ;
1454
- artifactsHolder .artifactMap = null ;
1450
+ this .artifactFilter = artifactFilter ;
1451
+ this .artifacts = null ;
1452
+ this .artifactMap = null ;
1455
1453
}
1456
1454
1457
1455
/**
@@ -1481,7 +1479,13 @@ public void addLifecyclePhase( String lifecyclePhase )
1481
1479
1482
1480
// ----------------------------------------------------------------------------------------------------------------
1483
1481
//
1484
- // D E P R E C A T E D - Everything below will be removed for Maven 4.0.0
1482
+ //
1483
+ // D E P R E C A T E D
1484
+ //
1485
+ //
1486
+ // ----------------------------------------------------------------------------------------------------------------
1487
+ //
1488
+ // Everything below will be removed for Maven 4.0.0
1485
1489
//
1486
1490
// ----------------------------------------------------------------------------------------------------------------
1487
1491
@@ -1502,6 +1506,7 @@ public String getModulePathAdjustment( MavenProject moduleProject )
1502
1506
if ( moduleFile != null )
1503
1507
{
1504
1508
File moduleDir = moduleFile .getCanonicalFile ().getParentFile ();
1509
+
1505
1510
module = moduleDir .getName ();
1506
1511
}
1507
1512
@@ -1822,6 +1827,7 @@ public Reporting getReporting()
1822
1827
public void setReportArtifacts ( Set <Artifact > reportArtifacts )
1823
1828
{
1824
1829
this .reportArtifacts = reportArtifacts ;
1830
+
1825
1831
reportArtifactMap = null ;
1826
1832
}
1827
1833
@@ -1838,13 +1844,15 @@ public Map<String, Artifact> getReportArtifactMap()
1838
1844
{
1839
1845
reportArtifactMap = ArtifactUtils .artifactMapByVersionlessId ( getReportArtifacts () );
1840
1846
}
1847
+
1841
1848
return reportArtifactMap ;
1842
1849
}
1843
1850
1844
1851
@ Deprecated
1845
1852
public void setExtensionArtifacts ( Set <Artifact > extensionArtifacts )
1846
1853
{
1847
1854
this .extensionArtifacts = extensionArtifacts ;
1855
+
1848
1856
extensionArtifactMap = null ;
1849
1857
}
1850
1858
@@ -1861,6 +1869,7 @@ public Map<String, Artifact> getExtensionArtifactMap()
1861
1869
{
1862
1870
extensionArtifactMap = ArtifactUtils .artifactMapByVersionlessId ( getExtensionArtifacts () );
1863
1871
}
1872
+
1864
1873
return extensionArtifactMap ;
1865
1874
}
1866
1875
@@ -1878,6 +1887,7 @@ public List<ReportPlugin> getReportPlugins()
1878
1887
public Xpp3Dom getReportConfiguration ( String pluginGroupId , String pluginArtifactId , String reportSetId )
1879
1888
{
1880
1889
Xpp3Dom dom = null ;
1890
+
1881
1891
// ----------------------------------------------------------------------
1882
1892
// I would like to be able to lookup the Mojo object using a key but
1883
1893
// we have a limitation in modello that will be remedied shortly. So
@@ -1981,20 +1991,4 @@ public void setProjectBuildingRequest( ProjectBuildingRequest projectBuildingReq
1981
1991
{
1982
1992
this .projectBuilderConfiguration = projectBuildingRequest ;
1983
1993
}
1984
-
1985
- private static class ArtifactsHolder
1986
- {
1987
- private ArtifactFilter artifactFilter ;
1988
- private Set <Artifact > artifacts ;
1989
- private Map <String , Artifact > artifactMap ;
1990
-
1991
- ArtifactsHolder copy ()
1992
- {
1993
- ArtifactsHolder copy = new ArtifactsHolder ();
1994
- copy .artifactFilter = artifactFilter ;
1995
- copy .artifacts = artifacts != null ? new LinkedHashSet <>( artifacts ) : null ;
1996
- copy .artifactMap = artifactMap != null ? new LinkedHashMap <>( artifactMap ) : null ;
1997
- return copy ;
1998
- }
1999
- }
2000
1994
}
0 commit comments