1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: ImportProject.java,v $
19 Created on $Date: 2003/09/11 10:16:27 $
20 */
21 package net.sf.bloof;
22
23 import java.io.IOException;
24 import java.sql.Connection;
25 import java.sql.SQLException;
26
27 import net.sf.bloof.db.Database;
28 import net.sf.bloof.db.DbAccess;
29 import net.sf.bloof.db.McKoiControl;
30 import net.sf.bloof.db.PostgresControl;
31 import net.sf.bloof.events.BloofEvent;
32 import net.sf.bloof.scm.ScmAccess;
33 import net.sf.bloof.scm.ScmAccessException;
34 import net.sf.bloof.scm.ScmRevisionIterator;
35 import net.sf.bloof.scm.cvsplugin.CvsPlugin;
36 import net.sf.bloof.util.ProgressEvent;
37 import net.sf.bloof.util.intl.Messages;
38 import net.sf.bloof.util.intl.Text;
39
40 /***
41 * Imports a new Project in a seperate thread.
42 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
43 * @version $Id: ImportProject.java,v 1.5 2003/09/11 10:16:27 pekacki Exp $
44 */
45 public class ImportProject implements Runnable {
46 /***
47 * Constructs a ImportProject class
48 * @param aDbAccess access to the database
49 * @param aScmAccess access to the version control system
50 */
51 public ImportProject(DbAccess aDbAccess, ScmAccess aScmAccess) {
52 mDbAccess = aDbAccess;
53 mScmAccess = aScmAccess;
54 }
55
56 private void newProject() throws SQLException, ScmAccessException, IOException {
57 Bloof.propagateProgressEvent(
58 new ProgressEvent(Messages.getString(Text.CREATING_DATABASE), 10));
59 Database db = null;
60 if (mDbAccess == Bloof.INTERNAL_DATABASE) {
61 /* start and connect to existing internal Database */
62 Connection c;
63 try {
64 c = McKoiControl.create(mDbAccess);
65 } catch (IOException e) {
66 throw new SQLException("Could not open internal database." + e.toString());
67 }
68 McKoiControl.createIndices();
69 db = new Database(c);
70 Bloof.setDatabase(db);
71
72 } else if (PostgresControl.isMyUrl(mDbAccess.getDatabaseUrl())) {
73 Connection c;
74 try {
75 c = PostgresControl.create(mDbAccess);
76 } catch (IOException e) {
77 throw new SQLException("Could not open postgres database." + e.toString());
78 }
79 PostgresControl.createIndices();
80 db = new Database(c);
81 Bloof.setDatabase(db);
82
83 } else if (McKoiControl.isMyUrl(mDbAccess.getDatabaseUrl())) {
84 Connection c;
85 try {
86 c = McKoiControl.createRemoteConnection(mDbAccess);
87 } catch (IOException e) {
88 throw new SQLException("Could not open McKoi database." + e.toString());
89 }
90 McKoiControl.createIndices();
91 db = new Database(c);
92 Bloof.setDatabase(db);
93
94 } else {
95 Bloof.fail(Messages.getString(Text.NO_SUCH_DB));
96 }
97 Bloof.propagateProgressEvent(
98 new ProgressEvent(Messages.getString(Text.FETCHING_VCS_DATA), 40));
99 CvsPlugin cvsPlugin = new CvsPlugin();
100 ScmRevisionIterator revisonIter = cvsPlugin.getRevisions(mScmAccess);
101 if (!revisonIter.hasNext()) {
102 Bloof.propagateProgressEvent(new ProgressEvent(Messages.getString(Text.ERROR), 100));
103 throw new ScmAccessException("Could not access SCM system.");
104 }
105 Bloof.propagateProgressEvent(new ProgressEvent(Messages.getString(Text.POPULATE_DB), 60));
106 db.populateDatabase(revisonIter);
107 Bloof.propagateProgressEvent(new ProgressEvent(Messages.getString(Text.POPULATE_DB), 80));
108 }
109 /***
110 * Starts the import
111 * @see java.lang.Runnable#run( )
112 */
113 public void run() {
114
115 try {
116 newProject();
117 } catch (SQLException e) {
118 Bloof.propagateBloofException(
119 new BloofException("SQL error on importing project. " + e.toString()));
120 Bloof.propagateProgressEvent(new ProgressEvent("Error", 100));
121 Bloof.collectGarbage();
122 return;
123
124 } catch (IOException e) {
125 Bloof.propagateBloofException(
126 new BloofException("IO error on importing project. " + e.toString()));
127 Bloof.propagateProgressEvent(new ProgressEvent("Error", 100));
128 Bloof.collectGarbage();
129 return;
130 } catch (ScmAccessException e) {
131 Bloof.propagateBloofException(
132 new BloofException("Scm access error on importing project. " + e.toString()));
133 Bloof.propagateProgressEvent(new ProgressEvent("Error", 100));
134 Bloof.collectGarbage();
135 return;
136 }
137 Bloof.collectGarbage();
138 Bloof.propagateProgressEvent(new ProgressEvent("Import finshed. ", 100));
139 Bloof.propagateBloofEvent(BloofEvent.IMPORTED);
140 }
141
142 private DbAccess mDbAccess;
143 private ScmAccess mScmAccess;
144 }
This page was automatically generated by Maven