Adding Git source, NetBeans project files, GPL v2 LICENSE, ant build file.
[nbgit.git] / src / org / netbeans / modules / git / ui / log / GitLogMessage.java
blobb7417ed1d5b86b0e8c6050d69b2470a650d08f64
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git.ui.log;
44 import java.io.File;
45 import java.util.ArrayList;
46 import java.util.Date;
47 import java.util.List;
48 import org.netbeans.modules.git.FileInformation;
49 import org.netbeans.modules.git.FileStatus;
50 import org.netbeans.modules.git.Git;
51 import org.netbeans.modules.git.OutputLogger;
54 /**
56 * @author jr140578
58 public class GitLogMessage {
59 private char mod = 'M';
60 private char add = 'A';
61 private char del = 'R';
62 private char copy = 'C';
64 private List<GitLogMessageChangedPath> mpaths;
65 private List<GitLogMessageChangedPath> apaths;
66 private List<GitLogMessageChangedPath> dpaths;
67 private List<GitLogMessageChangedPath> cpaths;
68 private String rev;
69 private String author;
70 private String desc;
71 private Date date;
72 private String id;
74 public GitLogMessage(String changeset){
77 public GitLogMessage( String rev, String auth, String desc, String date, String id,
78 String fm, String fa, String fd, String fc){
79 String splits[];
81 this.rev = rev;
82 this.author = auth;
83 this.desc = desc;
84 splits = date.split(" ");
85 this.date = new Date(Long.parseLong(splits[0]) * 1000); // UTC in miliseconds
86 this.id = id;
87 this.mpaths = new ArrayList<GitLogMessageChangedPath>();
88 this.apaths = new ArrayList<GitLogMessageChangedPath>();
89 this.dpaths = new ArrayList<GitLogMessageChangedPath>();
90 this.cpaths = new ArrayList<GitLogMessageChangedPath>();
92 if( fm != null && !fm.equals("")){
93 splits = fm.split(" ");
94 for(String s: splits){
95 this.mpaths.add(new GitLogMessageChangedPath(s, mod));
96 logCopied(s);
99 if( fa != null && !fa.equals("")){
100 splits = fa.split(" ");
101 for(String s: splits){
102 this.apaths.add(new GitLogMessageChangedPath(s, add));
103 logCopied(s);
106 if( fd != null && !fd.equals("")){
107 splits = fd.split(" ");
108 for(String s: splits){
109 this.dpaths.add(new GitLogMessageChangedPath(s, del));
110 logCopied(s);
113 if( fc != null && !fc.equals("")){
114 splits = fc.split(" ");
115 for(String s: splits){
116 this.cpaths.add(new GitLogMessageChangedPath(s, copy));
117 logCopied(s);
122 private void logCopied(String s){
123 File file = new File(s);
124 FileInformation fi = Git.getInstance().getFileStatusCache().getStatus(file);
125 FileStatus fs = fi != null? fi.getStatus(file): null;
126 if (fs != null && fs.isCopied()) {
127 OutputLogger logger = OutputLogger.getLogger(Git.GIT_OUTPUT_TAB_TITLE);
129 logger.outputInRed("*** Copied: " + s + " : " + fs.getFile() != null ? fs.getFile().getAbsolutePath() : "no filepath");
130 logger.closeLog();
134 public GitLogMessageChangedPath [] getChangedPaths(){
135 List<GitLogMessageChangedPath> paths = new ArrayList<GitLogMessageChangedPath>();
136 if(!mpaths.isEmpty()) paths.addAll(mpaths);
137 if(!apaths.isEmpty()) paths.addAll(apaths);
138 if(!dpaths.isEmpty()) paths.addAll(dpaths);
139 if(!cpaths.isEmpty()) paths.addAll(cpaths);
140 return paths.toArray(new GitLogMessageChangedPath[0]);
142 public String getRevision() {
143 return rev;
145 public Date getDate() {
146 return date;
148 public String getAuthor() {
149 return author;
151 public String getCSetShortID() {
152 return id;
154 public String getMessage() {
155 return desc;
158 @Override
159 public String toString(){
160 String s = null;
162 s = "rev: " + this.rev +
163 "\nauthor: " + this.author +
164 "\ndesc: " + this.desc +
165 "\ndate: " + this.date +
166 "\nid: " + this.id +
167 "\nfm: " + this.mpaths +
168 "\nfa: " + this.apaths +
169 "\nfd: " + this.dpaths +
170 "\nfc: " + this.cpaths;
172 return s;