Project.java revision 271
98N/A/*
98N/A * CDDL HEADER START
199N/A *
98N/A * The contents of this file are subject to the terms of the
98N/A * Common Development and Distribution License (the "License").
98N/A * You may not use this file except in compliance with the License.
98N/A *
98N/A * See LICENSE.txt included in this distribution for the specific
98N/A * language governing permissions and limitations under the License.
98N/A *
98N/A * When distributing Covered Code, include this CDDL HEADER in each
98N/A * file and include the License file at LICENSE.txt.
98N/A * If applicable, add the following below this CDDL HEADER, with the
98N/A * fields enclosed by brackets "[]" replaced with your own identifying
98N/A * information: Portions Copyright [yyyy] [name of copyright owner]
98N/A *
98N/A * CDDL HEADER END
98N/A */
98N/A
98N/A/*
98N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
98N/A * Use is subject to license terms.
98N/A */
98N/Apackage org.opensolaris.opengrok.configuration;
98N/A
98N/Aimport java.io.File;
98N/A
98N/A/**
98N/A * Placeholder for the information that builds up a project
98N/A */
98N/Apublic class Project {
98N/A private String path;
217N/A private String description;
98N/A
98N/A /**
98N/A * Get a textual description of this project
199N/A * @return a textual description of the project
98N/A */
98N/A public String getDescription() {
217N/A return description;
98N/A }
98N/A
199N/A /**
199N/A * Get the path (relative from source root) where this project is located
98N/A * @return the relative path
98N/A */
98N/A public String getPath() {
98N/A return path;
98N/A }
98N/A
98N/A /**
98N/A * Get the project id
98N/A * @return the id of the project
98N/A */
98N/A public String getId() {
98N/A return path;
98N/A }
98N/A
98N/A /**
98N/A * Set a textual description of this project
98N/A * @param description a textual description of the project
98N/A */
98N/A public void setDescription(String description) {
199N/A this.description = description;
199N/A }
199N/A
98N/A /**
98N/A * Set the path (relative from source root) this project is located
98N/A * @param path the relative path from source sroot where this project is
199N/A * located.
*/
public void setPath(String path) {
this.path = path;
}
/**
* Creates a new instance of Project
*/
public Project() {
}
/**
* Create a new instance of Project with a given description and path
* @param description the description of this project
* @param path the path to where this project is located (relative from source root)
*/
public Project(String description, String path) {
this.description = description;
this.path = path;
}
/**
* Get the project for a specific file
* @param path the file to lookup (relative from source root)
* @return the project that this file belongs to (or null if the file
* doesn't belong to a project)
*/
public static Project getProject(String path) {
Project ret = null;
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.hasProjects()) {
for (Project proj : env.getProjects()) {
if (path.indexOf(proj.getPath()) == 0) {
ret = proj;
}
}
}
return ret;
}
/**
* Get the project for a specific file
* @param file the file to lookup
* @return the project that this file belongs to (or null if the file
* doesn't belong to a project)
*/
public static Project getProject(File file) {
Project ret = null;
String root = RuntimeEnvironment.getInstance().getSourceRootFile().getAbsolutePath();
String me = file.getAbsolutePath();
if (me.startsWith(root)) {
ret = getProject(me.substring(root.length()));
}
return ret;
}
}