]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.maven/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java
Use commons as parent
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.maven / src / main / java / org / argeo / slc / maven / MavenDeployEnvironment.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.maven;
18
19 import java.io.File;
20 import java.net.URL;
21 import java.util.Map;
22 import java.util.Properties;
23 import java.util.UUID;
24
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;
29
30 public abstract class MavenDeployEnvironment implements DeployEnvironment {
31 private static final Log log = LogFactory
32 .getLog(MavenDeployEnvironment.class);
33 private MavenManager mavenManager;
34
35 public void unpackTo(Object packg, File targetLocation,
36 Map<String, String> filter) {
37 File packageLocation=null;
38 String type = null;
39 String removeRootDir = "enabled";
40 // if (packg instanceof MavenFile) {
41 // packageLocation = mavenManager
42 // .getPackageLocation((MavenFile) packg);
43 // type = ((MavenFile) packg).getType();
44 // } else
45 if (packg instanceof File) {
46 packageLocation = (File) packg;
47 // TODO: type based on extension
48 } else {
49 throw new SlcException("Unrecognized package type "
50 + packg.getClass());
51 }
52 if (log.isDebugEnabled()) {
53 log.debug("Unpack " + packageLocation + " of type " + type + " to "
54 + targetLocation);
55 }
56
57 try {
58 File tempDir = new File("/tmp/" + UUID.randomUUID().toString());
59 tempDir.mkdirs();
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);
66
67 URL antUrl = getClass().getClassLoader().getResource(
68 "org/argeo/slc/support/deploy/ant/build.xml");
69
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();
74 // } else {
75 // throw new SlcException("Unknow package type " + type);
76 // }
77 throw new SlcException("Not implemented.");
78 } catch (SlcException e) {
79 throw e;
80 } catch (Exception e) {
81 throw new SlcException("Cannot unpack package " + packg + " to "
82 + targetLocation, e);
83 }
84 }
85
86 public void setMavenManager(MavenManager mavenManager) {
87 this.mavenManager = mavenManager;
88 }
89
90 }