1 | package org.apache.maven.continuum.core.action; |
2 | |
3 | /* |
4 | * Licensed to the Apache Software Foundation (ASF) under one |
5 | * or more contributor license agreements. See the NOTICE file |
6 | * distributed with this work for additional information |
7 | * regarding copyright ownership. The ASF licenses this file |
8 | * to you under the Apache License, Version 2.0 (the |
9 | * "License"); you may not use this file except in compliance |
10 | * with the License. You may obtain a copy of the License at |
11 | * |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | * |
14 | * Unless required by applicable law or agreed to in writing, |
15 | * software distributed under the License is distributed on an |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
17 | * KIND, either express or implied. See the License for the |
18 | * specific language governing permissions and limitations |
19 | * under the License. |
20 | */ |
21 | |
22 | import java.util.Map; |
23 | |
24 | import org.apache.continuum.dao.ProjectGroupDao; |
25 | import org.apache.maven.continuum.ContinuumException; |
26 | import org.apache.maven.continuum.model.project.Project; |
27 | import org.apache.maven.continuum.model.project.ProjectGroup; |
28 | import org.apache.maven.continuum.store.ContinuumStoreException; |
29 | |
30 | /** |
31 | * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> |
32 | * @version $Id: StoreProjectAction.java 915747 2010-02-24 10:51:01Z oching $ |
33 | * @plexus.component role="org.codehaus.plexus.action.Action" |
34 | * role-hint="store-project" |
35 | */ |
36 | public class StoreProjectAction |
37 | extends AbstractContinuumAction |
38 | { |
39 | private static final String KEY_SCM_USE_CREDENTIALS_CACHE = "useCredentialsCache"; |
40 | |
41 | /** |
42 | * @plexus.requirement |
43 | */ |
44 | private ProjectGroupDao projectGroupDao; |
45 | |
46 | public void execute( Map context ) |
47 | throws ContinuumException, ContinuumStoreException |
48 | { |
49 | Project project = getUnvalidatedProject( context ); |
50 | |
51 | ProjectGroup projectGroup = getUnvalidatedProjectGroup( context ); |
52 | |
53 | // ---------------------------------------------------------------------- |
54 | // |
55 | // ---------------------------------------------------------------------- |
56 | |
57 | boolean useCredentialsCache = isUseScmCredentialsCache( context, false ); |
58 | // CONTINUUM-1605 don't store username/password |
59 | if ( useCredentialsCache ) |
60 | { |
61 | project.setScmUsername( null ); |
62 | project.setScmPassword( null ); |
63 | project.setScmUseCache( true ); |
64 | } |
65 | |
66 | projectGroup.addProject( project ); |
67 | |
68 | projectGroupDao.updateProjectGroup( projectGroup ); |
69 | |
70 | setProjectId( context, project.getId() ); |
71 | |
72 | // ---------------------------------------------------------------------- |
73 | // Set the working directory |
74 | // ---------------------------------------------------------------------- |
75 | /* |
76 | File projectWorkingDirectory = new File( getWorkingDirectory( context ), project.getId() ); |
77 | |
78 | if ( !projectWorkingDirectory.exists() && !projectWorkingDirectory.mkdirs() ) |
79 | { |
80 | throw new ContinuumException( "Could not make the working directory for the project " + |
81 | "'" + projectWorkingDirectory.getAbsolutePath() + "'." ); |
82 | } |
83 | |
84 | // The working directory is created based on the project id so we can always |
85 | // figure out what it is. |
86 | |
87 | project.setWorkingDirectory( projectWorkingDirectory.getAbsolutePath() ); |
88 | */ |
89 | // store.updateProject( project ); |
90 | } |
91 | |
92 | public static boolean isUseScmCredentialsCache( Map<String, Object> context, boolean defaultValue ) |
93 | { |
94 | return getBoolean( context, KEY_SCM_USE_CREDENTIALS_CACHE, defaultValue ); |
95 | } |
96 | |
97 | public static void setUseScmCredentialsCache( Map<String, Object> context, boolean useScmCredentialsCache ) |
98 | { |
99 | context.put( KEY_SCM_USE_CREDENTIALS_CACHE, useScmCredentialsCache ); |
100 | } |
101 | } |