o Fixed buggy anti-pattern

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@786892 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-20 19:39:56 +00:00
parent 12fbba751a
commit 2260cb2f58
5 changed files with 204 additions and 79 deletions

View File

@ -217,28 +217,52 @@ public class DefaultMavenExecutionRequest
public void setActiveProfiles( List<String> activeProfiles ) public void setActiveProfiles( List<String> activeProfiles )
{ {
getActiveProfiles().clear(); if ( activeProfiles != null )
getActiveProfiles().addAll( activeProfiles ); {
this.activeProfiles = new ArrayList<String>( activeProfiles );
}
else
{
this.activeProfiles = null;
}
} }
public void setInactiveProfiles( List<String> inactiveProfiles ) public void setInactiveProfiles( List<String> inactiveProfiles )
{ {
getInactiveProfiles().clear(); if ( inactiveProfiles != null )
getInactiveProfiles().addAll( inactiveProfiles ); {
this.inactiveProfiles = new ArrayList<String>( inactiveProfiles );
}
else
{
this.inactiveProfiles = null;
}
} }
public MavenExecutionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories ) public MavenExecutionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
{ {
getRemoteRepositories().clear(); if ( remoteRepositories != null )
getRemoteRepositories().addAll( remoteRepositories ); {
this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
}
else
{
this.remoteRepositories = null;
}
return this; return this;
} }
public MavenExecutionRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories ) public MavenExecutionRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
{ {
getPluginArtifactRepositories().clear(); if ( pluginArtifactRepositories != null )
getPluginArtifactRepositories().addAll( pluginArtifactRepositories ); {
this.pluginArtifactRepositories = new ArrayList<ArtifactRepository>( pluginArtifactRepositories );
}
else
{
this.pluginArtifactRepositories = null;
}
return this; return this;
} }
@ -328,8 +352,14 @@ public class DefaultMavenExecutionRequest
public MavenExecutionRequest setGoals( List<String> goals ) public MavenExecutionRequest setGoals( List<String> goals )
{ {
getGoals().clear(); if ( goals != null )
getGoals().addAll( goals ); {
this.goals = new ArrayList<String>( goals );
}
else
{
this.goals = null;
}
return this; return this;
} }
@ -357,8 +387,15 @@ public class DefaultMavenExecutionRequest
public MavenExecutionRequest setProperties( Properties properties ) public MavenExecutionRequest setProperties( Properties properties )
{ {
getProperties().clear(); if ( properties != null )
getProperties().putAll( properties ); {
this.properties = new Properties();
this.properties.putAll( properties );
}
else
{
this.properties = null;
}
return this; return this;
} }
@ -511,8 +548,14 @@ public class DefaultMavenExecutionRequest
public MavenExecutionRequest setProxies( List proxies ) public MavenExecutionRequest setProxies( List proxies )
{ {
getProxies().clear(); if ( proxies != null )
getProxies().addAll( proxies ); {
this.proxies = new ArrayList( proxies );
}
else
{
this.proxies = null;
}
return this; return this;
} }
@ -528,8 +571,14 @@ public class DefaultMavenExecutionRequest
public MavenExecutionRequest setServers( List servers ) public MavenExecutionRequest setServers( List servers )
{ {
getServers().clear(); if ( servers != null )
getServers().addAll( servers ); {
this.servers = new ArrayList( servers );
}
else
{
this.servers = null;
}
return this; return this;
} }
@ -545,8 +594,14 @@ public class DefaultMavenExecutionRequest
public MavenExecutionRequest setMirrors( List mirrors ) public MavenExecutionRequest setMirrors( List mirrors )
{ {
getMirrors().clear(); if ( mirrors != null )
getMirrors().addAll( mirrors ); {
this.mirrors = new ArrayList( mirrors );
}
else
{
this.mirrors = null;
}
return this; return this;
} }
@ -562,8 +617,14 @@ public class DefaultMavenExecutionRequest
public MavenExecutionRequest setProfiles( List<Profile> profiles ) public MavenExecutionRequest setProfiles( List<Profile> profiles )
{ {
getProfiles().clear(); if ( profiles != null )
getProfiles().addAll( profiles ); {
this.profiles = new ArrayList<Profile>( profiles );
}
else
{
this.profiles = null;
}
return this; return this;
} }
@ -580,8 +641,14 @@ public class DefaultMavenExecutionRequest
public MavenExecutionRequest setPluginGroups( List<String> pluginGroups ) public MavenExecutionRequest setPluginGroups( List<String> pluginGroups )
{ {
getPluginGroups().clear(); if ( pluginGroups != null )
getPluginGroups().addAll( pluginGroups ); {
this.pluginGroups = new ArrayList<String>( pluginGroups );
}
else
{
this.pluginGroups = null;
}
return this; return this;
} }

View File

@ -94,11 +94,13 @@ public class DefaultProjectBuildingRequest
public ProjectBuildingRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories ) public ProjectBuildingRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
{ {
this.remoteRepositories.clear();
if ( remoteRepositories != null ) if ( remoteRepositories != null )
{ {
this.remoteRepositories.addAll( remoteRepositories ); this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
}
else
{
this.remoteRepositories.clear();
} }
return this; return this;
@ -111,11 +113,13 @@ public class DefaultProjectBuildingRequest
public ProjectBuildingRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories ) public ProjectBuildingRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
{ {
this.pluginArtifactRepositories.clear();
if ( pluginArtifactRepositories != null ) if ( pluginArtifactRepositories != null )
{ {
this.pluginArtifactRepositories.addAll( pluginArtifactRepositories ); this.pluginArtifactRepositories = new ArrayList<ArtifactRepository>( pluginArtifactRepositories );
}
else
{
this.pluginArtifactRepositories.clear();
} }
return this; return this;
@ -128,12 +132,15 @@ public class DefaultProjectBuildingRequest
public ProjectBuildingRequest setExecutionProperties( Properties executionProperties ) public ProjectBuildingRequest setExecutionProperties( Properties executionProperties )
{ {
this.executionProperties.clear();
if ( executionProperties != null ) if ( executionProperties != null )
{ {
this.executionProperties = new Properties();
this.executionProperties.putAll( executionProperties ); this.executionProperties.putAll( executionProperties );
} }
else
{
this.executionProperties.clear();
}
return this; return this;
} }
@ -178,11 +185,13 @@ public class DefaultProjectBuildingRequest
public void setActiveProfileIds( List<String> activeProfileIds ) public void setActiveProfileIds( List<String> activeProfileIds )
{ {
this.activeProfileIds.clear();
if ( activeProfileIds != null ) if ( activeProfileIds != null )
{ {
this.activeProfileIds.addAll( activeProfileIds ); this.activeProfileIds = new ArrayList<String>( activeProfileIds );
}
else
{
this.activeProfileIds.clear();
} }
} }
@ -193,21 +202,25 @@ public class DefaultProjectBuildingRequest
public void setInactiveProfileIds( List<String> inactiveProfileIds ) public void setInactiveProfileIds( List<String> inactiveProfileIds )
{ {
this.inactiveProfileIds.clear();
if ( inactiveProfileIds != null ) if ( inactiveProfileIds != null )
{ {
this.inactiveProfileIds.addAll( inactiveProfileIds ); this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds );
}
else
{
this.inactiveProfileIds.clear();
} }
} }
public void setProfiles( List<Profile> profiles ) public void setProfiles( List<Profile> profiles )
{ {
this.profiles.clear();
if ( profiles != null ) if ( profiles != null )
{ {
this.profiles.addAll( profiles ); this.profiles = new ArrayList<Profile>( profiles );
}
else
{
this.profiles.clear();
} }
} }

View File

@ -51,14 +51,6 @@ public class DefaultModelBuildingRequest
private ModelResolver modelResolver; private ModelResolver modelResolver;
public DefaultModelBuildingRequest()
{
profiles = new ArrayList<Profile>();
activeProfileIds = new ArrayList<String>();
inactiveProfileIds = new ArrayList<String>();
executionProperties = new Properties();
}
public boolean istLenientValidation() public boolean istLenientValidation()
{ {
return lenientValidation; return lenientValidation;
@ -85,15 +77,23 @@ public class DefaultModelBuildingRequest
public List<Profile> getProfiles() public List<Profile> getProfiles()
{ {
if ( profiles == null )
{
profiles = new ArrayList<Profile>();
}
return profiles; return profiles;
} }
public DefaultModelBuildingRequest setProfiles( List<Profile> profiles ) public DefaultModelBuildingRequest setProfiles( List<Profile> profiles )
{ {
this.profiles.clear();
if ( profiles != null ) if ( profiles != null )
{ {
this.profiles.addAll( profiles ); this.profiles = new ArrayList<Profile>( profiles );
}
else
{
this.profiles = null;
} }
return this; return this;
@ -101,15 +101,23 @@ public class DefaultModelBuildingRequest
public List<String> getActiveProfileIds() public List<String> getActiveProfileIds()
{ {
if ( activeProfileIds == null )
{
activeProfileIds = new ArrayList<String>();
}
return activeProfileIds; return activeProfileIds;
} }
public DefaultModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds ) public DefaultModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds )
{ {
this.activeProfileIds.clear();
if ( activeProfileIds != null ) if ( activeProfileIds != null )
{ {
this.activeProfileIds.addAll( activeProfileIds ); this.activeProfileIds = new ArrayList<String>( activeProfileIds );
}
else
{
this.activeProfileIds = null;
} }
return this; return this;
@ -117,15 +125,23 @@ public class DefaultModelBuildingRequest
public List<String> getInactiveProfileIds() public List<String> getInactiveProfileIds()
{ {
if ( inactiveProfileIds == null )
{
inactiveProfileIds = new ArrayList<String>();
}
return inactiveProfileIds; return inactiveProfileIds;
} }
public DefaultModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds ) public DefaultModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds )
{ {
this.inactiveProfileIds.clear();
if ( inactiveProfileIds != null ) if ( inactiveProfileIds != null )
{ {
this.inactiveProfileIds.addAll( inactiveProfileIds ); this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds );
}
else
{
this.inactiveProfileIds = null;
} }
return this; return this;
@ -133,16 +149,25 @@ public class DefaultModelBuildingRequest
public Properties getExecutionProperties() public Properties getExecutionProperties()
{ {
if ( executionProperties == null )
{
executionProperties = new Properties();
}
return executionProperties; return executionProperties;
} }
public DefaultModelBuildingRequest setExecutionProperties( Properties executionProperties ) public DefaultModelBuildingRequest setExecutionProperties( Properties executionProperties )
{ {
this.executionProperties.clear();
if ( executionProperties != null ) if ( executionProperties != null )
{ {
this.executionProperties = new Properties();
this.executionProperties.putAll( executionProperties ); this.executionProperties.putAll( executionProperties );
} }
else
{
this.executionProperties = null;
}
return this; return this;
} }

View File

@ -135,11 +135,13 @@ class DefaultModelBuildingResult
public DefaultModelBuildingResult setActiveExternalProfiles( List<Profile> activeProfiles ) public DefaultModelBuildingResult setActiveExternalProfiles( List<Profile> activeProfiles )
{ {
this.activeExternalProfiles.clear();
if ( activeProfiles != null ) if ( activeProfiles != null )
{ {
this.activeExternalProfiles.addAll( activeProfiles ); this.activeExternalProfiles = new ArrayList<Profile>( activeProfiles );
}
else
{
this.activeExternalProfiles.clear();
} }
return this; return this;

View File

@ -38,24 +38,25 @@ public class DefaultProfileActivationContext
private Properties executionProperties; private Properties executionProperties;
public DefaultProfileActivationContext()
{
activeProfileIds = new ArrayList<String>();
inactiveProfileIds = new ArrayList<String>();
executionProperties = new Properties();
}
public List<String> getActiveProfileIds() public List<String> getActiveProfileIds()
{ {
if ( activeProfileIds == null )
{
activeProfileIds = new ArrayList<String>();
}
return activeProfileIds; return activeProfileIds;
} }
public DefaultProfileActivationContext setActiveProfileIds( List<String> activeProfileIds ) public DefaultProfileActivationContext setActiveProfileIds( List<String> activeProfileIds )
{ {
this.activeProfileIds.clear();
if ( activeProfileIds != null ) if ( activeProfileIds != null )
{ {
this.activeProfileIds.addAll( activeProfileIds ); this.activeProfileIds = new ArrayList<String>( activeProfileIds );
}
else
{
this.activeProfileIds = null;
} }
return this; return this;
@ -63,15 +64,23 @@ public class DefaultProfileActivationContext
public List<String> getInactiveProfileIds() public List<String> getInactiveProfileIds()
{ {
if ( inactiveProfileIds == null )
{
inactiveProfileIds = new ArrayList<String>();
}
return inactiveProfileIds; return inactiveProfileIds;
} }
public DefaultProfileActivationContext setInactiveProfileIds( List<String> inactiveProfileIds ) public DefaultProfileActivationContext setInactiveProfileIds( List<String> inactiveProfileIds )
{ {
this.inactiveProfileIds.clear();
if ( inactiveProfileIds != null ) if ( inactiveProfileIds != null )
{ {
this.inactiveProfileIds.addAll( inactiveProfileIds ); this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds );
}
else
{
this.inactiveProfileIds = null;
} }
return this; return this;
@ -79,16 +88,25 @@ public class DefaultProfileActivationContext
public Properties getExecutionProperties() public Properties getExecutionProperties()
{ {
if ( executionProperties == null )
{
executionProperties = new Properties();
}
return executionProperties; return executionProperties;
} }
public DefaultProfileActivationContext setExecutionProperties( Properties executionProperties ) public DefaultProfileActivationContext setExecutionProperties( Properties executionProperties )
{ {
this.executionProperties.clear();
if ( executionProperties != null ) if ( executionProperties != null )
{ {
this.executionProperties = new Properties();
this.executionProperties.putAll( executionProperties ); this.executionProperties.putAll( executionProperties );
} }
else
{
this.executionProperties = null;
}
return this; return this;
} }