com.marvelution.hudson.plugins.apiv2.dozer.utils.DozerUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hudson-apiv2-plugin Show documentation
Show all versions of hudson-apiv2-plugin Show documentation
This plugin features a Wink REST API application.
The newest version!
/*
* Licensed to Marvelution under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Marvelution licenses this file to you 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 com.marvelution.hudson.plugins.apiv2.dozer.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.dozer.util.DozerConstants;
import com.marvelution.hudson.plugins.apiv2.utils.HudsonPluginUtils;
/**
* Utility class for the Dozer {@link Mapper} implementation
*
* @author Mark Rekveld
*/
public class DozerUtils {
private static final String DOZER_CONFIG_LOCATION = "META-INF/dozer/";
private static final String[] DOZER_MAPPINGS = {"custom-converters-dozer-mapping.xml",
"global-dozer-mapping.xml", "build-dozer-mapping.xml", "project-dozer-mapping.xml", "view-dozer-mapping.xml",
"healthreport-dozer-mapping.xml", "testresult-dozer-mapping.xml"};
private static final Logger LOGGER = Logger.getLogger(DozerUtils.class.getName());
private static DozerBeanMapper mapper = null;
private static List mappingFiles = null;
public static final String FULL_MAP_ID = "full";
public static final String NAMEONLY_MAP_ID = "nameOnly";
public static final String ACTIVITY_MAP_ID = "activity";
/**
* Get the {@link Mapper} implementation
*
* @return the {@link Mapper}
*/
public static Mapper getMapper() {
if (mapper == null) {
System.setProperty(DozerConstants.CONFIG_FILE_SYS_PROP, DOZER_CONFIG_LOCATION + "configuration.properties");
mapper = new DozerBeanMapper();
mapper.setMappingFiles(getMappingFiles());
}
return mapper;
}
/**
* Get all the custom Dozer mapping files
*
* @return {@link List} of all the mapping files
*/
public static List getMappingFiles() {
if (mappingFiles == null) {
// First load, add all the plugin default mappings
mappingFiles = new ArrayList();
for (String filename : DOZER_MAPPINGS) {
LOGGER.log(Level.FINE, "Loaded Dozer Mapping file: " + DOZER_CONFIG_LOCATION + filename);
mappingFiles.add(DOZER_CONFIG_LOCATION + filename);
}
}
if (HudsonPluginUtils.hasTestNGPlugin()) {
// TestNG plugin is used, add the TestNG Dozer mapping
mappingFiles.add(DOZER_CONFIG_LOCATION + "optional-testng-dozer-mapping.xml");
}
// TODO Support user specific mapping files
return mappingFiles;
}
}