/** * This work was created by participants in the DataONE project, and is * jointly copyrighted by participating institutions in DataONE. For * more information on DataONE, see our web site at http://dataone.org. * * Copyright ${year} * * Licensed 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. * * $Id$ */ package org.dataone.cn.utility.versiontool; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.jar.Attributes; import java.util.jar.Manifest; import org.apache.commons.lang3.StringUtils; public class ComponentVersionInfo { private final DateFormat format = new SimpleDateFormat("MM/dd/yyyy:HH:mm"); private static final String D1_VERSION = "D1-version"; private static final String D1_BRANCH = "D1-SCM-Branch"; private static final String D1_REVISION = "D1-SCM-Revision"; private static final String D1_BUILD_TIME = "D1-Build-TimeStamp"; private String name = ""; private String path = ""; private String version = ""; private String branch = ""; private String revision = ""; private long buildTime; private String buildTimeString = ""; private boolean dependent = false; private List dependencies = new ArrayList(); public ComponentVersionInfo(String artifactName, String path, String version, String branch, String revision, long buildMilliseconds) { this.name = artifactName; if (path != null) { this.path = path; } if (version != null) { this.version = version; } if (branch != null) { this.branch = branch; } if (revision != null) { this.revision = revision; } this.buildTime = buildMilliseconds; this.buildTimeString = format.format(new Date(buildMilliseconds)); } public ComponentVersionInfo(String name, String path, Manifest manifest) { this.name = name; if (path != null) { this.path = path; } if (manifest != null) { Attributes attribs = manifest.getMainAttributes(); if (attribs.getValue(D1_VERSION) != null) { version = attribs.getValue(D1_VERSION); } if (attribs.getValue(D1_BRANCH) != null) { branch = attribs.getValue(D1_BRANCH); } if (attribs.getValue(D1_REVISION) != null) { revision = attribs.getValue(D1_REVISION); } if (StringUtils.isNotEmpty(attribs.getValue(D1_BUILD_TIME))) { buildTime = Long.parseLong(attribs.getValue(D1_BUILD_TIME)); this.buildTimeString = format.format(buildTime); } } } public String getName() { return name; } public String getPath() { return path; } public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } public String getBranch() { return branch; } public String getRevision() { return revision; } public long getBuildTime() { return buildTime; } public String getBuildTimeString() { return buildTimeString; } public boolean isDependent() { return dependent; } public boolean isMainComponent() { return !dependent; } private void setDependent(boolean depVal) { dependent = depVal; } public void addDependency(ComponentVersionInfo cvi) { cvi.setDependent(true); dependencies.add(cvi); } public List getDependencies() { return dependencies; } }