2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.maven
;
22 import java
.util
.Properties
;
23 import java
.util
.UUID
;
25 import org
.apache
.commons
.logging
.Log
;
26 import org
.apache
.commons
.logging
.LogFactory
;
27 import org
.argeo
.slc
.SlcException
;
28 import org
.argeo
.slc
.deploy
.DeployEnvironment
;
30 public abstract class MavenDeployEnvironment
implements DeployEnvironment
{
31 private static final Log log
= LogFactory
32 .getLog(MavenDeployEnvironment
.class);
33 private MavenManager mavenManager
;
35 public void unpackTo(Object packg
, File targetLocation
,
36 Map
<String
, String
> filter
) {
37 File packageLocation
=null;
39 String removeRootDir
= "enabled";
40 // if (packg instanceof MavenFile) {
41 // packageLocation = mavenManager
42 // .getPackageLocation((MavenFile) packg);
43 // type = ((MavenFile) packg).getType();
45 if (packg
instanceof File
) {
46 packageLocation
= (File
) packg
;
47 // TODO: type based on extension
49 throw new SlcException("Unrecognized package type "
52 if (log
.isDebugEnabled()) {
53 log
.debug("Unpack " + packageLocation
+ " of type " + type
+ " to "
58 File tempDir
= new File("/tmp/" + UUID
.randomUUID().toString());
60 targetLocation
.mkdirs();
61 Properties props
= new Properties();
62 props
.setProperty("dest", targetLocation
.getAbsolutePath());
63 props
.setProperty("src", packageLocation
.getAbsolutePath());
64 props
.setProperty("tempDir", tempDir
.getAbsolutePath());
65 props
.setProperty("removeRootDir", removeRootDir
);
67 URL antUrl
= getClass().getClassLoader().getResource(
68 "org/argeo/slc/support/deploy/ant/build.xml");
70 // if (type == null || type.equals("zip")) {
71 // new AntRunner(antUrl, "deployZip", props).run();
72 // } else if (type.equals("tar.gz")) {
73 // new AntRunner(antUrl, "deployTarGz", props).run();
75 // throw new SlcException("Unknow package type " + type);
77 throw new SlcException("Not implemented.");
78 } catch (SlcException e
) {
80 } catch (Exception e
) {
81 throw new SlcException("Cannot unpack package " + packg
+ " to "
86 public void setMavenManager(MavenManager mavenManager
) {
87 this.mavenManager
= mavenManager
;