001package org.kuali.common.devops.metadata.function; 002 003import static org.kuali.common.util.Encodings.UTF8; 004import static org.kuali.common.util.base.Exceptions.illegalState; 005import static org.kuali.common.util.base.Precondition.checkNotNull; 006 007import java.io.ByteArrayInputStream; 008import java.io.IOException; 009import java.util.Properties; 010 011import org.kuali.common.util.project.ProjectUtils; 012import org.kuali.common.util.project.model.Project; 013 014import com.google.common.base.Function; 015 016public class ProjectFunction implements Function<String, Project> { 017 018 @Override 019 public Project apply(String content) { 020 checkNotNull(content, "content"); 021 Properties properties = getProperties(content); 022 return ProjectUtils.getProject(properties); 023 } 024 025 protected Properties getProperties(String content) { 026 try { 027 ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes(UTF8)); 028 Properties props = new Properties(); 029 props.load(in); 030 return props; 031 } catch (IOException e) { 032 throw illegalState(e, "unexpected io error loading properties -> \n\n%s\n\n", content); 033 } 034 } 035 036}