]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.maven/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java
Add license headers
[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;
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 if (packg instanceof File) {
45 packageLocation = (File) packg;
46 // TODO: type based on extension
47 } else {
48 throw new SlcException("Unrecognized package type "
49 + packg.getClass());
50 }
51 if (log.isDebugEnabled()) {
52 log.debug("Unpack " + packageLocation + " of type " + type + " to "
53 + targetLocation);
54 }
55
56 try {
57 File tempDir = new File("/tmp/" + UUID.randomUUID().toString());
58 tempDir.mkdirs();
59 targetLocation.mkdirs();
60 Properties props = new Properties();
61 props.setProperty("dest", targetLocation.getAbsolutePath());
62 props.setProperty("src", packageLocation.getAbsolutePath());
63 props.setProperty("tempDir", tempDir.getAbsolutePath());
64 props.setProperty("removeRootDir", removeRootDir);
65
66 URL antUrl = getClass().getClassLoader().getResource(
67 "org/argeo/slc/support/deploy/ant/build.xml");
68
69 // if (type == null || type.equals("zip")) {
70 // new AntRunner(antUrl, "deployZip", props).run();
71 // } else if (type.equals("tar.gz")) {
72 // new AntRunner(antUrl, "deployTarGz", props).run();
73 // } else {
74 // throw new SlcException("Unknow package type " + type);
75 // }
76 throw new SlcException("Not implemented.");
77 } catch (SlcException e) {
78 throw e;
79 } catch (Exception e) {
80 throw new SlcException("Cannot unpack package " + packg + " to "
81 + targetLocation, e);
82 }
83 }
84
85 public void setMavenManager(MavenManager mavenManager) {
86 this.mavenManager = mavenManager;
87 }
88
89 }