001: package org.apache.maven.profiles;
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 org.apache.maven.model.Activation;
023: import org.apache.maven.model.ActivationFile;
024: import org.apache.maven.model.ActivationProperty;
025: import org.apache.maven.model.Profile;
026: import org.apache.maven.model.Repository;
027:
028: import java.util.Iterator;
029: import java.util.List;
030:
031: public class ProfilesConversionUtils {
032: private ProfilesConversionUtils() {
033: }
034:
035: public static Profile convertFromProfileXmlProfile(
036: org.apache.maven.profiles.Profile profileXmlProfile) {
037: Profile profile = new Profile();
038:
039: profile.setId(profileXmlProfile.getId());
040:
041: profile.setSource("profiles.xml");
042:
043: org.apache.maven.profiles.Activation profileActivation = profileXmlProfile
044: .getActivation();
045:
046: if (profileActivation != null) {
047: Activation activation = new Activation();
048:
049: activation.setActiveByDefault(profileActivation
050: .isActiveByDefault());
051:
052: activation.setJdk(profileActivation.getJdk());
053:
054: org.apache.maven.profiles.ActivationProperty profileProp = profileActivation
055: .getProperty();
056:
057: if (profileProp != null) {
058: ActivationProperty prop = new ActivationProperty();
059:
060: prop.setName(profileProp.getName());
061: prop.setValue(profileProp.getValue());
062:
063: activation.setProperty(prop);
064: }
065:
066: ActivationOS profileOs = profileActivation.getOs();
067:
068: if (profileOs != null) {
069: org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS();
070:
071: os.setArch(profileOs.getArch());
072: os.setFamily(profileOs.getFamily());
073: os.setName(profileOs.getName());
074: os.setVersion(profileOs.getVersion());
075: }
076:
077: org.apache.maven.profiles.ActivationFile profileFile = profileActivation
078: .getFile();
079:
080: if (profileFile != null) {
081: ActivationFile file = new ActivationFile();
082:
083: file.setExists(profileFile.getExists());
084: file.setMissing(profileFile.getMissing());
085:
086: activation.setFile(file);
087: }
088:
089: profile.setActivation(activation);
090: } else {
091: profile.setActivation(new AlwaysOnActivation());
092: }
093:
094: profile.setProperties(profileXmlProfile.getProperties());
095:
096: List repos = profileXmlProfile.getRepositories();
097: if (repos != null) {
098: for (Iterator it = repos.iterator(); it.hasNext();) {
099: profile
100: .addRepository(convertFromProfileXmlRepository((org.apache.maven.profiles.Repository) it
101: .next()));
102: }
103: }
104:
105: List pluginRepos = profileXmlProfile.getPluginRepositories();
106: if (pluginRepos != null) {
107: for (Iterator it = pluginRepos.iterator(); it.hasNext();) {
108: profile
109: .addPluginRepository(convertFromProfileXmlRepository((org.apache.maven.profiles.Repository) it
110: .next()));
111: }
112: }
113:
114: return profile;
115: }
116:
117: private static Repository convertFromProfileXmlRepository(
118: org.apache.maven.profiles.Repository profileXmlRepo) {
119: Repository repo = new Repository();
120:
121: repo.setId(profileXmlRepo.getId());
122: repo.setLayout(profileXmlRepo.getLayout());
123: repo.setName(profileXmlRepo.getName());
124: repo.setUrl(profileXmlRepo.getUrl());
125:
126: if (profileXmlRepo.getSnapshots() != null) {
127: repo.setSnapshots(convertRepositoryPolicy(profileXmlRepo
128: .getSnapshots()));
129: }
130: if (profileXmlRepo.getReleases() != null) {
131: repo.setReleases(convertRepositoryPolicy(profileXmlRepo
132: .getReleases()));
133: }
134:
135: return repo;
136: }
137:
138: private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy(
139: RepositoryPolicy profileXmlRepo) {
140: org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy();
141: policy.setEnabled(profileXmlRepo.isEnabled());
142: policy.setUpdatePolicy(profileXmlRepo.getUpdatePolicy());
143: policy.setChecksumPolicy(profileXmlRepo.getChecksumPolicy());
144: return policy;
145: }
146:
147: }
|