Home | History | Annotate | Download | only in configuration
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * See LICENSE.txt included in this distribution for the specific
      9  * language governing permissions and limitations under the License.
     10  *
     11  * When distributing Covered Code, include this CDDL HEADER in each
     12  * file and include the License file at LICENSE.txt.
     13  * If applicable, add the following below this CDDL HEADER, with the
     14  * fields enclosed by brackets "[]" replaced with your own identifying
     15  * information: Portions Copyright [yyyy] [name of copyright owner]
     16  *
     17  * CDDL HEADER END
     18  */
     19 
     20 /*
     21  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     22  * Use is subject to license terms.
     23  */
     24 package org.opensolaris.opengrok.configuration;
     25 
     26 import java.io.File;
     27 
     28 /**
     29  * Placeholder for the information that builds up a project
     30  */
     31 public class Project {
     32     private String path;
     33     private String description;
     34 
     35     /**
     36      * Get a textual description of this project
     37      * @return a textual description of the project
     38      */
     39     public String getDescription() {
     40         return description;
     41     }
     42 
     43     /**
     44      * Get the path (relative from source root) where this project is located
     45      * @return the relative path
     46      */
     47     public String getPath() {
     48         return path;
     49     }
     50 
     51     /**
     52      * Get the project id
     53      * @return the id of the project
     54      */
     55     public String getId() {
     56         return path;
     57     }
     58 
     59     /**
     60      * Set a textual description of this project
     61      * @param description a textual description of the project
     62      */
     63     public void setDescription(String description) {
     64         this.description = description;
     65     }
     66 
     67     /**
     68      * Set the path (relative from source root) this project is located
     69      * @param path the relative path from source sroot where this project is
     70      *             located.
     71      */
     72     public void setPath(String path) {
     73         this.path = path;
     74     }
     75 
     76     /**
     77      * Get the project for a specific file
     78      * @param path the file to lookup (relative from source root)
     79      * @return the project that this file belongs to (or null if the file
     80      *         doesn't belong to a project)
     81      */
     82     public static Project getProject(String path) {
     83         Project ret = null;
     84         RuntimeEnvironment env = RuntimeEnvironment.getInstance();
     85         if (env.hasProjects()) {
     86             for (Project proj : env.getProjects()) {
     87                 if (path.indexOf(proj.getPath()) == 0) {
     88                     ret = proj;
     89                 }
     90             }
     91         }
     92         return ret;
     93     }
     94 
     95     /**
     96      * Get the project for a specific file
     97      * @param file the file to lookup
     98      * @return the project that this file belongs to (or null if the file
     99      *         doesn't belong to a project)
    100      */
    101     public static Project getProject(File file) {
    102         Project ret = null;
    103         String root = RuntimeEnvironment.getInstance().getSourceRootFile().getAbsolutePath();
    104         String me = file.getAbsolutePath();
    105         if (me.startsWith(root)) {
    106             ret = getProject(me.substring(root.length()));
    107         }
    108         return ret;
    109     }
    110 }
    111