%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
nl.toolforge.karma.core.cmd.impl.SelectManifest |
|
|
1 | /* |
|
2 | Karma core - Core of the Karma application |
|
3 | Copyright (C) 2004 Toolforge <www.toolforge.nl> |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, write to the Free Software |
|
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | */ |
|
19 | package nl.toolforge.karma.core.cmd.impl; |
|
20 | ||
21 | import nl.toolforge.karma.core.cmd.CommandDescriptor; |
|
22 | import nl.toolforge.karma.core.cmd.CommandException; |
|
23 | import nl.toolforge.karma.core.cmd.CommandResponse; |
|
24 | import nl.toolforge.karma.core.cmd.DefaultCommand; |
|
25 | import nl.toolforge.karma.core.location.LocationException; |
|
26 | import nl.toolforge.karma.core.manifest.Manifest; |
|
27 | import nl.toolforge.karma.core.manifest.ManifestException; |
|
28 | import org.apache.commons.logging.Log; |
|
29 | import org.apache.commons.logging.LogFactory; |
|
30 | ||
31 | import java.util.prefs.BackingStoreException; |
|
32 | import java.util.prefs.Preferences; |
|
33 | ||
34 | /** |
|
35 | * <p>This command activates a manifest, which is a general requirement for most other commands. The newly activated |
|
36 | * manifest is stored for the Karma session in the {@link nl.toolforge.karma.core.cmd.CommandContext} that is associated |
|
37 | * with the Karma session. |
|
38 | * |
|
39 | * @author W.H. Schraal |
|
40 | * @author D.A. Smedes |
|
41 | * @version $Id: SelectManifest.java,v 1.25 2004/11/10 22:25:09 hippe Exp $ |
|
42 | */ |
|
43 | public class SelectManifest extends DefaultCommand { |
|
44 | ||
45 | 0 | private static Log logger = LogFactory.getLog(SelectManifest.class); |
46 | ||
47 | 0 | private CommandResponse commandResponse = new CommandResponse(); |
48 | 0 | private Manifest selectedManifest = null; |
49 | ||
50 | public SelectManifest(CommandDescriptor descriptor) { |
|
51 | 0 | super(descriptor); |
52 | 0 | } |
53 | ||
54 | /** |
|
55 | * Activates a manifest. |
|
56 | * */ |
|
57 | public void execute() throws CommandException { |
|
58 | ||
59 | // Select a manifest and store it in the command context |
|
60 | // |
|
61 | try { |
|
62 | 0 | getContext().changeCurrentManifest(getCommandLine().getOptionValue("m")); |
63 | 0 | selectedManifest = getContext().getCurrentManifest(); |
64 | 0 | } catch (ManifestException me) { |
65 | 0 | throw new CommandException(me.getErrorCode(), me.getMessageArguments()); |
66 | 0 | } catch (LocationException e) { |
67 | 0 | throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
68 | 0 | } |
69 | ||
70 | // Store this manifest as the last used manifest. |
|
71 | // |
|
72 | 0 | String contextManifest = getWorkingContext().getContextManifestPreference(); |
73 | ||
74 | 0 | Preferences.userRoot().put(contextManifest, getContext().getCurrentManifest().getName()); |
75 | try { |
|
76 | 0 | Preferences.userRoot().flush(); |
77 | 0 | } catch (BackingStoreException e) { |
78 | 0 | logger.warn("Could not write user preferences due to java.template.prefs.BackingStoreException."); |
79 | 0 | } |
80 | 0 | } |
81 | ||
82 | /** |
|
83 | * Gets the commands' response object. |
|
84 | * |
|
85 | * @return The commands' response object. |
|
86 | */ |
|
87 | public CommandResponse getCommandResponse() { |
|
88 | 0 | return this.commandResponse; |
89 | } |
|
90 | ||
91 | protected Manifest getSelectedManifest() { |
|
92 | 0 | return selectedManifest; |
93 | } |
|
94 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |