001 package org.apache.maven.model.profile; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import java.io.File; 023 import java.util.Collections; 024 import java.util.List; 025 import java.util.Map; 026 import java.util.Properties; 027 028 /** 029 * Describes the environmental context used to determine the activation status of profiles. 030 * 031 * @author Benjamin Bentmann 032 */ 033 public class DefaultProfileActivationContext 034 implements ProfileActivationContext 035 { 036 037 private List<String> activeProfileIds = Collections.emptyList(); 038 039 private List<String> inactiveProfileIds = Collections.emptyList(); 040 041 private Map<String, String> systemProperties = Collections.emptyMap(); 042 043 private Map<String, String> userProperties = Collections.emptyMap(); 044 045 private File projectDirectory; 046 047 public List<String> getActiveProfileIds() 048 { 049 return activeProfileIds; 050 } 051 052 /** 053 * Sets the identifiers of those profiles that should be activated by explicit demand. 054 * 055 * @param activeProfileIds The identifiers of those profiles to activate, may be {@code null}. 056 * @return This context, never {@code null}. 057 */ 058 public DefaultProfileActivationContext setActiveProfileIds( List<String> activeProfileIds ) 059 { 060 if ( activeProfileIds != null ) 061 { 062 this.activeProfileIds = Collections.unmodifiableList( activeProfileIds ); 063 } 064 else 065 { 066 this.activeProfileIds = Collections.emptyList(); 067 } 068 069 return this; 070 } 071 072 public List<String> getInactiveProfileIds() 073 { 074 return inactiveProfileIds; 075 } 076 077 /** 078 * Sets the identifiers of those profiles that should be deactivated by explicit demand. 079 * 080 * @param inactiveProfileIds The identifiers of those profiles to deactivate, may be {@code null}. 081 * @return This context, never {@code null}. 082 */ 083 public DefaultProfileActivationContext setInactiveProfileIds( List<String> inactiveProfileIds ) 084 { 085 if ( inactiveProfileIds != null ) 086 { 087 this.inactiveProfileIds = Collections.unmodifiableList( inactiveProfileIds ); 088 } 089 else 090 { 091 this.inactiveProfileIds = Collections.emptyList(); 092 } 093 094 return this; 095 } 096 097 public Map<String, String> getSystemProperties() 098 { 099 return systemProperties; 100 } 101 102 /** 103 * Sets the system properties to use for interpolation and profile activation. The system properties are collected 104 * from the runtime environment like {@link System#getProperties()} and environment variables. 105 * 106 * @param systemProperties The system properties, may be {@code null}. 107 * @return This context, never {@code null}. 108 */ 109 @SuppressWarnings( "unchecked" ) 110 public DefaultProfileActivationContext setSystemProperties( Properties systemProperties ) 111 { 112 if ( systemProperties != null ) 113 { 114 this.systemProperties = Collections.unmodifiableMap( (Map) systemProperties ); 115 } 116 else 117 { 118 this.systemProperties = Collections.emptyMap(); 119 } 120 121 return this; 122 } 123 124 /** 125 * Sets the system properties to use for interpolation and profile activation. The system properties are collected 126 * from the runtime environment like {@link System#getProperties()} and environment variables. 127 * 128 * @param systemProperties The system properties, may be {@code null}. 129 * @return This context, never {@code null}. 130 */ 131 public DefaultProfileActivationContext setSystemProperties( Map<String, String> systemProperties ) 132 { 133 if ( systemProperties != null ) 134 { 135 this.systemProperties = Collections.unmodifiableMap( systemProperties ); 136 } 137 else 138 { 139 this.systemProperties = Collections.emptyMap(); 140 } 141 142 return this; 143 } 144 145 public Map<String, String> getUserProperties() 146 { 147 return userProperties; 148 } 149 150 /** 151 * Sets the user properties to use for interpolation and profile activation. The user properties have been 152 * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command 153 * line. 154 * 155 * @param userProperties The user properties, may be {@code null}. 156 * @return This context, never {@code null}. 157 */ 158 @SuppressWarnings( "unchecked" ) 159 public DefaultProfileActivationContext setUserProperties( Properties userProperties ) 160 { 161 if ( userProperties != null ) 162 { 163 this.userProperties = Collections.unmodifiableMap( (Map) userProperties ); 164 } 165 else 166 { 167 this.userProperties = Collections.emptyMap(); 168 } 169 170 return this; 171 } 172 173 /** 174 * Sets the user properties to use for interpolation and profile activation. The user properties have been 175 * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command 176 * line. 177 * 178 * @param userProperties The user properties, may be {@code null}. 179 * @return This context, never {@code null}. 180 */ 181 public DefaultProfileActivationContext setUserProperties( Map<String, String> userProperties ) 182 { 183 if ( userProperties != null ) 184 { 185 this.userProperties = Collections.unmodifiableMap( userProperties ); 186 } 187 else 188 { 189 this.userProperties = Collections.emptyMap(); 190 } 191 192 return this; 193 } 194 195 public File getProjectDirectory() 196 { 197 return projectDirectory; 198 } 199 200 /** 201 * Sets the base directory of the current project. 202 * 203 * @param projectDirectory The base directory of the current project, may be {@code null} if profile activation 204 * happens in the context of metadata retrieval rather than project building. 205 * @return This context, never {@code null}. 206 */ 207 public DefaultProfileActivationContext setProjectDirectory( File projectDirectory ) 208 { 209 this.projectDirectory = projectDirectory; 210 211 return this; 212 } 213 214 }