001
014
015 package com.liferay.util.ant.bnd;
016
017 import java.io.File;
018
019 import org.apache.tools.ant.BuildException;
020 import org.apache.tools.ant.Project;
021
022
025 public class ReleaseToRepoTask extends BaseBndTask {
026
027 public void setDeployRepo(String name) {
028 _deployRepo = name;
029 }
030
031 public void setFile(File file) {
032 _file = file;
033 }
034
035 @Override
036 protected void doBeforeExecute() throws Exception {
037 super.doBeforeExecute();
038
039 if ((_file == null) || !_file.exists() || _file.isDirectory()) {
040 if (_file != null) {
041 project.log(
042 "file is either missing or is a directory " +
043 _file.getAbsolutePath(),
044 Project.MSG_ERR);
045 }
046
047 throw new BuildException("file is invalid");
048 }
049 }
050
051 @Override
052 protected void doExecute() throws Exception {
053 aQute.bnd.build.Project bndProject = getBndProject();
054
055 try {
056 if (_file.isFile() && _file.getName().endsWith(".jar")) {
057 if (_deployRepo != null) {
058 bndProject.deploy(_deployRepo, _file);
059 }
060 else {
061 bndProject.deploy(_file);
062 }
063 }
064 else {
065 project.log(
066 "Not a JAR file " + _file.getAbsolutePath(),
067 Project.MSG_ERR);
068 }
069 }
070 catch (Exception e) {
071 throw new BuildException(
072 e.getMessage(), e,
073 new org.apache.tools.ant.Location(_file.getAbsolutePath()));
074 }
075
076 report(bndProject);
077
078 if (bndProject.getErrors().size() > 0) {
079 throw new BuildException(
080 "Unable to deploy",
081 new org.apache.tools.ant.Location(_file.getAbsolutePath()));
082 }
083 }
084
085 private String _deployRepo;
086 private File _file;
087
088 }